[工作问题总结]Directory.Exists 判断域中的共享文件夹
来源:互联网 发布:阿里云香港ss 编辑:程序博客网 时间:2024/04/29 11:00
------------------------------ASP.Net+Android+IO开发 .Net培训 期待与您交流!------------------------------
工作中遇到一个问题,Directory.Exists 判断域中的共享文件夹,明明存在,却返回false
最终解决方案: 需要using 链接域中共享文件夹所在的服务器 删除文件的时候 也需要
重要代码如下:
/// <summary>/// 得到当前路劲下方的所有文件/// </summary>/// <param name="clientName"></param>/// <param name="type"></param>/// <param name="no"></param>/// <returns></returns>public static FileInfo[] TransShow(string clientName, string type, string no){var domain = string.Empty; //域var userName = string.Empty; //用户名var pwd = string.Empty; //密码var targetFilePath = string.Empty; //路径try{LinkDomain(type, ref domain, ref userName, ref pwd, ref targetFilePath); //连接域所用数据赋值targetFilePath += type == "2" || type == "3"? @"\" + no + @"\" + clientName + @"\" + DateTime.Now.Year + @"\": @"\" + clientName + @"\" + DateTime.Now.Year + @"\";using (new IdentityScope(domain, userName, pwd, LogonType.NewCredentials, LogonProvider.Default)){if (!Directory.Exists(targetFilePath)) //判断该路劲是否存在,不存在直接返回Nullreturn null;}}catch (Exception ex){Log.Error(" Exception: " + ex.Message);}var info = new DirectoryInfo(targetFilePath); //路劲存在的话,得到该路劲下方的所有文件var fileInfo = info.GetFiles();return fileInfo;}
/// <summary>/// 连接域所用数据赋值/// </summary>/// <param name="type">类型</param>/// <param name="domain">域</param>/// <param name="userName">用户名</param>/// <param name="pwd">密码</param>/// <param name="targetFilePath">路径</param>public static void LinkDomain(string type, ref string domain, ref string userName, ref string pwd, ref string targetFilePath){try{switch (type){case "2": //合约{domain = GlobalCaches.GetSystemConfig(false).ContractDomain;userName = GlobalCaches.GetSystemConfig(false).ContractUid;pwd = GlobalCaches.GetSystemConfig(false).ContractPwd;targetFilePath = GlobalCaches.GetSystemConfig(false).UploadPathContract;} break;case "3": //机器回厂{domain = GlobalCaches.GetSystemConfig(false).MachineDomain;userName = GlobalCaches.GetSystemConfig(false).MachineUid;pwd = GlobalCaches.GetSystemConfig(false).MachinePwd;targetFilePath = GlobalCaches.GetSystemConfig(false).UploadPathMachine;} break;case "4": //客户资料首批汇入{domain = GlobalCaches.GetSystemConfig(false).ClientDataFirstDomain;userName = GlobalCaches.GetSystemConfig(false).ClientDataFirstUid;pwd = GlobalCaches.GetSystemConfig(false).ClientDataFirstPwd;targetFilePath = GlobalCaches.GetSystemConfig(false).UploadPathClientDataFirst;} break;default: //客户{domain = GlobalCaches.GetSystemConfig(false).ClientDomain; //域userName = GlobalCaches.GetSystemConfig(false).ClientUid; //用户名pwd = GlobalCaches.GetSystemConfig(false).ClientPwd; //密码targetFilePath = GlobalCaches.GetSystemConfig(false).UploadPathClient;} break;}}catch (Exception ex){Log.Error(" Exception: " + ex.Message);}}
IdentityScope
public IdentityScope(string domain, string userName, string password, LogonType logonType, LogonProvider logonProvider){var logger = log4net.LogManager.GetLogger(GetType());try{if (string.IsNullOrEmpty(userName)){userName = "";}if (string.IsNullOrEmpty(domain)){domain = ".";}IntPtr token;var errorCode = 0;if (LogonUser(userName, domain, password, logonType, logonProvider, out token)){if (!ImpersonateLoggedOnUser(token)){errorCode = GetLastError();}}else{errorCode = GetLastError();}}catch (Exception ex){logger.Error(ex.Message);return;}}
private static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword,LogonType dwLogonType, LogonProvider dwLogonProvider, out IntPtr phToken);
------------------------------ASP.Net+Android+IO开发 .Net培训 期待与您交流!------------------------------
- [工作问题总结]Directory.Exists 判断域中的共享文件夹
- 子域中的一些问题总结。
- 网域中hp打印机共享不能打印的问题
- samba共享文件夹下可读不可写的问题总结
- VMWare与Centos7.0无法共享文件夹的问题总结
- VMWare与Centos7.0无法共享文件夹的问题总结
- virtualBox共享文件夹的问题
- Visualbox 共享文件夹的问题
- 解决:Windows Server 2003 域中设置user用户后,该用户登录后无法使用服务器的共享文件夹
- 关于域中计算机调取网络共享目录中图片的问题
- 缓解VSS共享文件夹的安全隐患问题
- 文件夹共享后--局域网看不见的问题
- 关于windows共享文件夹的密码问题
- 缓解VSS共享文件夹的安全隐患问题
- vitualbox共享文件夹出的问题
- 解决Win8不能共享文件夹的问题
- Ubuntu中设置共享文件夹,遇到问题总结(包括VMware-tools安装,更新源更改,共享工具的安装)
- Active Directory 安装时的问题总结
- data structure test
- CV codes代码分类整理合集
- RAC 的一些概念性和原理性的知识
- win2003系统下学习Mysql主从复制安装配置
- cvseq与cvpoint之间转换
- [工作问题总结]Directory.Exists 判断域中的共享文件夹
- 万能Makefile
- 快速学习法:一年搞定MIT计算机课程
- IOCP使用时常见的几个错误
- 动态规划之整齐打印
- 关于Android隐式启动Activity的分析和说明
- CentOS中JDK的安装和环境配置
- zencart刷淘宝信誉 被骗了 多情自古空余恨
- VS 2010 OpenGL 配置与实例开发