What is the best way to write and upload an xml file to asp.net?

I have a web form that should save the data that the user enters into a file and to a client computer, which can also read from a saved file and re-fill the fields later. No files will be saved on the server side, so I expect streaming to be enabled during recording.

I decided that XML would be an easy way to do this, but I disagree with the methodology. XML documents? XML Writers? I am in the right search conditions to get what I want.

Thanks in advance for any pointers.

+3
source share
3 answers

XML. MSDN. :

, . XmlDocument System.Xml . XmlSerializer System.Xml.Serialization . MemoryStream System.IO , . , , xml. .

SerializeAnObject ( obj)

{

System.Xml.XmlDocument doc = new XmlDocument();

System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(obj.GetType());

System.IO.MemoryStream stream = new System.IO.MemoryStream();

try

{

    serializer.Serialize(stream, obj);

    stream.Position = 0;

    doc.Load(stream);

    return doc.InnerXml;

}

catch

{

    throw;

}

finally

{

    stream.Close();

    stream.Dispose();

}

}

StringReader, XmlReader XmlSerializer , xml ( ), XmlReader DeSerialize . , .

DeSerializeAnObject ( xmlOfAnObject)

{

MyClass myObject = new MyClass();

System.IO.StringReader read = new StringReader(xmlOfAnObject);

System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(myObject.GetType());

System.Xml.XmlReader reader = new XmlTextReader(read);

try

{

    myObject = (MyClass)serializer.Deserialize(reader);

    return myObject;

}

catch

{

throw;

}

finally

{

    reader.Close();

    read.Close();

    read.Dispose();

}

}

+1

: . ,

  • HTML5 ( )
  • Google gears ( )
  • Yahoo SWFStore ( Flash, , , a > 98% )
  • cookie ( )

: IE? , .

+1

It looks like you need to store data in a cookie. You cannot write from a browser to a file on a client computer. The browser runs in a sandbox that protects the client PC from malicious websites.

Take a look at this page to save and retrieve cookie data to / from the client machine:

http://www.aspnettutorials.com/tutorials/network/cookies-csharp.aspx

0
source

Source: https://habr.com/ru/post/1760576/


All Articles