I am trying to download an SSRS report in PDF format using an HTTP connection that is called in an SSIS script task. I get the error "could not open because it is either not a supported file type or because the file has been damaged.". The ultimate goal is to just have the SSRS report saved within the folder location that is stored in the variable "AEIOutputStagingFileFullPath" as a PDF file. Here is the actual code within the SSIS script task
protected void SaveFile(string url, string localpath)
{
System.Net.HttpWebRequest loRequest;
System.Net.HttpWebResponse loResponse;
System.IO.Stream loResponseStream;
System.IO.FileStream loFileStream = new System.IO.FileStream(localpath, System.IO.FileMode.Create, System.IO.FileAccess.Write);
byte[] laBytes = new byte[257];
int liCount = 1;
try
{
loRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
loRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
loRequest.Timeout = 600000;
loRequest.Method = "GET";
loResponse = (System.Net.HttpWebResponse)loRequest.GetResponse();
loResponseStream = loResponse.GetResponseStream();
while (liCount > 0)
{
liCount = loResponseStream.Read(laBytes, 0, 256);
loFileStream.Write(laBytes, 0, liCount);
}
loFileStream.Flush();
loFileStream.Close();
}
catch (Exception ex)
{
}
}
public void Main()
{
ConnectionManager conn = Dts.Connections["AccountSTP_HTTPCon"];
HttpClientConnection httpConn = new HttpClientConnection(conn.AcquireConnection(null));
string outputSTPpdf = Dts.Variables["User::AEIOutputStagingFileFullPath"].Value.ToString();
string pdfUrl = httpConn.ServerURL = @"http://vwdsrsdba0001/reports/report/TGAP/AccountChanges_STP&rs:Command=Render&rs:Format=PDF&rc:Toolbar=False";
SaveFile(pdfUrl, outputSTPpdf);
Dts.TaskResult = (int)ScriptResults.Success;
}