0

I want to check if a certain network drive is accessible and exit my addin if not. It's an Outlook 2013 addin in VSTO. Anyway, I would like to search for it by UNC if possible as \192.168.0.2\WAN\ or I could use the drive letter as a last last resort, but not everyone uses the same letter for that drive in our company.

Anyway if I do Directory.Exists("path with correct drive letter"); it hangs. I want to just see if its there or not.

Can someone provide assistance and also give me a small example?

Oh and by the way, there is an answer where a process is spawned to do net use. I wanted to do it without spawning a new process wanted to know if it was possible.

Thanks a ton

ss7
  • 2,902
  • 7
  • 41
  • 90
  • Possible duplicate of http://stackoverflow.com/questions/458363/determining-if-file-exists-using-c-sharp-and-resolving-unc-path – dotNET Jun 01 '15 at 06:52
  • saw that one I wanted to do it without spawning another process. fixed – ss7 Jun 01 '15 at 06:53
  • The accepted answer doesn't spawn a process. Does it? – dotNET Jun 01 '15 at 07:43
  • Have you tried to run a check on a secondary thread which you may cancel if it hangs? – Eugene Astafiev Jun 01 '15 at 12:52
  • it spawns one to run net use – ss7 Jun 01 '15 at 13:14
  • @EugeneAstafiev I', not sure how to do that do you have an example? That would work for me as an answer too. – ss7 Jun 01 '15 at 13:14
  • 1
    The simplest way is to use the BackgroundWorker component. See [How do I run a simple bit of code in a new thread?](http://stackoverflow.com/questions/363377/how-do-i-run-a-simple-bit-of-code-in-a-new-thread) for more information. – Eugene Astafiev Jun 01 '15 at 13:18
  • 1
    Also see the [How to: Create and Terminate Threads (C# Programming Guide)](https://msdn.microsoft.com/en-us/library/7a2f3ay4(v=vs.90).aspx) in MSDN. – Eugene Astafiev Jun 01 '15 at 13:19
  • @EugeneAstafiev if you just write those up a little I will accept answer – ss7 Jun 01 '15 at 20:24

1 Answers1

1

You can run a check on a secondary thread which you may cancel if it hangs. The simplest way is to use the BackgroundWorker component. See How do I run a simple bit of code in a new thread? for more information. Also see the How to: Create and Terminate Threads (C# Programming Guide) in MSDN.

Community
  • 1
  • 1
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45