jack Chen jack Chen - 1 year ago 89
C# Question

UNC path error in C# when output the file

The programme is developed with C# and the error occurs during the process of outputing.
When the software runs on the local PC,there is no error however when runs on the Service an error occurs :UNC path should be \server\share.

I guess the error happens on this sentence:


Answer Source

You have to convert a local path to a UNC path. Network Shares and UNC paths Encapsulates information about a single network share, including the server name, share name, share type, local path and comment. Also has some utility methods to determine if it is a file-system share, whether it matches part of a local path, and returns the root directory.

You can also use WMI to get the info like

using (ManagementClass shares = new ManagementClass(@"\\NameOfTheRemoteComputer\root\cimv2", "Win32_Share", new ObjectGetOptions())) {
    foreach (ManagementObject share in shares.GetInstances()) {

but Appropriate permissions are required.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download