Showing posts with label render. Show all posts
Showing posts with label render. Show all posts

Wednesday, 7 March 2012

Confusion about rs.Render method and reportPath argument

I'm trying to issue the Render method based on some samples I've tried
to adapt and I am getting errors about the path.
The doc states the first parameter to be passed to the Render method is
the "full path name of the report".
I'm not sure what is wanted there.
I currently have 2 projects in my .sln file: one is my web app which
has a web reference to the RS webservice and the other is a report
project. Here is a code snippet:
Dim rs As New ReportingService
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
'rs.Url = "localhost/ReportService.asmx"
Dim proxyParameters(0) As ParameterValue
proxyParameters(0) = New ParameterValue
proxyParameters(0).Name = "DataSource"
' get serialized dataset
proxyParameters(0).Value = objDataSet.GetXml()
' Render arguments
Dim result As Byte() = Nothing
'Dim reportPath As String = "/SampleReports/Employee Sales
Summary"
Dim reportPath As String = "/RD/Reports/MarketShare"
Dim format As String = "PDF" 'was "MHTML"
Dim historyID As String = Nothing
Dim devInfo As String = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"
Dim credentials As DataSourceCredentials() = Nothing
Dim showHideToggle As String = Nothing
Dim encoding As String
Dim mimeType As String
Dim warnings As Warning() = Nothing
Dim reportHistoryParameters As ParameterValue() = Nothing
Dim streamIDs As String() = Nothing
Dim sh As New SessionHeader
rs.SessionHeaderValue = sh
Try
result = rs.Render(reportPath, format, historyID, devInfo,
proxyParameters, _
credentials, showHideToggle, encoding, mimeType,
reportHistoryParameters, warnings, streamIDs)
sh.SessionId = rs.SessionHeaderValue.SessionId
Console.WriteLine("SessionID after call to Render: {0}",
rs.SessionHeaderValue.SessionId)
Console.WriteLine("Execution date and time: {0}",
rs.SessionHeaderValue.ExecutionDateTime)
Console.WriteLine("Is new execution: {0}",
rs.SessionHeaderValue.IsNewExecution)
Catch eX As SoapException
Console.WriteLine(eX.Detail.OuterXml)
End Try
I get:
<Message
xmlns="http://www.microsoft.com/sql/reportingservices">The item
'/RD/Reports/MarketShare' cannot be found.</Message>
I have my report file called Marketshare.rdl in the Reports folder of
my report project I call RD. Do I need to create a virtual directory to
hold my .rdl files? I've tried adding the file extension .rdl to this
reportPath string and that gives the same error. Please help me with
what I am missing. Thank you.Hi,
The ReportPath where the rs.Render method is needing is the complete path at
the ReportServer.
When you have create your reports in VS.NET 2003 you have to deploy them to
your ReportServer. The deploy server you have to define in the properties of
your Report project file (TargetServerURL usally
http://localhost/ReportServer). Also in this properties you can define a
report Path (TargetFolder)
This TargetFolder and your Report Filename are the complete reportParh.
e.g. You have set the TargetFolder to TestReport and you deploy a report
Report1.rdl to the server your reportPath will be: /TestReport/Report1
Jan Pieter Posthuma
"JJA" wrote:
> I'm trying to issue the Render method based on some samples I've tried
> to adapt and I am getting errors about the path.
> The doc states the first parameter to be passed to the Render method is
> the "full path name of the report".
> I'm not sure what is wanted there.
> I currently have 2 projects in my .sln file: one is my web app which
> has a web reference to the RS webservice and the other is a report
> project. Here is a code snippet:
> Dim rs As New ReportingService
> rs.Credentials = System.Net.CredentialCache.DefaultCredentials
> 'rs.Url = "localhost/ReportService.asmx"
> Dim proxyParameters(0) As ParameterValue
> proxyParameters(0) = New ParameterValue
> proxyParameters(0).Name = "DataSource"
> ' get serialized dataset
> proxyParameters(0).Value = objDataSet.GetXml()
> ' Render arguments
> Dim result As Byte() = Nothing
> 'Dim reportPath As String = "/SampleReports/Employee Sales
> Summary"
> Dim reportPath As String = "/RD/Reports/MarketShare"
> Dim format As String = "PDF" 'was "MHTML"
> Dim historyID As String = Nothing
> Dim devInfo As String => "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"
> Dim credentials As DataSourceCredentials() = Nothing
> Dim showHideToggle As String = Nothing
> Dim encoding As String
> Dim mimeType As String
> Dim warnings As Warning() = Nothing
> Dim reportHistoryParameters As ParameterValue() = Nothing
> Dim streamIDs As String() = Nothing
> Dim sh As New SessionHeader
> rs.SessionHeaderValue = sh
> Try
> result = rs.Render(reportPath, format, historyID, devInfo,
> proxyParameters, _
> credentials, showHideToggle, encoding, mimeType,
> reportHistoryParameters, warnings, streamIDs)
> sh.SessionId = rs.SessionHeaderValue.SessionId
> Console.WriteLine("SessionID after call to Render: {0}",
> rs.SessionHeaderValue.SessionId)
> Console.WriteLine("Execution date and time: {0}",
> rs.SessionHeaderValue.ExecutionDateTime)
> Console.WriteLine("Is new execution: {0}",
> rs.SessionHeaderValue.IsNewExecution)
> Catch eX As SoapException
> Console.WriteLine(eX.Detail.OuterXml)
> End Try
> I get:
> <Message
> xmlns="The">http://www.microsoft.com/sql/reportingservices">The item
> '/RD/Reports/MarketShare' cannot be found.</Message>
> I have my report file called Marketshare.rdl in the Reports folder of
> my report project I call RD. Do I need to create a virtual directory to
> hold my .rdl files? I've tried adding the file extension .rdl to this
> reportPath string and that gives the same error. Please help me with
> what I am missing. Thank you.
>

Friday, 24 February 2012

Conflicting docs on how to render

I am trying to use the render method to render to a byte array in an ASP.Net application and I am having a problem in that there is a lot of conflicting information in the books and the docs on how to do this. The latest docs I read led to the following code...

ReportingService2005 _rs = new ReportingService2005();

//have to use custom credentials because ASPNET does not have sufficient authority...
NetworkCredential myCred = new NetworkCredential("myuserid", "mypassword", "mydomain");
CredentialCache myCash = new CredentialCache();
myCash.Add(new Uri("http://localhost/myWebSiteName"), "NTLM", myCred);
_rs.Credentials = myCash;
_rs.Url = "http://localhost/ReportServer/ReportService2005.asmx";

//we just have one parameter...
ParameterValue[] Parameters = new ParameterValue[1];
Parameters[0].Name = "myReportID";
Parameters[0].Value = argmyReportID;

//Render the report to a byte array...
byte[] data;
data = _rs. oops there is no Render method!!

The first docs I read (WROX BOOK on SSRS2005) said to use the ReportingService class but there is no such class. I then found docs saying to use ReportingService2005 class as I did above. But that class has no Render method. Today I found other docs that say to use ReportExecutionService class.

Why are there so many conflicting docs. What class am I supposed to use to do a render?

Thanks,
Gary

This one here worked for me:

ReportServices.ReportingService rs = new ReportServices.ReportingService();

rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

byte[] ResultStream; // bytearray for result stream

string[] StreamIdentifiers; // string array for stream idenfiers

string OptionalParam = null; // string out param for optional parameters

ReportServices.ParameterValue[] optionalParams = null; // parametervalue array for optional parameters

ReportServices.Warning[] optionalWarnings = null; // warning array for optional warnings

ResultStream = rs.Render("/ReportProject1/Report1", "HTML4.0", null,

"<DeviceInfo><StreamRoot>/RSWebServiceXS/</StreamRoot></DeviceInfo>", null, null,

null, out OptionalParam, out OptionalParam, out optionalParams,

out optionalWarnings, out StreamIdentifiers);

After creating a webServices proxy class on ReportService.asmx.

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

|||

I get an error on

ResultStream = rs.Render(My.Settings.ReportPath, "PDF", Nothing, "<DeviceInfo><StreamRoot>/RSWebServiceXS/</StreamRoot></DeviceInfo>", Nothing, Nothing, _

Nothing, OptionalParam, OptionalParam, optionalParams, _

optionalWarnings, StreamIdentifiers)

it says that "render" is not a member of reportService. any ideas?

|||Which WebService (*.asmx) did you reference ?

HTH, Jens K. Suessmeyer.


http://www.sqlserver2005.de

|||

I am using both the reportExecution and ReportService. After struggling with it for a while I went and looked at the renderand save sample that someone had pointed out earlier. This time the code actually worked with some minor modifications. I am posting the whole code routine below in case someone has the same issue in the future.

Public Sub ExportToDisk()

Dim strFileName As String = System.Windows.Forms.Application.StartupPath

Dim strAppPath As String = System.Windows.Forms.Application.StartupPath

Try

Dim rs As New ReportExecutionService()

rs.Credentials = System.Net.CredentialCache.DefaultCredentials

rs.Url = My.Settings.EmailInvoices_ReportExecution_ReportExecutionService

Dim result As Byte() = Nothing

Dim reportPath As String = My.Settings.ReportPath

Dim format As String = "PDF"

Dim historyID As String = Nothing

Dim devInfo As String = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"

' Prepare report parameter.

Dim parameters(0) As ReportExecution.ParameterValue

parameters(0) = New ReportExecution.ParameterValue()

parameters(0).Name = "InvoiceNumber"

parameters(0).Value = Me.Invoice

Dim credentials As ReportExecution.DataSourceCredentials() = Nothing

Dim showHideToggle As String = Nothing

Dim encoding As String = ""

Dim mimeType As String = ""

Dim warnings As ReportExecution.Warning() = Nothing

Dim reportHistoryParameters As ReportExecution.ParameterValue() = Nothing

Dim streamIDs As String() = Nothing

Dim execInfo As New ExecutionInfo

Dim execHeader As New ExecutionHeader()

Dim SessionId As String

Dim extension As String = ""

rs.ExecutionHeaderValue = execHeader

execInfo = rs.LoadReport(reportPath, historyID)

rs.SetExecutionParameters(parameters, "en-us")

SessionId = rs.ExecutionHeaderValue.ExecutionID

Console.WriteLine("SessionID: {0}", rs.ExecutionHeaderValue.ExecutionID)

Try

result = rs.Render(format, devInfo, extension, encoding, mimeType, warnings, streamIDs)

execInfo = rs.GetExecutionInfo()

Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime)

Catch e As System.Exception

Console.WriteLine(e.ToString)

End Try

' Try

Using stream As FileStream = File.OpenWrite(strFileName & "\EmailFiles\" & Me.Invoice & ".PDF")

stream.Write(result, 0, result.Length)

stream.Close()

stream.Dispose()

End Using

Catch e As Exception

Console.WriteLine(e.Message)

End Try

Catch e As System.Exception

MessageBox.Show(e.Message)

End Try

End Sub

|||

I am using both the reportExecution and ReportService. After struggling with it for a while I went and looked at the renderand save sample that someone had pointed out earlier. This time the code actually worked with some minor modifications. I am posting the whole code routine below in case someone has the same issue in the future.

Public Sub ExportToDisk()

Dim strFileName As String = System.Windows.Forms.Application.StartupPath

Dim strAppPath As String = System.Windows.Forms.Application.StartupPath

Try

Dim rs As New ReportExecutionService()

rs.Credentials = System.Net.CredentialCache.DefaultCredentials

rs.Url = My.Settings.EmailInvoices_ReportExecution_ReportExecutionService

Dim result As Byte() = Nothing

Dim reportPath As String = My.Settings.ReportPath

Dim format As String = "PDF"

Dim historyID As String = Nothing

Dim devInfo As String = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"

' Prepare report parameter.

Dim parameters(0) As ReportExecution.ParameterValue

parameters(0) = New ReportExecution.ParameterValue()

parameters(0).Name = "InvoiceNumber"

parameters(0).Value = Me.Invoice

Dim credentials As ReportExecution.DataSourceCredentials() = Nothing

Dim showHideToggle As String = Nothing

Dim encoding As String = ""

Dim mimeType As String = ""

Dim warnings As ReportExecution.Warning() = Nothing

Dim reportHistoryParameters As ReportExecution.ParameterValue() = Nothing

Dim streamIDs As String() = Nothing

Dim execInfo As New ExecutionInfo

Dim execHeader As New ExecutionHeader()

Dim SessionId As String

Dim extension As String = ""

rs.ExecutionHeaderValue = execHeader

execInfo = rs.LoadReport(reportPath, historyID)

rs.SetExecutionParameters(parameters, "en-us")

SessionId = rs.ExecutionHeaderValue.ExecutionID

Console.WriteLine("SessionID: {0}", rs.ExecutionHeaderValue.ExecutionID)

Try

result = rs.Render(format, devInfo, extension, encoding, mimeType, warnings, streamIDs)

execInfo = rs.GetExecutionInfo()

Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime)

