Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. The process cannot access the file because it is being used by another process.

The process cannot access the file because it is being used by another process.

Scheduled Pinned Locked Moved C#
help
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    singhdurgesh
    wrote on last edited by
    #1

    Hi I am writting the following code to write into text file.After Checking whether the file exixt or not ,It is giving the following error.Can any one help. Any solution to this problem would be appreciated. public void Ping(string hostName) { string path; path = @"C:\CheckList\checklist_"+DateTime.Now.ToString("yyyyMMdd")+".txt"; if (!File.Exists(path)) { File.Create(path); } TextWriter tw = new StreamWriter(path,true); Error comes when we create text writer.

    E P 0 3 Replies Last reply
    0
    • S singhdurgesh

      Hi I am writting the following code to write into text file.After Checking whether the file exixt or not ,It is giving the following error.Can any one help. Any solution to this problem would be appreciated. public void Ping(string hostName) { string path; path = @"C:\CheckList\checklist_"+DateTime.Now.ToString("yyyyMMdd")+".txt"; if (!File.Exists(path)) { File.Create(path); } TextWriter tw = new StreamWriter(path,true); Error comes when we create text writer.

      E Offline
      E Offline
      Ennis Ray Lynch Jr
      wrote on last edited by
      #2

      File.Create returns an open stream to the file created, locking it.

      Need custom software developed? I do C# development and consulting all over the United States. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

      1 Reply Last reply
      0
      • S singhdurgesh

        Hi I am writting the following code to write into text file.After Checking whether the file exixt or not ,It is giving the following error.Can any one help. Any solution to this problem would be appreciated. public void Ping(string hostName) { string path; path = @"C:\CheckList\checklist_"+DateTime.Now.ToString("yyyyMMdd")+".txt"; if (!File.Exists(path)) { File.Create(path); } TextWriter tw = new StreamWriter(path,true); Error comes when we create text writer.

        P Offline
        P Offline
        pkreddy04
        wrote on last edited by
        #3

        Check if the file is being used by some other process? Are you writing to a directory which is read only?

        1 Reply Last reply
        0
        • S singhdurgesh

          Hi I am writting the following code to write into text file.After Checking whether the file exixt or not ,It is giving the following error.Can any one help. Any solution to this problem would be appreciated. public void Ping(string hostName) { string path; path = @"C:\CheckList\checklist_"+DateTime.Now.ToString("yyyyMMdd")+".txt"; if (!File.Exists(path)) { File.Create(path); } TextWriter tw = new StreamWriter(path,true); Error comes when we create text writer.

          0 Offline
          0 Offline
          0x3c0
          wrote on last edited by
          #4

          You don't need the if statement at all. If the file doesn't exist, the StreamWriter will create it

          Between the idea And the reality Between the motion And the act Falls the Shadow

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups