public static OpenXmlPowerToolsDocument FromFileName(string fileName)
        {
            byte[] bytes = File.ReadAllBytes(fileName);
            Type   type;

            try
            {
                type = GetDocumentType(bytes);
            }
            catch (FileFormatException)
            {
                throw new PowerToolsDocumentException("Not an Open XML document.");
            }
            if (type == typeof(WordprocessingDocument))
            {
                return(new WmlDocument(fileName, bytes));
            }
            if (type == typeof(SpreadsheetDocument))
            {
                return(new SmlDocument(fileName, bytes));
            }
            if (type == typeof(PresentationDocument))
            {
                return(new PmlDocument(fileName, bytes));
            }
            if (type == typeof(Package))
            {
                OpenXmlPowerToolsDocument pkg = new OpenXmlPowerToolsDocument(bytes);
                pkg.FileName = fileName;
                return(pkg);
            }
            throw new PowerToolsDocumentException("Not an Open XML document.");
        }
 public PmlDocument(OpenXmlPowerToolsDocument original)
     : base(original)
 {
     if (GetDocumentType() != typeof(PresentationDocument))
     {
         throw new PowerToolsDocumentException("Not a Presentation document.");
     }
 }
 public SmlDocument(OpenXmlPowerToolsDocument original)
     : base(original)
 {
     if (GetDocumentType() != typeof(SpreadsheetDocument))
     {
         throw new PowerToolsDocumentException("Not a Spreadsheet document.");
     }
 }
 public WmlDocument(OpenXmlPowerToolsDocument original)
     : base(original)
 {
     if (GetDocumentType() != typeof(WordprocessingDocument))
     {
         throw new PowerToolsDocumentException("Not a Wordprocessing document.");
     }
 }
 public OpenXmlMemoryStreamDocument(OpenXmlPowerToolsDocument doc)
 {
     Document        = doc;
     DocMemoryStream = new MemoryStream();
     doc.WriteByteArray(DocMemoryStream);
     try
     {
         DocPackage = Package.Open(DocMemoryStream, FileMode.Open);
     }
     catch (Exception)
     {
         throw new PowerToolsDocumentException("Not an Open XML document.");
     }
 }
 public OpenXmlMemoryStreamDocument(OpenXmlPowerToolsDocument doc)
 {
     Document = doc;
     DocMemoryStream = new MemoryStream();
     doc.WriteByteArray(DocMemoryStream);
     try
     {
         DocPackage = Package.Open(DocMemoryStream, FileMode.Open);
     }
     catch (Exception)
     {
         throw new PowerToolsDocumentException("Not an Open XML document.");
     }
 }
        public static OpenXmlPowerToolsDocument FromDocument(OpenXmlPowerToolsDocument doc)
        {
            Type type = doc.GetDocumentType();

            if (type == typeof(WordprocessingDocument))
            {
                return(new WmlDocument(doc));
            }
            if (type == typeof(SpreadsheetDocument))
            {
                return(new SmlDocument(doc));
            }
            if (type == typeof(PresentationDocument))
            {
                return(new PmlDocument(doc));
            }
            return(null);    // This should not be possible from a valid OpenXmlPowerToolsDocument object
        }
 public OpenXmlPowerToolsDocument(OpenXmlPowerToolsDocument original)
 {
     DocumentByteArray = new byte[original.DocumentByteArray.Length];
     Array.Copy(original.DocumentByteArray, DocumentByteArray, original.DocumentByteArray.Length);
     FileName = original.FileName;
 }
 public WmlDocument(OpenXmlPowerToolsDocument original)
     : base(original)
 {
     if (GetDocumentType() != typeof(WordprocessingDocument))
         throw new PowerToolsDocumentException("Not a Wordprocessing document.");
 }
 public SmlDocument(OpenXmlPowerToolsDocument original)
     : base(original)
 {
     if (GetDocumentType() != typeof(SpreadsheetDocument))
         throw new PowerToolsDocumentException("Not a Spreadsheet document.");
 }
 public PmlDocument(OpenXmlPowerToolsDocument original)
     : base(original)
 {
     if (GetDocumentType() != typeof(PresentationDocument))
         throw new PowerToolsDocumentException("Not a Presentation document.");
 }
 public static OpenXmlPowerToolsDocument FromFileName(string fileName)
 {
     byte[] bytes = File.ReadAllBytes(fileName);
     Type type;
     try
     {
         type = GetDocumentType(bytes);
     }
     catch (FileFormatException)
     {
         throw new PowerToolsDocumentException("Not an Open XML document.");
     }
     if (type == typeof(WordprocessingDocument))
         return new WmlDocument(fileName, bytes);
     if (type == typeof(SpreadsheetDocument))
         return new SmlDocument(fileName, bytes);
     if (type == typeof(PresentationDocument))
         return new PmlDocument(fileName, bytes);
     if (type == typeof(Package))
     {
         OpenXmlPowerToolsDocument pkg = new OpenXmlPowerToolsDocument(bytes);
         pkg.FileName = fileName;
         return pkg;
     }
     throw new PowerToolsDocumentException("Not an Open XML document.");
 }
 public static OpenXmlPowerToolsDocument FromDocument(OpenXmlPowerToolsDocument doc)
 {
     Type type = doc.GetDocumentType();
     if (type == typeof(WordprocessingDocument))
         return new WmlDocument(doc);
     if (type == typeof(SpreadsheetDocument))
         return new SmlDocument(doc);
     if (type == typeof(PresentationDocument))
         return new PmlDocument(doc);
     return null;    // This should not be possible from a valid OpenXmlPowerToolsDocument object
 }
 public OpenXmlPowerToolsDocument(OpenXmlPowerToolsDocument original)
 {
     DocumentByteArray = new byte[original.DocumentByteArray.Length];
     Array.Copy(original.DocumentByteArray, DocumentByteArray, original.DocumentByteArray.Length);
     FileName = original.FileName;
 }