简体   繁体   中英

Can I get UNC path of a network drive through my code?

I made a server and many users are accessing it.

Now I want to get Unc path for mapped drive for each user which will of course be different.

Actually I need the complete path in order to access those files in my c# code.

Taking complete path from user is not an option as they are not developers. What I want to do is ...If someone gives me Q: then I should get absolute path like this \\\\server1\\foo . I have searched but unable to get solution for this.

Is there any way to do this?

In C#(backend) or in angularjs(frontend) ?

From this_link I have learned that I cannot get the complete path just by uploading it in using javascript because For security reasons browsers do not allow this.

can I provide more details on this question?

Use WMI to check for network path. You can use ManagementClass object in C#. We can get this information from Win32_LogicalDisk , you will be interested in Name and ProviderName properties.

select * from win32_LogicalDisk where driveType = 4

instance of Win32_LogicalDisk
{
    Access = 0;
    Caption = "Z:";
    Compressed = FALSE;
    CreationClassName = "Win32_LogicalDisk";
    Description = "Network Connection";
    DeviceID = "Z:";
    DriveType = 4;
    FileSystem = "NTFS";
    FreeSpace = "1805758038016";
    MaximumComponentLength = 255;
    MediaType = 0;
    Name = "Z:";
    ProviderName = "\\\\<server>\\<path>";
    Size = "2000396742656";
    SupportsDiskQuotas = FALSE;
    SupportsFileBasedCompression = TRUE;
    SystemCreationClassName = "Win32_ComputerSystem";
    SystemName = "<server>";
    VolumeName = "New Volume";
    VolumeSerialNumber = "<id>";
};

EDIT : We have to connect using \\\\<server>\\root\\cimv2 to fetch share information from remote machine. Thanks Alex for pointing that out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM