예제 #1
0
        /// <summary>
        /// Extracts all the embedded object from the Microsoft Office <paramref name="inputFile"/> to the
        /// <see cref="outputFolder"/> and returns the files with full path as a list of strings
        /// </summary>
        /// <param name="inputFile">The Microsoft Office file</param>
        /// <param name="outputFolder">The output folder</param>
        /// <returns>List with files or en empty list when there are nog embedded files</returns>
        /// <exception cref="ArgumentNullException">Raised when the <paramref name="inputFile"/> or <paramref name="outputFolder"/> is null or empty</exception>
        /// <exception cref="FileNotFoundException">Raised when the <sparamref name="inputFile"/> does not exist</exception>
        /// <exception cref="DirectoryNotFoundException">Raised when the <paramref name="outputFolder"/> does not exists</exception>
        /// <exception cref="OEFileIsCorrupt">Raised when the <paramref name="inputFile" /> is corrupt</exception>
        /// <exception cref="OEFileTypeNotSupported">Raised when the <paramref name="inputFile"/> is not supported</exception>
        /// <exception cref="OEFileIsPasswordProtected">Raised when the <paramref name="inputFile"/> is password protected</exception>
        public List <string> SaveToFolder(string inputFile, string outputFolder)
        {
            CheckFileNameAndOutputFolder(inputFile, outputFolder);

            var extension = GetExtension(inputFile);

            outputFolder = FileManager.CheckForBackSlash(outputFolder);

            try
            {
                switch (extension)
                {
                case ".ODT":
                case ".ODS":
                case ".ODP":
                    return(ExtractFromOpenDocumentFormat(inputFile, outputFolder));

                case ".DOC":
                case ".DOT":
                    // Word 97 - 2003
                    return(Word.SaveToFolder(inputFile, outputFolder));

                case ".DOCM":
                case ".DOCX":
                case ".DOTM":
                    // Word 2007 - 2013
                    return(ExtractFromOfficeOpenXmlFormat(inputFile, "/word/embeddings/", outputFolder));

                case ".RTF":
                    return(Rtf.SaveToFolder(inputFile, outputFolder));

                case ".XLS":
                case ".XLT":
                case ".XLW":
                    // Excel 97 - 2003
                    return(Excel.SaveToFolder(inputFile, outputFolder));

                case ".XLSB":
                case ".XLSM":
                case ".XLSX":
                case ".XLTM":
                case ".XLTX":
                    // Excel 2007 - 2013
                    return(ExtractFromOfficeOpenXmlFormat(inputFile, "/xl/embeddings/", outputFolder));

                case ".POT":
                case ".PPT":
                case ".PPS":
                    // PowerPoint 97 - 2003
                    return(PowerPoint.SaveToFolder(inputFile, outputFolder));

                case ".POTM":
                case ".POTX":
                case ".PPSM":
                case ".PPSX":
                case ".PPTM":
                case ".PPTX":
                    // PowerPoint 2007 - 2013
                    return(ExtractFromOfficeOpenXmlFormat(inputFile, "/ppt/embeddings/", outputFolder));

                default:
                    throw new OEFileTypeNotSupported("The file '" + Path.GetFileName(inputFile) +
                                                     "' is not supported, only .ODT, .DOC, .DOCM, .DOCX, .DOT, .DOTM, .RTF, .XLS, .XLSB, .XLSM, .XLSX, .XLT, " +
                                                     ".XLTM, .XLTX, .XLW, .POT, .PPT, .POTM, .POTX, .PPS, .PPSM, .PPSX, .PPTM and .PPTX are supported");
                }
            }
            catch (CFCorruptedFileException)
            {
                throw new OEFileIsCorrupt("The file '" + Path.GetFileName(inputFile) + "' is corrupt");
            }
        }