Catch e As System.Exception

Console.WriteLine(e.ToString)

End Try

' Try

Using stream As FileStream = File.OpenWrite(strFileName & "\EmailFiles\" & Me.Invoice & ".PDF")

stream.Write(result, 0, result.Length)

stream.Close()

stream.Dispose()

End Using

Catch e As Exception

Console.WriteLine(e.Message)

End Try

Catch e As System.Exception

MessageBox.Show(e.Message)

End Try

End Sub

|||

I am using both the reportExecution and ReportService. After struggling with it for a while I went and looked at the renderand save sample that someone had pointed out earlier. This time the code actually worked with some minor modifications. I am posting the whole code routine below in case someone has the same issue in the future.

Public Sub ExportToDisk()

Dim strFileName As String = System.Windows.Forms.Application.StartupPath

Dim strAppPath As String = System.Windows.Forms.Application.StartupPath

Try

Dim rs As New ReportExecutionService()

rs.Credentials = System.Net.CredentialCache.DefaultCredentials

rs.Url = My.Settings.EmailInvoices_ReportExecution_ReportExecutionService

Dim result As Byte() = Nothing

Dim reportPath As String = My.Settings.ReportPath

Dim format As String = "PDF"

Dim historyID As String = Nothing

Dim devInfo As String = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"

' Prepare report parameter.

Dim parameters(0) As ReportExecution.ParameterValue

parameters(0) = New ReportExecution.ParameterValue()

parameters(0).Name = "InvoiceNumber"

parameters(0).Value = Me.Invoice

Dim credentials As ReportExecution.DataSourceCredentials() = Nothing

Dim showHideToggle As String = Nothing

Dim encoding As String = ""

Dim mimeType As String = ""

Dim warnings As ReportExecution.Warning() = Nothing

Dim reportHistoryParameters As ReportExecution.ParameterValue() = Nothing

Dim streamIDs As String() = Nothing

Dim execInfo As New ExecutionInfo

Dim execHeader As New ExecutionHeader()

Dim SessionId As String

Dim extension As String = ""

rs.ExecutionHeaderValue = execHeader

execInfo = rs.LoadReport(reportPath, historyID)

rs.SetExecutionParameters(parameters, "en-us")

SessionId = rs.ExecutionHeaderValue.ExecutionID

Console.WriteLine("SessionID: {0}", rs.ExecutionHeaderValue.ExecutionID)

Try

result = rs.Render(format, devInfo, extension, encoding, mimeType, warnings, streamIDs)

execInfo = rs.GetExecutionInfo()

Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime)

