LitDev.LDZip.ExtractFile C# (CSharp) Method

ExtractFile() private static method

private static ExtractFile ( string rootFolder, System.IO.Packaging.ZipPackagePart contentFile ) : void
rootFolder string
contentFile System.IO.Packaging.ZipPackagePart
return void
        private static void ExtractFile(string rootFolder, ZipPackagePart contentFile)
        {
            try
            {
                string contentFilePath = contentFile.Uri.OriginalString.Replace('/', Path.DirectorySeparatorChar);
                if (contentFilePath.StartsWith(Path.DirectorySeparatorChar.ToString()))
                {
                    contentFilePath = contentFilePath.TrimStart(Path.DirectorySeparatorChar);
                }
                contentFilePath = Path.Combine(rootFolder, contentFilePath);
                if (Directory.Exists(Path.GetDirectoryName(contentFilePath)) != true)
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(contentFilePath));
                }
                FileStream newFileStream = System.IO.File.Create(contentFilePath);
                newFileStream.Close();
                byte[] content = new byte[contentFile.GetStream().Length];
                contentFile.GetStream().Read(content, 0, content.Length);
                System.IO.File.WriteAllBytes(contentFilePath, content);
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
        }