ฉันมีไดรฟ์ที่ใช้ร่วมกันซึ่งอยู่ที่อื่นบนเซิร์ฟเวอร์ ฉันต้องการรับการแจ้งเตือนที่ให้ชื่อผู้ใช้ของบุคคลที่แก้ไขไฟล์ใด ๆ ที่อยู่ในไดรฟ์ที่แชร์
ขณะนี้ฉันกำลังใช้ FileSystemWatcher เพื่อรับการแจ้งเตือนและรหัสที่ได้รับจากคำถาม Stack overflow "ค้นหาชื่อผู้ใช้ (ใคร) แก้ไขไฟล์ใน C#" เพื่อค้นหาชื่อผู้ใช้
แต่ฉันกลับได้รับชื่อของคอมพิวเตอร์ที่มีไดรฟ์ที่แชร์อยู่ในขณะนี้ ฉันต้องการชื่อผู้ใช้ที่แก้ไข ไฟล์บนไดรฟ์ที่แชร์
รหัสของฉันคือ:
private string GetSpecificFileProperties(string file, params int[] indexes)
{
string fileName = Path.GetFileName(file);
string folderName = Path.GetDirectoryName(file);
Shell32.Shell shell = new Shell32.Shell();
Shell32.Folder objFolder;
objFolder = shell.NameSpace(folderName);
StringBuilder sb = new StringBuilder();
foreach (Shell32.FolderItem2 item in objFolder.Items())
{
if (fileName == item.Name)
{
for (int i = 0; i < indexes.Length; i++)
{
sb.Append(objFolder.GetDetailsOf(item, indexes[i]) + ",");
}
break;
}
}
string result = sb.ToString().Trim();
if (result.Length == 0)
{
return string.Empty;
}
return result.Substring(0, result.Length - 1);
}
string Type = GetSpecificFileProperties(filePath, 2);
string ObjectKind = GetSpecificFileProperties(filePath, 11);
DateTime CreatedDate = Convert.ToDateTime(GetSpecificFileProperties(filePath, 4));
DateTime LastModifiedDate = Convert.ToDateTime(GetSpecificFileProperties(filePath, 3));
DateTime LastAccessDate = Convert.ToDateTime(GetSpecificFileProperties(filePath, 5));
string LastUser = GetSpecificFileProperties(filePath, 10);
string ComputerName = GetSpecificFileProperties(filePath, 53);
string FileSize = GetSpecificFileProperties(filePath, 1);