2013-07-24 15 views
5

Sì, voglio esportare report SSRS nel PDF e restituirlo dalla mia azione, Non ho alcun visualizzatore di report. Vi prego di suggerire come posso ottenere questo. Finora ho fatto questoEsportazione di report SSRS in PDF in MVC Azione

public void SqlServerReport() 
    { 
     NetworkCredential nwc = new NetworkCredential("username", "password", "domain"); 
     WebClient client = new WebClient(); 
     client.Credentials = nwc; 
     string reportURL = "http://servername/ReportServer/reportfolder/StateReport&rs:Command=Render&rs:Format=PDF"; 
     Byte[] pageData = client.DownloadData(reportURL); 
     Response.ContentType = "application/pdf"; 
     Response.AddHeader("Content-Disposition", "attachment; filename=" + DateTime.Now); 
     Response.BinaryWrite(pageData); 
     Response.Flush(); 
     Response.End(); 
    } 

Sopra codice genera un'eccezione

"The remote server returned an error: (401) Unauthorized." 

Le mie domande sono
1) sto andando in direzione giusta?
2) C'è qualche alternativa migliore per raggiungere questo obiettivo?

risposta

7

ho corretto il codice precedente e ora il suo lavoro

public ActionResult GetPdfReport() 
    { 
     NetworkCredential nwc = new NetworkCredential("username", "password"); 
     WebClient client = new WebClient(); 
     client.Credentials = nwc; 
     string reportURL = "http://someIp/ReportServer/?%2fReportProjectName/ReportName&rs:Command=Render&rs:Format=PDF"; 
     return File(client.DownloadData(reportURL), "application/pdf"); 
    } 

io non trovai qualsiasi altra alternativa di questo per esportare SSRS Report nel MVC senza l'utilizzo di ReportViewer.

+0

Come mai non si ottiene un 401 utilizzando un JoshYates1980

0

non provare specificare il dominio in questo modo:

NetworkCredential nwc = new NetworkCredential("username", "password"); 
+0

Sì apolo90 corretto, solo un codice di esempio –