Saving text file in notepad called from Process.Start

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PFancy
    New Member
    • Apr 2008
    • 1

    Saving text file in notepad called from Process.Start

    Hi,

    Not sure if anyone can help. I have writen some code that will allow users to edit a txt file (it's actually an xml file) in notepad. I can get notepad to open correctly with the correct file, but once changes have been made and you want to save the file it errors with "Cannot create the Locations.xml file. Please check that the filename and path are correct. I have checked these and they seem fine. It would seem that the file is still locked by the process.
    Is there a way of opening the file for read and write access?

    Code:

    Code:
    public static void editXML()
            {
                if (File.Exists("Locations.xml"))
                {
                    Process process = new Process();
                    ProcessStartInfo startinfo = new ProcessStartInfo("Notepad.exe", Environment.CurrentDirectory.ToString() + "\\Locations.xml");
                                 
                    process.StartInfo = startinfo;
                    
                    process.Start();
                    process.Close();
                }
    Thanks

    Paul
Working...