Device information settings in SSRS are used to pass parameters to a rendering extension. For more information regarding device information settings in reporting services, see Passing Device Information Settings to Rendering Extensions.
For SQL Reporting, none of the options specified in the above article are feasible. We see a lot of scenarios where we would want to modify these settings, and render/export the report in the format that we are looking for.
For SQL Reporting reports, we can explore the SOAP APIs in modifying these device information settings at the run time. If we have integrated SQL Reporting within our applications, this approach is really easy, by just creating a separate function.
Here are some steps to achieve this:
public void Render_Export()
{
ReportExecutionService rs = new ReportExecutionService();
rs.Url = String.Format("https://{0}:443/ReportServer/reportExecution2005.asmx", ConfigurationManager.AppSettings["SERVER_NAME"]);
rs.CookieContainer = new CookieContainer();
rs.LogonUser(ConfigurationManager.AppSettings["USERNAME"], ConfigurationManager.AppSettings["PASSWORD"], ConfigurationManager.AppSettings["SERVER_NAME"]);
byte[] result = null;
string reportPath = "/SSRSReport/Report5";
string format = "CSV";
string historyID = null;
// Setting the deviceinfo parameters
string devInfo = @"<DeviceInfo><FieldDelimiter>;</FieldDelimiter></DeviceInfo>";
string encoding;
string mimeType;
string extension;
Warning[] warnings = null;
string[] streamIDs = null;
ExecutionInfo execInfo = new ExecutionInfo();
ExecutionHeader execHeader = new ExecutionHeader();
rs.ExecutionHeaderValue = execHeader;
execInfo = rs.LoadReport(reportPath, historyID);
String SessionId = rs.ExecutionHeaderValue.ExecutionID;
// code snippet to set the DataSource credentials.
if (execInfo.CredentialsRequired)
List<DataSourceCredentials> credentials = new List<DataSourceCredentials>();
foreach (DataSourcePrompt dsp in execInfo.DataSourcePrompts)
DataSourceCredentials cred = new DataSourceCredentials();
cred.DataSourceName = dsp.Name;
cred.UserName = ConfigurationManager.AppSettings["USERNAME"];
cred.Password = ConfigurationManager.AppSettings["PASSWORD"];
credentials.Add(cred);
}
Console.WriteLine("Setting data source credentials...");
execInfo = rs.SetExecutionCredentials(credentials.ToArray());
// Code snippet to render the file to a specified format.
try
result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);
execInfo = rs.GetExecutionInfo();
catch (Exception ex)
throw ex;
// Code snippet to write the file to a specific location using FileStream object
FileStream stream = File.Create(@"D:\report.csv", result.Length);
Console.WriteLine("File created.");
stream.Write(result, 0, result.Length);
Console.WriteLine("Result written to the file.");
stream.Close();
Console.WriteLine(ex.Message);
<appSettings>
<add key="SERVER_NAME" value="SQLReportingServer.reporting.windows.net"/>
<add key="USERNAME" value="UserName"/>
<add key="PASSWORD" value="Password"/>
</appSettings>
For more information about unsupported APIs in SQL Reporting, see http://msdn.microsoft.com/en-us/library/windowsazure/gg430132#UnsupportedAPIs
Other references:
Any questions around this, feel free to ping me.
Thanks
Chaitanya