Update Session variable which is XML Doc in C#

Hello Experts,
I am trying to make changes to an existing program in C#.  I am loading an XML doc SalesXml by the following way from the Session, which is working just fine.  Now, I did some data changes in SalesXml,   and trying to reverse the process.  Meaning trying to update the Session variable GetSetXmlSalesData, so that I can restore it later.  Any idea, how can I do it?  Please help.

Thank you very much in advance.

XmlDocument SalesXml = new XmlDocument();
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Karrtik IyerSoftware ArchitectCommented:
Can you please share the snippet of how your class CommSession looks like and what other methods it has other than GetSetXmlSalesData?

Since you are using the return of GetSetXmlSalesData to the LoadXML function, I am assuming it (GetSetXMLSalesData) is returning string.

The XML Document class (SalesXML) provides different ways to save the modified XML, please refer the link below. Based on what other methods CommSession class provides use the appropriate overridden save method to save the changes to the XML.



Save(Stream)       Saves the XML document to the specified stream.
Save(String)      Saves the XML document to the specified file. If the specified file exists, this method overwrites it.
Save(TextWriter)      Saves the XML document to the specified TextWriter.
Save(XmlWriter)      Saves the XML document to the specified XmlWriter.
RadhaKrishnaKiJayaAuthor Commented:
Thank you Karrtik for your time.  Here is the answer.  Thank you again.

((CommSession)Session["CommSession"]).GetSetXmlSalesData = SalesXml.OuterXml;
RadhaKrishnaKiJayaAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for RadhaKrishnaKiJaya's comment #a41190764

for the following reason:

The solution already described in the note.
Karrtik IyerSoftware ArchitectCommented:
There was limited context given in the question by author about CommSession session class, and its methods (GetSetXmlSalesData-> is it a property or method, what is the type of it, nothing is mentioned in the question), in my earlier comment I asked for more information on the class CommSession and its methods. Given this limited context, the save method of XMLDocument is still a viable option to save the XML data to various destination. I provided this alternative to the author.
In his next comment the author instead of providing additional information, has just pasted one liner code as solution. It can be argued that there can be multiple solution to this problem.
Hence request the author to reconsider his option of choosing his comment as solution to this problem. And accept multiple solutions to this question.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RadhaKrishnaKiJayaAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.