ICSharpCode.SharpZipLib.Zip.ZipEntry.CleanName C# (CSharp) Method

CleanName() public static method

Cleans a name making it conform to Zip file conventions. Devices names ('c:\') and UNC share names ('\\server\share') are removed and forward slashes ('\') are converted to back slashes ('/'). Names are made relative by trimming leading slashes which is compatible with the ZIP naming convention.
The Zip name transform class is more flexible.
public static CleanName ( string name ) : string
name string The name to clean
return string
        public static string CleanName(string name)
        {
            if (name == null) {
                return string.Empty;
            }

            if (Path.IsPathRooted(name)) {
                // NOTE:
                // for UNC names...  \\machine\share\zoom\beet.txt gives \zoom\beet.txt
                name = name.Substring(Path.GetPathRoot(name).Length);
            }

            name = name.Replace(@"\", "/");

            while ((name.Length > 0) && (name[0] == '/')) {
                name = name.Remove(0, 1);
            }
            return name;
        }

Usage Example

Example #1
0
 internal ZipEntry(string name, int versionRequiredToExtract, int madeByInfo, CompressionMethod method)
 {
     this.externalFileAttributes = -1;
     this.method       = CompressionMethod.Deflated;
     this.zipFileIndex = -1L;
     base..ctor();
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (name.Length > 65535)
     {
         throw new ArgumentException("Name is too long", "name");
     }
     if (versionRequiredToExtract != 0 && versionRequiredToExtract < 10)
     {
         throw new ArgumentOutOfRangeException("versionRequiredToExtract");
     }
     this.DateTime         = DateTime.Now;
     this.name             = ZipEntry.CleanName(name);
     this.versionMadeBy    = (ushort)madeByInfo;
     this.versionToExtract = (ushort)versionRequiredToExtract;
     this.method           = method;
 }