Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Save SSRS Report as pdf using Reporting Services

$
0
0

I've been trying to convert a SSRS Report to PDF and save to
my local drive using the Reporting Web Services. Though I'm able to
generate the corresponding pdf file but the contents of the file are
missing. I've checked that the report I'm trying to convert is not an
empty one. Only the header section is present there within the generated
pdf files. Below is the code I'm using:

protected void GeneratePDFFromReport(object sender, EventArgs e)
    {        
	RS2005.ReportingService2005 rs;        
	RE2005.ReportExecutionService rsExec; 
	// Create a new proxy to the web service        
	rs = new RS2005.ReportingService2005();        
	rsExec = new RE2005.ReportExecutionService();      
	// Authenticate to the Web service using Windows credentials        
	rs.Credentials = new System.Net.NetworkCredential("username", "password", "domain");        		
	rsExec.Credentials = new System.Net.NetworkCredential("username", "password", "domain");        	
	//rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;        
	rs.Url = "http://servername/reportserver/reportservice2005.asmx";        
	rsExec.Url = "http://servername/reportserver/reportexecution2005.asmx";

        string historyID = null;        
	string deviceInfo = null;        
	string format = "PDF";        
	Byte[] results;        
	string encoding = String.Empty;        
	string mimeType = "application/pdf";        
	string extension = String.Empty;        
	RE2005.Warning[] warnings = null;        
	string[] streamIDs = null;        

	// Path of the Report - XLS, PDF etc.        
	string fileName = @"C:\Report\MemberReport.pdf";        
	// Name of the report - Please note this is not the RDL file.       
 	string _reportName = @"/ReportFolder/ReportName";        
	string _historyID = null;        
	bool _forRendering = false;        
	RS2005.ParameterValue[] _values = null;        
	RS2005.DataSourceCredentials[] _credentials = null;        
	RS2005.ReportParameter[] _parameters = null;     
	try        
	{            
		_parameters = rs.GetReportParameters(_reportName, _historyID, _forRendering, _values, _credentials);
		RE2005.ExecutionInfo ei = rsExec.LoadReport(_reportName, historyID);            
		results = rsExec.Render(format, deviceInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);   
		Guid siteID = SPContext.Current.Site.ID;   
		GuidwebID = SPContext.Current.Site.OpenWeb().ID;            
		stringbudgetName = string.Empty;            
		try   
		{    
			SPSecurity.RunWithElevatedPrivileges(delegate()    
			{     
				using(SPSitesite = newSPSite(siteID))     
				{      
					using(SPWebweb = site.OpenWeb(webID))      
					{       
						web.AllowUnsafeUpdates = true;                            
						web.Files.Add(web.Url + "/Shared Documents/SharepointMemberExpenseReport_" + DateTime.Now.ToShortDateString().Replace('/','-') + ".pdf", results, true);       
						web.AllowUnsafeUpdates = false;      
					}     
				}    
			});   
		}   
		catch{ }   

		try            
		{                
			FileStream stream = File.Create(fileName, results.Length);                
			stream.Write(results, 0, results.Length);                
			stream.Close();            
		}            
		catch { }            

		results = null;        
	}        
	catch (Exception ex)        
	{            
		throw ex;        
	}    
}

 

Any help would highly be appreciated. Thanks.





Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>