Catch e As System.Exception

Console.WriteLine(e.ToString)

End Try

' Try

Using stream As FileStream = File.OpenWrite(strFileName & "\EmailFiles\" & Me.Invoice & ".PDF")

stream.Write(result, 0, result.Length)

stream.Close()

stream.Dispose()

End Using

Catch e As Exception

Console.WriteLine(e.Message)

End Try

Catch e As System.Exception

MessageBox.Show(e.Message)

End Try

End Sub

Conflicting docs on how to render

I am trying to use the render method to render to a byte array in an ASP.Net application and I am having a problem in that there is a lot of conflicting information in the books and the docs on how to do this. The latest docs I read led to the following code...

ReportingService2005 _rs = new ReportingService2005();

//have to use custom credentials because ASPNET does not have sufficient authority...
NetworkCredential myCred = new NetworkCredential("myuserid", "mypassword", "mydomain");
CredentialCache myCash = new CredentialCache();
myCash.Add(new Uri("http://localhost/myWebSiteName"), "NTLM", myCred);
_rs.Credentials = myCash;
_rs.Url = "http://localhost/ReportServer/ReportService2005.asmx";

//we just have one parameter...
ParameterValue[] Parameters = new ParameterValue[1];
Parameters[0].Name = "myReportID";
Parameters[0].Value = argmyReportID;

//Render the report to a byte array...
byte[] data;
data = _rs. oops there is no Render method!!

The first docs I read (WROX BOOK on SSRS2005) said to use the ReportingService class but there is no such class. I then found docs saying to use ReportingService2005 class as I did above. But that class has no Render method. Today I found other docs that say to use ReportExecutionService class.

Why are there so many conflicting docs. What class am I supposed to use to do a render?

Thanks,
Gary

This one here worked for me:

ReportServices.ReportingService rs = new ReportServices.ReportingService();

rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

byte[] ResultStream; // bytearray for result stream

string[] StreamIdentifiers; // string array for stream idenfiers

string OptionalParam = null; // string out param for optional parameters

ReportServices.ParameterValue[] optionalParams = null; // parametervalue array for optional parameters

ReportServices.Warning[] optionalWarnings = null; // warning array for optional warnings

ResultStream = rs.Render("/ReportProject1/Report1", "HTML4.0", null,

"<DeviceInfo><StreamRoot>/RSWebServiceXS/</StreamRoot></DeviceInfo>", null, null,

null, out OptionalParam, out OptionalParam, out optionalParams,

out optionalWarnings, out StreamIdentifiers);

After creating a webServices proxy class on ReportService.asmx.

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

|||

I get an error on

ResultStream = rs.Render(My.Settings.ReportPath, "PDF", Nothing, "<DeviceInfo><StreamRoot>/RSWebServiceXS/</StreamRoot></DeviceInfo>", Nothing, Nothing, _

Nothing, OptionalParam, OptionalParam, optionalParams, _

optionalWarnings, StreamIdentifiers)

it says that "render" is not a member of reportService. any ideas?

|||Which WebService (*.asmx) did you reference ?

HTH, Jens K. Suessmeyer.


http://www.sqlserver2005.de

|||

I am using both the reportExecution and ReportService. After struggling with it for a while I went and looked at the renderand save sample that someone had pointed out earlier. This time the code actually worked with some minor modifications. I am posting the whole code routine below in case someone has the same issue in the future.

Public Sub ExportToDisk()

Dim strFileName As String = System.Windows.Forms.Application.StartupPath

Dim strAppPath As String = System.Windows.Forms.Application.StartupPath

Try

Dim rs As New ReportExecutionService()

rs.Credentials = System.Net.CredentialCache.DefaultCredentials

rs.Url = My.Settings.EmailInvoices_ReportExecution_ReportExecutionService

Dim result As Byte() = Nothing

Dim reportPath As String = My.Settings.ReportPath

Dim format As String = "PDF"

Dim historyID As String = Nothing

Dim devInfo As String = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"

' Prepare report parameter.

Dim parameters(0) As ReportExecution.ParameterValue

parameters(0) = New ReportExecution.ParameterValue()

parameters(0).Name = "InvoiceNumber"

parameters(0).Value = Me.Invoice

Dim credentials As ReportExecution.DataSourceCredentials() = Nothing

Dim showHideToggle As String = Nothing

Dim encoding As String = ""

Dim mimeType As String = ""

Dim warnings As ReportExecution.Warning() = Nothing

Dim reportHistoryParameters As ReportExecution.ParameterValue() = Nothing

Dim streamIDs As String() = Nothing

Dim execInfo As New ExecutionInfo

Dim execHeader As New ExecutionHeader()

Dim SessionId As String

Dim extension As String = ""

rs.ExecutionHeaderValue = execHeader

execInfo = rs.LoadReport(reportPath, historyID)

rs.SetExecutionParameters(parameters, "en-us")

SessionId = rs.ExecutionHeaderValue.ExecutionID

Console.WriteLine("SessionID: {0}", rs.ExecutionHeaderValue.ExecutionID)

Try

result = rs.Render(format, devInfo, extension, encoding, mimeType, warnings, streamIDs)

execInfo = rs.GetExecutionInfo()

Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime)

Catch e As System.Exception

Console.WriteLine(e.ToString)

End Try

' Try

Using stream As FileStream = File.OpenWrite(strFileName & "\EmailFiles\" & Me.Invoice & ".PDF")

stream.Write(result, 0, result.Length)

stream.Close()

stream.Dispose()

End Using

Catch e As Exception

Console.WriteLine(e.Message)

End Try

Catch e As System.Exception

MessageBox.Show(e.Message)

End Try

End Sub

|||

I am using both the reportExecution and ReportService. After struggling with it for a while I went and looked at the renderand save sample that someone had pointed out earlier. This time the code actually worked with some minor modifications. I am posting the whole code routine below in case someone has the same issue in the future.

Public Sub ExportToDisk()

Dim strFileName As String = System.Windows.Forms.Application.StartupPath

Dim strAppPath As String = System.Windows.Forms.Application.StartupPath

Try

Dim rs As New ReportExecutionService()

rs.Credentials = System.Net.CredentialCache.DefaultCredentials

rs.Url = My.Settings.EmailInvoices_ReportExecution_ReportExecutionService

Dim result As Byte() = Nothing

Dim reportPath As String = My.Settings.ReportPath

Dim format As String = "PDF"

Dim historyID As String = Nothing

Dim devInfo As String = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"

' Prepare report parameter.

Dim parameters(0) As ReportExecution.ParameterValue

parameters(0) = New ReportExecution.ParameterValue()

parameters(0).Name = "InvoiceNumber"

parameters(0).Value = Me.Invoice

Dim credentials As ReportExecution.DataSourceCredentials() = Nothing

Dim showHideToggle As String = Nothing

Dim encoding As String = ""

Dim mimeType As String = ""

Dim warnings As ReportExecution.Warning() = Nothing

Dim reportHistoryParameters As ReportExecution.ParameterValue() = Nothing

Dim streamIDs As String() = Nothing

Dim execInfo As New ExecutionInfo

Dim execHeader As New ExecutionHeader()

Dim SessionId As String

Dim extension As String = ""

rs.ExecutionHeaderValue = execHeader

execInfo = rs.LoadReport(reportPath, historyID)

rs.SetExecutionParameters(parameters, "en-us")

SessionId = rs.ExecutionHeaderValue.ExecutionID

Console.WriteLine("SessionID: {0}", rs.ExecutionHeaderValue.ExecutionID)

Try

result = rs.Render(format, devInfo, extension, encoding, mimeType, warnings, streamIDs)

execInfo = rs.GetExecutionInfo()

Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime)

Catch e As System.Exception

Console.WriteLine(e.ToString)

End Try

' Try

Using stream As FileStream = File.OpenWrite(strFileName & "\EmailFiles\" & Me.Invoice & ".PDF")

stream.Write(result, 0, result.Length)

stream.Close()

stream.Dispose()

End Using

Catch e As Exception

Console.WriteLine(e.Message)

End Try

Catch e As System.Exception

MessageBox.Show(e.Message)

End Try

End Sub

|||

I am using both the reportExecution and ReportService. After struggling with it for a while I went and looked at the renderand save sample that someone had pointed out earlier. This time the code actually worked with some minor modifications. I am posting the whole code routine below in case someone has the same issue in the future.

Public Sub ExportToDisk()

Dim strFileName As String = System.Windows.Forms.Application.StartupPath

Dim strAppPath As String = System.Windows.Forms.Application.StartupPath

Try

Dim rs As New ReportExecutionService()

rs.Credentials = System.Net.CredentialCache.DefaultCredentials

rs.Url = My.Settings.EmailInvoices_ReportExecution_ReportExecutionService

Dim result As Byte() = Nothing

Dim reportPath As String = My.Settings.ReportPath

Dim format As String = "PDF"

Dim historyID As String = Nothing

Dim devInfo As String = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"

' Prepare report parameter.

Dim parameters(0) As ReportExecution.ParameterValue

parameters(0) = New ReportExecution.ParameterValue()

parameters(0).Name = "InvoiceNumber"

parameters(0).Value = Me.Invoice

Dim credentials As ReportExecution.DataSourceCredentials() = Nothing

Dim showHideToggle As String = Nothing

Dim encoding As String = ""

Dim mimeType As String = ""

Dim warnings As ReportExecution.Warning() = Nothing

Dim reportHistoryParameters As ReportExecution.ParameterValue() = Nothing

Dim streamIDs As String() = Nothing

Dim execInfo As New ExecutionInfo

Dim execHeader As New ExecutionHeader()

Dim SessionId As String

Dim extension As String = ""

rs.ExecutionHeaderValue = execHeader

execInfo = rs.LoadReport(reportPath, historyID)

rs.SetExecutionParameters(parameters, "en-us")

SessionId = rs.ExecutionHeaderValue.ExecutionID

Console.WriteLine("SessionID: {0}", rs.ExecutionHeaderValue.ExecutionID)

Try

result = rs.Render(format, devInfo, extension, encoding, mimeType, warnings, streamIDs)

execInfo = rs.GetExecutionInfo()

Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime)

Catch e As System.Exception

Console.WriteLine(e.ToString)

End Try

' Try

Using stream As FileStream = File.OpenWrite(strFileName & "\EmailFiles\" & Me.Invoice & ".PDF")

stream.Write(result, 0, result.Length)

stream.Close()

stream.Dispose()

End Using

Catch e As Exception

Console.WriteLine(e.Message)

End Try

Catch e As System.Exception

MessageBox.Show(e.Message)

End Try

End Sub