Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using C#, how to know whether a folder is located on a network or not

Using C#, I would like my application to return whether a folder (with an already known path) is located in a network or in my computer.

How can I do that?

like image 213
MyrR Avatar asked Aug 10 '11 13:08

MyrR


People also ask

What is using () in C#?

The using statement causes the object itself to go out of scope as soon as Dispose is called. Within the using block, the object is read-only and can't be modified or reassigned. A variable declared with a using declaration is read-only.

Is Vs as C#?

The is operator returns true if the given object is of the same type, whereas the as operator returns the object when they are compatible with the given type. The is operator returns false if the given object is not of the same type, whereas the as operator returns null if the conversion is not possible.

Does using statement Call dispose?

The using statement guarantees that the object is disposed in the event an exception is thrown. It's the equivalent of calling dispose in a finally block.

What is the use of in front of a variable in C#?

What is the @ symbol in front of variables in C#? From the C# documentation it states that the @ symbol is an Identifier. The prefix “@” enables the use of keywords as identifiers, which is useful when interfacing with other programming languages.


1 Answers

If you are talking about a mapped network drive, you can use the DriveInfo's DriveType property:

var driveInfo = new DriveInfo("S:\");
if(driveInfo.DriveType == DriveType.Network)
    // do something
like image 123
Daniel Hilgarth Avatar answered Sep 19 '22 07:09

Daniel Hilgarth