public static List <TreeViewModel> LoadLocalNetworkFolders(string host, string username, string password) { List <TreeViewModel> finalObjList = new List <TreeViewModel>(); try { List <string> directories = ImpersonationHelper.Impersonate(username, password, @"\\" + host); if (directories != null && directories.Count > 0) { foreach (string dir in directories) { TreeViewModel obj = new TreeViewModel(); //push folder into final list obj.Value = dir.Substring(dir.LastIndexOf("\\") + 1); obj.Children = GetLocalNetworkDirectorties(username, password, dir); finalObjList.Add(obj); } } } catch (Exception e) { return(null); } return(finalObjList); }
//loading LocalNetwork Directories recursively private static List <TreeViewModel> GetLocalNetworkDirectorties(string username, string password, string folderPath) { List <TreeViewModel> newList = new List <TreeViewModel>(); try { List <string> newFolderList = ImpersonationHelper.Impersonate(username, password, folderPath); if (newFolderList != null && newFolderList.Count > 0) { foreach (string dir in newFolderList) { TreeViewModel obj = new TreeViewModel(); //push folder into final list obj.Value = dir.Substring(dir.LastIndexOf("\\") + 1); obj.Children = GetLocalNetworkDirectorties(username, password, dir); newList.Add(obj); } } } catch (Exception e) { throw; } return(newList); }
public static bool TestLocalNetworkConnection(string host, string username, string password) { try { ImpersonationHelper.Impersonate(username, password, @"\\" + host); } catch (Exception e) { return(false); } return(true); }