相关疑难解决方法(0)

获取本地网络服务器上所有UNC共享文件夹的列表

我正在尝试获取本地Intranet服务器上可用的所有共享文件夹的列表.

System.IO.Directory.GetDirectories()对于像这样的路径来说\\myServer\myShare,这样的工作很好,但是我得到了一条路径的例外\\myServer:

未处理的异常:System.ArgumentException:UNC路径的格式应为\ server\share.

有没有办法获取服务器的所有共享文件夹的列表?最终,我正在寻找一种方法,可以根据给定的路径处理这两种情况 - 返回给定服务器的所有共享列表,并返回给定网络共享文件夹的所有子目录列表.

.net c#

16
推荐指数
2
解决办法
4万
查看次数

寻找在C#中进行"净使用"的最佳实践

我宁愿不必诉诸于调用命令行.
我正在寻找可以映射/断开驱动器的代码,同时还有异常处理.

有任何想法吗?

c# .net-1.1

9
推荐指数
1
解决办法
1万
查看次数

在C#中将UNC路径转换为本地路径

有没有办法从UNC路径获取本地路径?

例如:\\ server7\hello.jpg应该给我D:\ attachments\hello.jpg

在应用Windows文件名和完整路径长度限制后,我试图将附件保存到UNC路径.在这里,我通过将UNC路径长度作为参考来应用这些限制.但是本地路径长度比UNC路径长,我想因为这个我得到以下异常.

发生System.IO.PathTooLongException HResult = -2147024690
Message =指定的路径,文件名或两者都太长.完全限定的文件名必须少于260个字符,目录名必须少于248个字符.Source = mscorlib
StackTrace:System.IO.Path.NormalizePath(String path,Boolean fullCheck,Int32 maxPathLength,Boolean expandShortPaths)的System.IO.PathHelper.GetFullPathName()at System.IO.Path.NormalizePath(String path,Boolean fullCheck) System.IO.FileStream.Init上的,Int32 maxPathLength)(String路径,FileMode模式,FileAccess访问,Int32权限,Boolean useRights,FileShare共享,Int32 bufferSize,FileOptions选项,SECURITY_ATTRIBUTES secAttrs,String msgPath,Boolean bFromProxy,Boolean useLongPath,Boolean checkHost)在System.IO.FileStream..ctor(String路径,FileMode模式,FileAccess访问,FileShare共享,Int32 bufferSize,FileOptions选项,String msgPath,Boolean bFromProxy)处于System.IO.FileStream..ctor(String path,FileMode)模式)在Presensoft.JournalEmailVerification.EmailVerification.DownloadFailedAttachments(EmailMessage msg,JournalEmail journalEmail)中的D:\ Source\ProductionReleases\Release_8.0.7.0\Email Archiving\Presensoft.JournalEmailVerification\EmailVer ification.cs:第630行InnerException:

.net c# windows path

5
推荐指数
1
解决办法
9764
查看次数

Network PC的DirectoryInfo抛出ArgumentException

我正在尝试将TreeView控件绑定到LAN上的机器ASUS-PC的公共文件夹.

华硕PC形式图片

但是,我无法弄清楚如何解析"ASUS-PC"目录,因为我无法从路径创建DirectoryInfo对象"\\\\ASUS-PC".

DirectoryInfo dir = new DirectoryInfo("\\\\ASUS-PC");
Run Code Online (Sandbox Code Playgroud)

上面的行抛出带有消息的ArgumentExceptionThe UNC path should be of the form \\server\share.

下面的代码只为root创建一个哑节点,因此我无法在该PC上显示所有公共文件夹.

如何提取路径"\\ ASUS-PC"的目录列表?

public void BindDirectoryToTreeView(string directoryPathToBind) {
  if (!String.IsNullOrEmpty(directoryPathToBind) && Directory.Exists(directoryPathToBind)) {
    treeView1.Nodes.Clear();
    TreeNode rootNode = null;
    char[] ps = treeView1.PathSeparator.ToCharArray();
    string[] split = directoryPathToBind.Split(ps);
    var folders = split.Where(str => !String.IsNullOrEmpty(str));
    for (int i = 0; i < folders.Count(); i++) {
      var folder = folders.ElementAt(i);
      int index = directoryPathToBind.IndexOf(folder);
      int length = index …
Run Code Online (Sandbox Code Playgroud)

c# directory smb

2
推荐指数
1
解决办法
2928
查看次数

标签 统计

c# ×4

.net ×2

.net-1.1 ×1

directory ×1

path ×1

smb ×1

windows ×1