Reputation: 93
I have a large web form application that I want to allow the user to export their data in case they don't want to complete the entire form at once. Then when they return they can import the data and continue where they left off.
The reason for this is part of the requirement for the client is that no database is to be used.
I've gotten to the point where I create an XML file containing all the form data, but I want the client to be able to download that XML file without the application having to save it to the server, even temporarily.
Is it possible to create the XML file and transmit it via stream/attachment to the client without saving it to disk?
I'm using C# Asp.net
Upvotes: 0
Views: 5095
Reputation: 11
HttpResponse response = HttpContext.Current.Response; string xmlString = "<xml>blah</xml>"; string fileName = "ExportedForm.xml"; response.StatusCode = 200; response.AddHeader("content-disposition", "attachment;
filename=" + fileName); response.AddHeader("Content-Transfer-Encoding", "binary"); response.AddHeader("Content-Length", _Buffer.Length.ToString());
response.ContentType = "application-download"; response.Write(xmlString);
But it saves all page content to file
Upvotes: 1
Reputation: 8938
You can write to the HttpResponse:
HttpResponse response = HttpContext.Current.Response;
string xmlString = "<xml>blah</xml>";
string fileName = "ExportedForm.xml";
response.StatusCode = 200;
response.AddHeader("content-disposition", "attachment; filename=" + fileName);
response.AddHeader("Content-Transfer-Encoding", "binary");
response.AddHeader("Content-Length", _Buffer.Length.ToString());
response.ContentType = "application-download";
response.Write(xmlString);
Upvotes: 2
Reputation: 5501
Look into MemoryStream.
http://msdn.microsoft.com/en-us/library/system.io.memorystream.aspx
You should be able to store the XML in memory, then pipe it to your client through the HTTP Request or however you would like.
Upvotes: 1
Reputation: 1271
You don't mention what server technology you are using, but generally:
text/xml
attachment; filename=data.xml;
Some links: http://en.wikipedia.org/wiki/MIME#Content-Disposition
Upvotes: 2
Reputation: 8040
yes. In PHP it looks like this:
header("Content-type: text/xml");
$headerText = "Content-disposition: attachment; filename=file.xml";
header($headerText);
echo $your_XML_contents;
exit;
Upvotes: 0