XML File user output [modified]
-
Hi, I generate an Xml File with XmlTextwriter.I saved it in a known path (C:\Documents and Settings\My Documents\Visual Studio 2008myprojects\MyFile.xml). I want now to let the user choose where he wants to save his xml File. How can I import the data from my xml File to copy them in the specified file choosen by the user of my application???? Thank u very much
modified on Friday, March 11, 2011 5:33 AM
-
Hi, I generate an Xml File with XmlTextwriter.I saved it in a known path (C:\Documents and Settings\My Documents\Visual Studio 2008myprojects\MyFile.xml). I want now to let the user choose where he wants to save his xml File. How can I import the data from my xml File to copy them in the specified file choosen by the user of my application???? Thank u very much
modified on Friday, March 11, 2011 5:33 AM
Good question. Here is how i did. Suppose user selects the path like this :
Path="C:\MyFile.xml";
Suppose you have an object of xmlDoc containing the xml. So now we have to create a Filestream for the new path, and then use the StreamWriter class to write the xml to the new path.
FileStream fs=new FileStream(path,FileMode.Create,FileAccess.ReadWrite);
StreamWriter sw=new StreamWriter(fs,Text.Encoding.UTF8);
sw.Write(xmlDoc.OuterXml);
sw.Close();
fs.Close();Hope it helped! :)
People with high attitude deserve the standing ovation of our highest finger! My Technical Blog![^]
-
Good question. Here is how i did. Suppose user selects the path like this :
Path="C:\MyFile.xml";
Suppose you have an object of xmlDoc containing the xml. So now we have to create a Filestream for the new path, and then use the StreamWriter class to write the xml to the new path.
FileStream fs=new FileStream(path,FileMode.Create,FileAccess.ReadWrite);
StreamWriter sw=new StreamWriter(fs,Text.Encoding.UTF8);
sw.Write(xmlDoc.OuterXml);
sw.Close();
fs.Close();Hope it helped! :)
People with high attitude deserve the standing ovation of our highest finger! My Technical Blog![^]
Hi, I don't understand what u mean xmldoc.outerxml??? xmldoc is is my xml document? ty
-
Hi, I don't understand what u mean xmldoc.outerxml??? xmldoc is is my xml document? ty
xmlDoc is an object of XmlDocument. It will contain your MyFile.xml .
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load(@"C:\Documents and Settings\My Documents\Visual Studio\MyFile.xml");and xmlDoc.OuterXml will give you the whole contents of the xml which will be used to write to the new file.
People with high attitude deserve the standing ovation of our highest finger! My Technical Blog![^]
-
Hi, I generate an Xml File with XmlTextwriter.I saved it in a known path (C:\Documents and Settings\My Documents\Visual Studio 2008myprojects\MyFile.xml). I want now to let the user choose where he wants to save his xml File. How can I import the data from my xml File to copy them in the specified file choosen by the user of my application???? Thank u very much
modified on Friday, March 11, 2011 5:33 AM
If you are already generating the document in your application then why would you need to import it again. Just save it to where the user wants it when you generate it, rather than saving it to your application directory. If you want to prompt the user for a save location then use the SaveFileDialog[^] Also, if you want to just copy a file from one location to another then use System.IO.File.Copy()
I may or may not be responsible for my own actions
-
xmlDoc is an object of XmlDocument. It will contain your MyFile.xml .
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load(@"C:\Documents and Settings\My Documents\Visual Studio\MyFile.xml");and xmlDoc.OuterXml will give you the whole contents of the xml which will be used to write to the new file.
People with high attitude deserve the standing ovation of our highest finger! My Technical Blog![^]
Hi Tarun, Fine my file is well copied but the problem all tags appear in the same ligne. How can i get an organized xml file well organized (tags organized)like this:
<GrpHdr>
<MsgId>DOSSIER1</MsgId>
<CreDtTm>2011-03-07T10:39:29</CreDtTm>
<BtchBookg>True</BtchBookg>
<NbOfTxs>2</NbOfTxs>
<CtrlSum>5534,4</CtrlSum>
<Grpg>MIXD</Grpg>
<InitgPty>
<Nm>Dossier1</Nm>
</InitgPty>
</GrpHdr>As I conclude, it reads them string. How can I solve that? ty
-
Hi Tarun, Fine my file is well copied but the problem all tags appear in the same ligne. How can i get an organized xml file well organized (tags organized)like this:
<GrpHdr>
<MsgId>DOSSIER1</MsgId>
<CreDtTm>2011-03-07T10:39:29</CreDtTm>
<BtchBookg>True</BtchBookg>
<NbOfTxs>2</NbOfTxs>
<CtrlSum>5534,4</CtrlSum>
<Grpg>MIXD</Grpg>
<InitgPty>
<Nm>Dossier1</Nm>
</InitgPty>
</GrpHdr>As I conclude, it reads them string. How can I solve that? ty
-
I will get back to you on this as soon as i find the solution.
People with high attitude deserve the standing ovation of our highest finger! My Technical Blog![^]
Hi, even if I use Text.Encoding.UTF8 the file still not organized like an xml File format. Thank u for u help on this (still waiting for u help :) )
-
I will get back to you on this as soon as i find the solution.
People with high attitude deserve the standing ovation of our highest finger! My Technical Blog![^]
hello Turan, I found a solution. i just add the text.encoding UTF-8 to my code:
this.Response.ContentEncoding = Encoding.GetEncoding ("UTF-8");
I open my file with an Xml editor all works fine and my File is well structred. Thank u a lot for u help and I am now sssssssssssssssso happy. :laugh:
-
hello Turan, I found a solution. i just add the text.encoding UTF-8 to my code:
this.Response.ContentEncoding = Encoding.GetEncoding ("UTF-8");
I open my file with an Xml editor all works fine and my File is well structred. Thank u a lot for u help and I am now sssssssssssssssso happy. :laugh: