How can I use FileInfo class, avoiding PathTooLongException?

后端 未结 4 1372
遇见更好的自我
遇见更好的自我 2020-12-03 14:17

How can I use (to avoid PathTooLongException):

System.IO.FileInfo

with paths bigger than 260 chars?

Are there similar classes/metho

4条回答
  •  爱一瞬间的悲伤
    2020-12-03 15:14

    I only needed to use the FullName property but was also receiving the PathTooLongException.

    Using reflection to extract the FullPath value was enough to solve my problem:

    private static string GetFullPath(FileInfo src)
    {
        return (string)src.GetType()
            .GetField("FullPath", BindingFlags.Instance|BindingFlags.NonPublic)
            .GetValue(src);
    }
    

提交回复
热议问题