Some of the Commonly Used Methods with Short Code Snippets


Some of the Commonly Used Methods with Short Code Snippets

All snippets require a proper SSRS endpoint reference as described earlier in the chapter, web and SOAP proxy references, and the following calls prior to calling any of the methods:

 ReportingService2005 rs = new ReportingService2005(); rs.Credentials = System.Net.CredentialCache.DefaultCredentials; 

  • Find and cancel all jobs

     Job[] jobs = null;         jobs = rs.ListJobs(); //Get a list of current jobs.         foreach (Job job in jobs)         {            if (job.Status == JobStatusEnum.Running  job.Status ==  JobStatusEnum.New)            {               rs.CancelJob(job.JobID);            }         } 
  • Create a folder item

     rs.CreateFolder(strFolderName, strParentFolderName, null); 
  • Create a report item

     FileStream stream = File.OpenRead("sample.rdl"); Byte[] rdl = new Byte[stream.Length]; stream.Read(rdl, 0, (int) stream.Length); stream.Close(); rs.CreateReport(strReportName, strFolderName, false, rdl, null); 
  • Delete an item

     rs.DeleteItem(strItemPath) 
  • Get an RDL of a report from SSRS

     System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); byte[] reportDefinition = rs.GetReportDefinition(strReportName); MemoryStream stream = new MemoryStream(reportDefinition); doc.Load(stream); doc.Save(@"C:\sample.rdl"); 

Method calls can also be grouped together and executed as a single transaction, that is, commit and rollback as a whole. The following code snippet shows how this could be accomplished:

 BatchHeader bh = new BatchHeader();        bh.BatchID = rs.CreateBatch();        rs.BatchHeaderValue = bh;        rs.<<MethodCall, like        DeleteItem>>;        rs.<<MethodCall>>;        ...        rs.ExecuteBatch(); 



Microsoft SQL Server 2005 Reporting Services
Microsoft SQL Server 2005 Reporting Services
ISBN: 0672327996
EAN: 2147483647
Year: 2004
Pages: 254

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net