大家好,又见面了,我是你们的朋友全栈君。
1.获取本地路径的网络访问地址
private IEnumerable<KeyValuePair<string, string>> GetShareFolders() { var shareFolders = new List<KeyValuePair<string, string>>(); // Create a ManagementClass object var searcher = new ManagementObjectSearcher("select * from win32_share"); foreach (ManagementObject share in searcher.Get()) { //共享目录的名字 string name = string.Empty; PropertyData propertyData = share.Properties["Name"]; if (propertyData.Value != null && !string.IsNullOrEmpty(propertyData.Value.ToString())) { name = propertyData.Value.ToString(); } //共享目录的本地路程 string path = string.Empty; propertyData = share.Properties["Path"]; if (propertyData.Value != null && !string.IsNullOrEmpty(propertyData.Value.ToString())) { path = propertyData.Value.ToString(); } if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(path)) { var kv = new KeyValuePair<string, string>(name, path); shareFolders.Add(kv); } } return shareFolders; } private string GetShareFolderPath(string path) { var kvList = GetShareFolders(); var kv = kvList.FirstOrDefault(item => item.Value.Equals(path)); if (!string.IsNullOrEmpty(kv.Key)) { return @"\\" + Dns.GetHostName() + @"\" + kv.Key; } return null; }
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/154905.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...