最近,因為公司的檔案管理系統需要支持長文件名,也就是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; } }