Generate SSRS report PDF file automatically in AX 2009

Remark: The AOS service running user can't be 'Network Service'(The default value), or else the web request will be deny running in batch job.

static void Jinn_GeneralSSRSPDFByCode(Args _args) { System.Net.WebRequest request; System.Net.WebResponse response; System.IO.Stream stream; System.IO.FileStream fileStream; System.Byte[] buffer = new System.Byte[1024](); str m_URL = @"http://******/ReportServer/Pages/ReportViewer.aspx?%2fDynamics %2fCustSalesOrderReportSRS.CustSalesConfirmSRS.RDS&rs:Command=Render&rs:Format=pdf"; str m_FileName = @"\\****\MailAttachment\SalesConfirmation.pdf"; int m_ByteRead; ; request = System.Net.WebRequest::Create(m_URL); request.set_Credentials(System.Net.CredentialCache::get_DefaultNetworkCredentials()); response = request.GetResponse(); stream = response.GetResponseStream(); fileStream = new System.IO.FileStream(m_FileName, System.IO.FileMode::Create); m_ByteRead = stream.Read(buffer, 0, buffer.get_Length()); while (m_ByteRead) { fileStream.Write(buffer, 0, m_ByteRead); m_ByteRead = stream.Read(buffer, 0, buffer.get_Length()); } fileStream.Close(); }

  

posted @ 2014-12-19 14:38  Sprite.z  Views(441)  Comments(0Edit  收藏  举报