I have the following code which I want to use to download an SSRS report as a PDF into a folder
Protected Sub BtnPDF_Click(sender As Object, e As EventArgs)
Try
Dim client As New WebClient()
client.Headers.Add("user-agent", "Document download")
client.UseDefaultCredentials = True
'client.DownloadFile("http://server-name1/ReportServer_REPORTSDB/Pages/ReportViewer.aspx?%2fReport_Folder%2fReportName&rs:Command=Render&ID=12421&DTE=0&rs:Format=PDF", "\\server-name1\SharedFolder\Test2.pdf")
'client.DownloadFile("http://server-name2/ReportServer_REPORTSDB/Pages/ReportViewer.aspx?%2fReport_Folder%2fReportName&rs:Command=Render&ID=12421&DTE=0&rs:Format=PDF", "\\server-name1\SharedFolder\Test2.pdf")
'client.DownloadFile("http://server-name2/NormalWebsite/Documents/UserGuide.pdf", "\\server-name1\SharedFolder\Test2.pdf")
Catch ex As Exception
txtComments.Text = ex.Message
End Try
End Sub
Note the lines commented out: When running the code in Visual Studio and uncommenting any one of these three lines, the code works as expected, downloading the PDF file to the location.
When publishing to IIS, only the last line (Which just points to a PDF file a local site) will download the file to the location. If I uncomment just one of the first two lines, the code falls into a catch block and displays a 403 error in the comments textbox
I guess this is some sort of SSRS issue since this is only happening to the SSRS URLs but I can't figure out what the problem would be?
NB
http://server-name1/ReportServer_REPORTSDB is a SSRS 2016 server
http://server-name2/ReportServer_REPORTSDB is a SSRS 2008R2 server
This is not my code, but the documentation suggests the line
client.Headers.Add("user-agent", "Document download")
is to prevent a 500 error