Click here to Skip to main content
15,896,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here in the below code im trying to convert the ReportViewer to pdf. When
i'm trying to save that pdf in desktop, it's working fine. But when i host the application at IIS it's not saving the file at all. But my requirement is to save the file in clients Machine in any of the Public folders.

What I have tried:

C#
protected void btnPrint_Click(object sender, EventArgs e) 
    {
                   

            Warning[] warnings;
            string[] streamids;
            string mimeType;
            string encoding;
            string extension;
            string deviceInfo = string.Empty;

            deviceInfo = "<DeviceInfo><SimplePageHeaders>True</SimplePageHeaders></DeviceInfo>";

            byte[] data = ReportViewer1.ServerReport.Render(
               "PDF", null, out mimeType, out encoding, out extension,
               out streamids, out warnings);

            //Identify the Client Machine Desktop folder Path
            string ClientDesktopPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "");            

            //DirPath = Server.MapPath(@"" + "~/Temp") + @"\" + "TempReportFiles";//Server.MapPath("~") returns the physical path to the root of the application
            PDFFileName = "OutPutTmpRpt" + SessionHandler.UserID.Trim() + ".pdf"; //Set the File name here
           
            using (FileStream fs = new FileStream(ClientDesktopPath + @"\" + PDFFileName.Trim(), FileMode.Create)) 
            {
                fs.Write(data, 0, data.Length);
                fs.Close();
                fs.Dispose();
            }
}
Posted
Updated 15-Aug-16 22:09pm
v2

1 solution

Can you image the security issues if you could write files to the client's file system? Your code is running on the server and it works locally as your server and client are the same machine. Once deployed your server code as no access to the client file system.

What you are wanting to do simply can't be done.
 
Share this answer
 
Comments
VICK 16-Aug-16 6:03am    
Agreed! My 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900