XML should be just plain text UTF8. I used serialization for objects. Perhaps someone will correct me, but I did not consider it necessary to use serialization for text or binary data.
To transfer this data through memory, there is a good fooobar.com/questions/12683 / ... , which shows how to use MemoryStream memory buffers and bytes.
Because if you can get it in the buffer [], you can do something like this :
public bool SaveDocument( Byte[] docbinaryarray, string docname) { string strdocPath; strdocPath = "C:\\DocumentDirectory\\" + docname; FileStream objfilestream =new FileStream(strdocPath,FileMode.Create,FileAccess.ReadWrite); objfilestream.Write(docbinaryarray,0,docbinaryarray.Length); objfilestream.Close(); return true; }
Contact here for more information on System.IO methods , for example:
StreamWriter writer = new StreamWriter("c:\\KBTest.txt"); writer.WriteLine("File created using StreamWriter class."); writer.Close(); this.listbox1.Items.Clear(); addListItem("File Written to C:\\KBTest.txt");
UPDATE 1 (Windows):
(I thought you were looking for System.Windows.Forms.SaveFileDialog )
Here is an example MSDN code for this:
private void button2_Click(object sender, System.EventArgs e) {
And as they say, you need to register an event handler:
this.button2.Click += new System.EventHandler(this.button2_Click);
UPDATE 2 (Internet):
Ok, I see that you are really looking for a web solution. I was thinking about Windows instead of the Web. Here is what you need to do on the web page. This is an example of VB.NET, but I assume you can translate:
string FileName = "Hello.doc"; string Filename = strFileName.Substring(0, FileName.LastIndexOf(".")); Response.AppendHeader("Content-Disposition", "attachment; filename=" + FileName); Response.TransmitFile(Server.MapPath("~/Folder_Name/" + FileName)); Response.End();
I have made variations of this approach several times. You send the XML file back to the user's browser. As soon as he gets there, the user must decide what to do with him (often, "open this file or save it?"). This is under the control of the browser.
You can help the browser by including a content type header that tells the browser which file it is looking for and what it should try to open. Therefore, this header will ask him to call Excel:
Response.AppendHeader("Content-Type", "application/vnd.ms-excel");
You will often see the / pdf application that pulls out Adobe Reader or any other PDF reader that the user uses. Here you will want to use the content type "text / xml". The type of content is less critical here, because we intend to save the file, and not open it using the application.
There is some issue with the content of attachment compared to inline. Try both ways and see which one is best for you. One of them (I can't remember) basically ignores the suggested file name that you send it to, and instead uses the name of its ASP page. Very annoying. Firefox at least documents this as a bug, IE seems to just consider this another “feature”.