Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am currently using a ASP.net Webservice to generate and downlaod PDF file to the clients computer.

Whats weird though is that instead of saving the file to the users computer download folder the Web Service saves the file to the IIS Server DefaultAppPool\Download folder on which the ASP.net web application is hosted onto.

This is my current folder which to generate folder paths

C#
string status = "";
string filename = "File_"
string sourcepath = "";
string destinationpath = "";
string baseUrl = "http://serverPath/MyApp/";

filename = filename + "_" + DateTime.Now.ToLongTimeString().Replace(":", "-").Replace(".", "-") + ".pdf";
sourcepath = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["_baseTempPDFPath"] + filename);
destinationpath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Downloads\\" + filename;
string DocContent = "";


This below line of code generate a wrong path which is not intended by me.
C#
destinationpath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Downloads\\" + filename;

What i want is C:\Users\ProfileName\Downloads\
I want to save the dynamically generated PDF to this path.

OR Is there a way to download the PDF to users computer

I tried this code and it does not work

C#
HttpContext.Current.Response.BinaryWrite(outPdfBuffer);
HttpContext.Current.Response.End();
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.SuppressContent = true;
HttpContext.Current.ApplicationInstance.CompleteRequest();


Any solutions

What I have tried:

I have pasted the code above which i am currently using in the Web Service. I am using EVOPDF to generate the PDF file.
Posted
Updated 2-Sep-16 4:58am
v2

1 solution

Your code is running on the server so when you ask for the Downloads folder you get the folder on the server of the account the code is running under, ergo the default app pool's folder.

You can't dictate the path that the file is saved as, you can only state its filename and the user saves it where they want to. Neither can you save directly to the user's file system either.
 
Share this answer
 
Comments
Christopher Fernandes 5-Sep-16 1:35am    
How do i then prompt the user to save or open the file?
F-ES Sitecore 6-Sep-16 4:47am    
When you push the file to the client use "application/octet-stream" as the file type and that will make the browser prompt to save or open

http://stackoverflow.com/questions/5596747/download-stream-file-from-url-asp-net (this isn't about your issue, but it shows code for downloading as octet-stream)

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