JG Vimalan's Blog

It is all about coding!

Check if a path is UNC or not using C#

The following code snippet will give you an idea on verifying whether the given path is an UNC or not, 

using System.Runtime.InteropServices; 

public class UNCTest

 . . .

 . . . 

[DllImport(“shlwapi.dll”, CharSet = CharSet.Unicode)]
        [ResourceExposure(ResourceScope.None)]
        [return: MarshalAsAttribute(UnmanagedType.Bool)]
        public static extern bool PathIsUNC(
            [MarshalAsAttribute(UnmanagedType.LPWStr), In] string pszPath); 

You can directly call the PathIsUNC method and verify whether the given path is unc or not as shown below, 

if (UNCTest.PathIsUNC(\\\\abcd001\\Documents\\))
 _UncPath = true; 

Regards,

JG Vimalan

Advertisements

August 10, 2009 - Posted by | C#.NET

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: