Chủ Nhật, 23 tháng 12, 2018

[C#] Mapping Network Drive

using IWshRuntimeLibrary;

string drive = ConfigurationManager.AppSettings["Drive"];
string folder = ConfigurationManager.AppSettings["Folder"];
string userName = ConfigurationManager.AppSettings["Username"];
string password = ConfigurationManager.AppSettings["Password"];

IWshNetwork_Class network = new IWshNetwork_Class();

try
{
 network.RemoveNetworkDrive(drive);
}
catch (Exception ex)
{

}

try
{
 network.MapNetworkDrive(drive, folder, Type.Missing, userName, password);
}
catch (Exception ex)
{

}

Thứ Sáu, 21 tháng 12, 2018

[C#] Open file without locking

var stream = File.Open(filePath, FileMode.Open,
 FileAccess.Read,
 FileShare.ReadWrite);