By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,997 Members | 1,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,997 IT Pros & Developers. It's quick & easy.

Saving text file in notepad called from Process.Start

P: 1
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:

Expand|Select|Wrap|Line Numbers
  1. public static void editXML()
  2.         {
  3.             if (File.Exists("Locations.xml"))
  4.             {
  5.                 Process process = new Process();
  6.                 ProcessStartInfo startinfo = new ProcessStartInfo("Notepad.exe", Environment.CurrentDirectory.ToString() + "\\Locations.xml");
  7.  
  8.                 process.StartInfo = startinfo;
  9.  
  10.                 process.Start();
  11.                 process.Close();
  12.             }
Thanks

Paul
Apr 3 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.