/// <summary> /// Initializes a new instance of the <see cref="WindowsNetworkFileShare"/> class. /// </summary> /// <param name="networkName">Address of the file share</param> /// <param name="credentials">Username and password for accessing the file share</param> /// <param name="mpr">A class that handles calls to mpr.dll or performs same operations</param> public WindowsNetworkFileShare(string networkName, NetworkCredential credentials, IMPR mpr = null) { _mpr = mpr ?? new MPR(); _networkName = networkName; var netResource = new NetResource { Scope = ResourceScope.GlobalNetwork, ResourceType = ResourceType.Disk, DisplayType = ResourceDisplaytype.Share, RemoteName = networkName }; var userName = string.IsNullOrEmpty(credentials.Domain) ? credentials.UserName : string.Format(@"{0}\{1}", credentials.Domain, credentials.UserName); var result = _mpr.UseConnection(IntPtr.Zero, netResource, credentials.Password, userName, 0, null, null, null); if (result != 0) { throw new ExternalException("Error connecting to remote share - Code: " + result + ", " + GetErrorForNumber(result)); } }