C # solve PathTooLongException by overwriting the entire System. IO

Source: Internet
Author: User

Recently, because the company's file management system needs to support long file names, that is, the limit of 260 characters, the company found relevant information online and found a dll written by a foreign cool man, based on the original author, we have added some of the methods we need to implement. The method is as follows:

If you need to retrieve the dll, leave your email address or upload it to 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;            }        }


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.