how to solve this problem?


hi there,

i submitted last week problem till there. see first: http://social.msdn.microsoft.com/forums/en-us/csharpgeneral/thread/ff62549f-a153-4fa4-ab6c-726ed15d4d37

it works string (the sign removed pipe not comma now) not line fed text file. see code used follows:

string tempfile = path.gettempfilename();

using (var sr = new streamreader (@"c:\oldfile.txt"))
{
   using (var sw = new streamwriter (tempfile))
   {
      string line;
      while (line = sr.readline() != null)
      {
         string pattern = "(?<=(.*?\\|){4})(.*?\\|)";
         regex pipetoremove = new regex(pattern);
         string match = pipetoremove.match(line).value;
         string switchwith = match.replace("|", " ");
         line = line.replace(match, switchwith);
         sw.writeline(line);
      }
      file.delete(oldfile.txt);
      file.move(tempfile, oldfile.txt);

now when run it gives error msg "process can't access file c:\oldfile.txt because being used bby process". not sure where, somewhere code not right. plz advise. appreciate time.

 


allan

you have file locked stream reader sr, have close before delete file sr.close. delete file try move it; not work well.


Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'