C# 解决 PathTooLongException 重写了整个System.IO

最近,因为公司的档案管理系统需要支持长文件名,也就是260字符上限的问题,上网找了相关的资料,,并且找到了外国一个牛人写的dll,在原有作者的基础上加了我们需要实现的一些方法。所加方法如下:

如大家需要取dll,请留邮箱,或之后我上传到csdn.

public static DirectorySecurity GetDirectorySecurity(string longname){int length = 0;byte[] buffer;// = new byte[65536];bool ret = Win32Interop.GetFileSecurity(longname, (int)(SECURITY_INFORMATION.OWNER_SECURITY_INFORMATION | SECURITY_INFORMATION.GROUP_SECURITY_INFORMATION ), null, 0, out length);if (length > 0){buffer = new byte[length];ret = Win32Interop.GetFileSecurity(longname, (int)(SECURITY_INFORMATION.OWNER_SECURITY_INFORMATION | SECURITY_INFORMATION.GROUP_SECURITY_INFORMATION), buffer, (uint)length, out length);DirectorySecurity pSD = new DirectorySecurity();pSD.SetSecurityDescriptorBinaryForm(buffer);return pSD;}else{return null;}}public static DirectorySecurity GetDirectorySecurity(string longname, AccessControlSections sec){int length = 0;byte[] buffer;// = new byte[65536];bool ret = Win32Interop.GetFileSecurity(longname, (int)sec, null, 0, out length);if (length > 0){buffer = new byte[length];ret = Win32Interop.GetFileSecurity(longname, (int)sec, buffer, (uint)length, out length);DirectorySecurity pSD = new DirectorySecurity();pSD.SetSecurityDescriptorBinaryForm(buffer);return pSD;}else{return null;}}public static FileSecurity GetFileSecurity(string longname){int length = 0;byte[] buffer;// = new byte[65536];bool ret = Win32Interop.GetFileSecurity(longname, (int)(SECURITY_INFORMATION.OWNER_SECURITY_INFORMATION | SECURITY_INFORMATION.GROUP_SECURITY_INFORMATION), null, 0, out length);if (length > 0){buffer = new byte[length];ret = Win32Interop.GetFileSecurity(longname, (int)(SECURITY_INFORMATION.OWNER_SECURITY_INFORMATION | SECURITY_INFORMATION.GROUP_SECURITY_INFORMATION), buffer, (uint)length, out length);FileSecurity pSD = new FileSecurity();pSD.SetSecurityDescriptorBinaryForm(buffer);return pSD;}else{return null;}}public static FileSecurity GetFileSecurity(string longname,AccessControlSections sec){int length = 0;byte[] buffer;// = new byte[65536];bool ret = Win32Interop.GetFileSecurity(longname, (int)sec, null, 0, out length);if (length > 0){buffer = new byte[length];ret = Win32Interop.GetFileSecurity(longname, (int)sec, buffer, (uint)length, out length);FileSecurity pSD = new FileSecurity();pSD.SetSecurityDescriptorBinaryForm(buffer);return pSD;}else{return null;}}

要知道,当你一直在担心错过了什么的时候,

C# 解决 PathTooLongException 重写了整个System.IO

相关文章:

你感兴趣的文章:

标签云: