Save SSRS Report as .PDF in Client Machine


I am working on a SharePoint 2010 Visual WebPart, the saves a SSRS report as pdf on a button click.  The code is mentioned below:

		HttpWebRequest Req = (HttpWebRequest)WebRequest.Create(URL);
                Req.UseDefaultCredentials = true;
                Req.PreAuthenticate = true;
                Req.Credentials = CredentialCache.DefaultNetworkCredentials;
                HttpWebResponse objResponse = (HttpWebResponse)Req.GetResponse();
                Req.Method = "GET";

                //Specify the path for saving.
                string path = @"C:\test\" + quoteID + @".pdf";
                FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
                Stream stream = objResponse.GetResponseStream();

                byte[] buf = new byte[1024];
                int len = stream.Read(buf, 0, 1024);
                while (len > 0)
                    fs.Write(buf, 0, len);
                    len = stream.Read(buf, 0, 1024);

The code works great, however, when the user clicks the button the file is getting saved directly in the main server when the WebPart is deployed.  So, now I want the user to be able to select the location in there system to save the file.  How to enable the "Open save file dialog" and let the user select the location. can someone help me with this ? 


January 30th, 2014 12:14am

You can use below snippet.

 string strURL=path;
        WebClient req=new WebClient();
        HttpResponse response = HttpContext.Current.Response;
        response.Buffer= true;
        response.AddHeader("Content-Disposition","attachment;filename=\"" + Server.MapPath(strURL) + "\"");
        byte[] data=req.DownloadData(Server.MapPath(strURL));

Free Windows Admin Tool Kit Click here and download it now
January 30th, 2014 12:42am

Hi Bala,

Thanks for the code, I made some changes and got it working.

January 30th, 2014 5:27am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics