0

So I have written a simple program that creates an html document based on user input into a number of fields. Currently, when the user pressed a button it generates the document and automatically downloads onto the user's machine using the following:

        Response.ContentType = "text/plain";
        Response.Write(HTML.ToString());
        Response.Flush();
        Response.End();

But, I would like to have the file written to a folder on the user's machine when a user presses a button. So, let's say I want them to press the button and it automatically writes the file to their desktop. What would this code look like? (c#)

Thank you,

p.s. I have been trying something like this with no luck:

            string filename = Server.MapPath("~/C:/Users/Sean/Desktop/new.html");
            System.IO.StreamWriter textWriter = default(System.IO.StreamWriter);
            textWriter = System.IO.File.AppendText(filename);
            textWriter.Write(HTML);
            textWriter.Close();
Cybernetic
  • 12,628
  • 16
  • 93
  • 132

1 Answers1

1

Using ASP.Net, you CANNOT force user to save any file on any specific location. Moreover the file you want user to save is HTML which will be rendered directly on browser i.e. user will not be prompted to save it on their machine.

So to answer your question, you cannot have ANY file automatically saved to user's machine. There has to be some manual intervention by the user(to select the path at which he/she wants to save it.)

patil.rahulk
  • 574
  • 1
  • 3
  • 13