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. Check if a file is used by an other process

Check if a file is used by an other process

Scheduled Pinned Locked Moved C#
csharpsysadminquestion
2 Posts 2 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.
  • H Offline
    H Offline
    holgerl
    wrote on last edited by
    #1

    I'm writing a program (Vis. C# .NET) to move files, depending from content, to a backup server. Sometimes the file cannot be deleted afdter copying because it is opened by an other process. The best would be to have a test a first that gives me a result if a specific file is opened by an other process or not. How this can be done ? At least I need a boolean answer if the file is opened in this moment by anything other or not. The better way would be to have an answer which process has opened it. Can anybody give me a hint for a good solution ? Holger

    J 1 Reply Last reply
    0
    • H holgerl

      I'm writing a program (Vis. C# .NET) to move files, depending from content, to a backup server. Sometimes the file cannot be deleted afdter copying because it is opened by an other process. The best would be to have a test a first that gives me a result if a specific file is opened by an other process or not. How this can be done ? At least I need a boolean answer if the file is opened in this moment by anything other or not. The better way would be to have an answer which process has opened it. Can anybody give me a hint for a good solution ? Holger

      J Offline
      J Offline
      jonny5
      wrote on last edited by
      #2

      I would think that you could just try to open the file for exclusive read access - that should throw an exception. As for the ultimate, you would have to use interop and Win32 functions to delve into the finer details. The OpenFile() Win32 function might do a better job than .Net for what you want. This site really helps with the interop stuff.... http://pinvoke.net Jon Humphreys ActivePlanet Software Bangkok, Thailand

      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