Save a file on client

N

Nikhil Tayal

Is there a way to write a file on the client machine from an aspx page? I've
a custom query page and need to store the search criteria specified in an
XML file on the user machine from my web page (aspx). I form the XML at run
time from the search fileds specfied by the user and now my aspx page should
save it on client machine so that the user can open the same query on next
visit of the page.

And help is appreciated.

Nikhil
 
M

Martin Dechev

Hi, Nikhil Tayal,

If the info is not that large you can save it as a cookie on the client.

If it is really large you can prompt the user to save it and on the next
visit to upload it. This is very bad design regarding the security though,
because the users can upload practically anything.

A standard solution is to keep this data in the server in the profile of the
user (supposing that you keep the profiles of your users and they (may)
authenticate before the visit to the page).

Greetings
Martin
 
N

Nikhil Tayal

Thanks for replying. I'll not be uploading anything back to server on next
visit, I'll just read the file, extract the XML and then use the xml to form
my query.

But my question remain unanswered - How do I save the text that I form at
runtime into a file on the client machine? Currently I use this:

xmlDoc = Session["XmlDocument"] as XmlDocument;
string fileName = "query.xml";
Response.Clear();
Response.AppendHeader("content-disposition", "attachment; filename=" +
fileName);
Response.ContentType = "text/xml";
Response.Write(xmlDoc.OuterXml);
Response.Flush();

But this saves the XML as well as the source from the current aspx page. How
do I save just the XML and/or get rid of all other source from the file.

Nikhil
 
M

Martin Dechev

But my question remain unanswered - How do I save the text that I form at
runtime into a file on the client machine?

I may be wrong, but your next question will be how to read the file on the
client machine from the aspx page. That's why I explained you how this
situation is usually handled.
xmlDoc = Session["XmlDocument"] as XmlDocument;
string fileName = "query.xml";
Response.Clear();
Response.AppendHeader("content-disposition", "attachment; filename=" +
fileName);
Response.ContentType = "text/xml";
Response.Write(xmlDoc.OuterXml);
Response.Flush();

But this saves the XML as well as the source from the current aspx page. How
do I save just the XML and/or get rid of all other source from the file.

Just like you do it, only call Response.End() instead of Response.Flush()

Greetings
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top