none
save file xml RRS feed

  • Question

  • I need the name of the file to be me who places it, I have this code:

    string file = config.Text;
      XmlWriter w = XmlWriter.Create ((@ "C: \ Users \ admin \ Desktop \" file ".xml"));

    file would be the name that would place in the textbox to the file so that it is saved.

    Wednesday, April 4, 2018 4:59 PM

Answers

  • Try this:

    XmlWriter w = XmlWriter.Create( Path.Combine( Environment.GetFolderPath( Environment.SpecialFolder.DesktopDirectory ), file + ".xml" ) );
    

    • Marked as answer by Ronald_11 Wednesday, April 4, 2018 5:56 PM
    Wednesday, April 4, 2018 5:35 PM

All replies

  • Try this:

    XmlWriter w = XmlWriter.Create( Path.Combine( Environment.GetFolderPath( Environment.SpecialFolder.DesktopDirectory ), file + ".xml" ) );
    

    • Marked as answer by Ronald_11 Wednesday, April 4, 2018 5:56 PM
    Wednesday, April 4, 2018 5:35 PM
  • and in case of opening this file? I'm using open file dialog
    • Edited by Ronald_11 Wednesday, April 4, 2018 6:15 PM
    Wednesday, April 4, 2018 5:58 PM
  • To  create a file, SaveFileDialog is more appropriate than OpenFileDialog. The selected path is in FileName property:

       XmlWriter w = XmlWriter.Create( myFileDialog.FileName );

    Wednesday, April 4, 2018 6:47 PM