【问题标题】:Long Path in .net.net 中的长路径
【发布时间】:2013-06-16 02:21:29
【问题描述】:

我有问题

当我想访问目录安全并且我的路径长度超过 260 个字符时 所以我从这个链接得到了解决方案

http://blogs.msdn.com/b/bclteam/archive/2007/03/26/long-paths-in-net-part-2-of-3-long-path-workarounds-kim-hamilton.aspx

但是当我尝试访问目录的 GetAccessControl() 时,它会给出错误没有实现,所以我想为 GetAccessControl() 或您拥有的任何其他解决方案实现非托管代码

[DllImport("mscorlib.dll", CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.I4)]
static extern int GetAccessControl(string lpPathName, IntPtr lpSecurityAttributes);

public static int GetAccess(string dirPath)
{
    return GetAccessControl(@"\\?\" + dirPath, IntPtr.Zero);

}

派生自此类 System.Security.AccessControl.DirectorySecurity

【问题讨论】:

  • Mscorlib.dll 是一个托管 程序集,它不会导出任何您可以调用的函数。目前尚不清楚您要做什么,但您的方法是行不通的。

标签: .net path long-integer


【解决方案1】:

请查看这个库,它对我来说更适合使用长路径

Link Here

【讨论】:

    【解决方案2】:

    你可以看看彼得的图书馆in here。这将帮助您处理System.IO.PathTooLongException

    LongPaths 允许您的代码通过替换以下 System.IO 类型来支持长路径:FileInfoDirectoryInfoFileSystemInfoFileInfoDirectoryInfoFileSystemInfo

    就像你可以用下面的别名替换 System.IO 类型

    using Path = Pri.LongPath.Path;
    using Directory = Pri.LongPath.Directory;
    using DirectoryInfo = Pri.LongPath.DirectoryInfo;
    using File = Pri.LongPath.File;
    using FileSystemInfo = Pri.LongPath.FileSystemInfo;
    

    我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2017-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 2017-03-18
      • 2018-11-23
      • 2015-06-15
      • 1970-01-01
      相关资源
      最近更新 更多