程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C# 解決 PathTooLongException 重寫了整個System.IO

C# 解決 PathTooLongException 重寫了整個System.IO

編輯:C#入門知識

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


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved