/// <summary>
        /// Gets and returns files of a specific document type
        /// </summary>
        /// <param name="directory">Directory Path</param>
        /// <param name="documentType">Document Type</param>
        /// <returns>String array containing file paths</returns>
        public static string[] GetFiles(string directory, DocumentType documentType)
        {
            // get all files using Directory.GetFiles approach
            string[] files = Directory.GetFiles(directory, "*.*");

            // return empty array if directory is empty
            if (files.Length == 0)
            {
                return new string[0];
            }

            List<string> result = new List<string>();

            foreach (string path in files)
            {
                using (FileFormatChecker fileFormatChecker = new FileFormatChecker(path))
                {
                    if (fileFormatChecker.VerifyFormat(documentType))
                    {
                        result.Add(path);
                    }
                }
            }

            return result.ToArray();
        }
        public void Get()
        {
            try
            {
                HttpResponseMessage response = new HttpResponseMessage();
                var httpRequest = HttpContext.Current.Request;
                if (httpRequest.Files.Count > 0)
                {
                    foreach (string file in httpRequest.Files)
                    {
                        var postedFile = httpRequest.Files[file];
                        var filePath = Utils._storagePath + "\\" + postedFile.FileName;
                        FileFormatChecker fileFormatChecker = new FileFormatChecker(postedFile.InputStream);
                        DocumentType documentType = fileFormatChecker.GetDocumentType();

                        if (fileFormatChecker.VerifyFormat(documentType))
                        {
                            postedFile.SaveAs(filePath);
                        }
                        else
                        {
                            throw new Exception("File format not supported.");
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }
 /// <summary>
 /// Gets and returns document type in the file
 /// </summary>
 /// <param name="path">File Path</param> 
 public static DocumentType GetDocumentType(string path)
 {
     using (FileFormatChecker fileFormatChecker = new FileFormatChecker(path))
     {
         return fileFormatChecker.GetDocumentType();
     }
 }
コード例 #4
0
        /// <summary>
        /// Gets and returns files of a specific document type
        /// </summary>
        /// <param name="directory">Directory Path</param>
        /// <param name="documentType">Document Type</param>
        /// <returns>String array containing file paths</returns>
        public static string[] GetFiles(string directory, DocumentType documentType)
        {
            // get all files using Directory.GetFiles approach
            string[] files = Directory.GetFiles(directory, "*.*");

            // return empty array if directory is empty
            if (files.Length == 0)
            {
                return(new string[0]);
            }

            List <string> result = new List <string>();

            foreach (string path in files)
            {
                using (FileFormatChecker fileFormatChecker = new FileFormatChecker(path))
                {
                    if (fileFormatChecker.VerifyFormat(documentType))
                    {
                        result.Add(path);
                    }
                }
            }

            return(result.ToArray());
        }
コード例 #5
0
 /// <summary>
 /// Gets and returns document type in the file
 /// </summary>
 /// <param name="path">File Path</param>
 public static DocumentType GetDocumentType(string path)
 {
     using (FileFormatChecker fileFormatChecker = new FileFormatChecker(path))
     {
         return(fileFormatChecker.GetDocumentType());
     }
 }
コード例 #6
0
        /// <summary>
        /// Gets and returns files of a specific document type
        /// </summary>
        /// <param name="directory">Directory Path</param>
        /// <param name="documentType">Document Type</param>
        /// <returns>File info array</returns>
        public static FileInfo[] GetFiles(this DirectoryInfo directoryInfo, DocumentType documentType)
        {
            FileInfo[] files = directoryInfo.GetFiles();

            // return empty array if directory is empty
            if (files.Length == 0)
            {
                return new FileInfo[0];
            }

            List<FileInfo> result = new List<FileInfo>();

            foreach (FileInfo fileInfo in files)
            {
                using (FileFormatChecker fileFormatChecker = new FileFormatChecker(fileInfo.FullName))
                {
                    if (fileFormatChecker.VerifyFormat(documentType))
                    {
                        result.Add(fileInfo);
                    }
                }
            }

            return result.ToArray();
        }
コード例 #7
0
        /// <summary>
        /// Gets and returns files of a specific document type
        /// </summary>
        /// <param name="directory">Directory Path</param>
        /// <param name="documentType">Document Type</param>
        /// <returns>File info array</returns>
        public static FileInfo[] GetFiles(this DirectoryInfo directoryInfo, DocumentType documentType)
        {
            FileInfo[] files = directoryInfo.GetFiles();

            // return empty array if directory is empty
            if (files.Length == 0)
            {
                return(new FileInfo[0]);
            }

            List <FileInfo> result = new List <FileInfo>();

            foreach (FileInfo fileInfo in files)
            {
                using (FileFormatChecker fileFormatChecker = new FileFormatChecker(fileInfo.FullName))
                {
                    if (fileFormatChecker.VerifyFormat(documentType))
                    {
                        result.Add(fileInfo);
                    }
                }
            }

            return(result.ToArray());
        }
コード例 #8
0
 /// <summary>
 /// Check FLV file format
 /// This method is supported by version 18.11 or higher
 /// </summary>
 public static void DetectFlvFormat()
 {
     using (FileFormatChecker checker = new FileFormatChecker(Common.MapSourceFilePath(filePath)))
     {
         if (checker.GetDocumentType() == DocumentType.Flv)
         {
             // The file is an FLV video
             Console.WriteLine("This is a valid FLV file...");
         }
     }
 }
        public JsonResult <List <PropertyItem> > Get(string file)
        {
            try
            {
                FileStream        original          = File.Open(Utils._storagePath + "\\" + file, FileMode.OpenOrCreate);
                FileFormatChecker fileFormatChecker = new FileFormatChecker(original);

                DocumentType        documentType = fileFormatChecker.GetDocumentType();
                List <PropertyItem> values       = new List <PropertyItem>();

                if (fileFormatChecker.VerifyFormat(documentType))
                {
                    switch (documentType)
                    {
                    case DocumentType.Doc:

                        DocFormat docFormat = new DocFormat(original);
                        values = AppendMetadata(docFormat.GetMetadata(), values);

                        break;

                    case DocumentType.Xls:

                        XlsFormat xlsFormat = new XlsFormat(original);
                        values = AppendMetadata(xlsFormat.GetMetadata(), values);

                        break;

                    case DocumentType.Pdf:

                        PdfFormat pdfFormat = new PdfFormat(original);
                        values = AppendMetadata(pdfFormat.GetMetadata(), values);
                        values = AppendXMPData(pdfFormat.GetXmpData(), values);

                        break;

                    case DocumentType.Png:

                        PngFormat pngFormat = new PngFormat(original);
                        values = AppendMetadata(pngFormat.GetMetadata(), values);
                        values = AppendXMPData(pngFormat.GetXmpData(), values);

                        break;

                    case DocumentType.Jpeg:

                        JpegFormat jpegFormat = new JpegFormat(original);
                        values = AppendMetadata(jpegFormat.GetMetadata(), values);
                        values = AppendXMPData(jpegFormat.GetXmpData(), values);

                        break;

                    case DocumentType.Gif:

                        GifFormat gifFormat = new GifFormat(original);
                        values = AppendMetadata(gifFormat.GetMetadata(), values);
                        values = AppendXMPData(gifFormat.GetXmpData(), values);

                        break;

                    case DocumentType.Bmp:

                        BmpFormat bmpFormat = new BmpFormat(original);
                        values = AppendMetadata(bmpFormat.GetMetadata(), values);

                        break;

                    case DocumentType.Msg:

                        OutlookMessage outlookMessage = new OutlookMessage(original);
                        values = AppendMetadata(outlookMessage.GetMsgInfo(), values);
                        break;

                    case DocumentType.Eml:

                        EmlFormat emlFormat = new EmlFormat(original);
                        values = AppendMetadata(emlFormat.GetEmlInfo(), values);
                        break;

                    case DocumentType.Dwg:

                        DwgFormat dwgFormat = new DwgFormat(original);
                        values = AppendMetadata(dwgFormat.GetMetadata(), values);
                        break;

                    case DocumentType.Dxf:

                        DxfFormat dxfFormat = new DxfFormat(original);
                        values = AppendMetadata(dxfFormat.GetMetadata(), values);
                        break;

                    default:

                        DocFormat defaultDocFormat = new DocFormat(original);
                        values = AppendMetadata(defaultDocFormat.GetMetadata(), values);

                        break;
                    }

                    return(Json(values));
                }
                else
                {
                    throw new Exception("File format not supported.");
                }
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }
        public HttpResponseMessage Get(string file)
        {
            try
            {
                File.Copy(Utils._storagePath + "\\" + file, Utils._storagePath + "\\Cleaned_" + file, true);
                FileStream        original          = File.Open(Utils._storagePath + "\\Cleaned_" + file, FileMode.Open, FileAccess.ReadWrite);
                FileFormatChecker fileFormatChecker = new FileFormatChecker(original);
                DocumentType      documentType      = fileFormatChecker.GetDocumentType();


                if (fileFormatChecker.VerifyFormat(documentType))
                {
                    switch (documentType)
                    {
                    case DocumentType.Doc:

                        DocFormat docFormat = new DocFormat(original);
                        docFormat.CleanMetadata();
                        docFormat.ClearBuiltInProperties();
                        docFormat.ClearComments();
                        docFormat.ClearCustomProperties();
                        docFormat.RemoveHiddenData(new DocInspectionOptions(DocInspectorOptionsEnum.All));

                        docFormat.Save(Utils._storagePath + "\\Cleaned_" + file);
                        break;

                    case DocumentType.Xls:

                        XlsFormat xlsFormat = new XlsFormat(original);
                        xlsFormat.CleanMetadata();
                        xlsFormat.ClearBuiltInProperties();
                        xlsFormat.ClearContentTypeProperties();
                        xlsFormat.ClearCustomProperties();
                        xlsFormat.RemoveHiddenData(new XlsInspectionOptions(XlsInspectorOptionsEnum.All));

                        xlsFormat.Save(Utils._storagePath + "\\Cleaned_" + file);

                        break;

                    case DocumentType.Pdf:

                        PdfFormat pdfFormat = new PdfFormat(original);
                        pdfFormat.CleanMetadata();
                        pdfFormat.ClearBuiltInProperties();
                        pdfFormat.ClearCustomProperties();
                        pdfFormat.RemoveHiddenData(new PdfInspectionOptions(PdfInspectorOptionsEnum.All));
                        pdfFormat.RemoveXmpData();

                        pdfFormat.Save(Utils._storagePath + "\\Cleaned_" + file);

                        break;

                    case DocumentType.Png:

                        PngFormat pngFormat = new PngFormat(original);
                        pngFormat.CleanMetadata();
                        pngFormat.RemoveXmpData();

                        pngFormat.Save(Utils._storagePath + "\\Cleaned_" + file);

                        break;

                    case DocumentType.Jpeg:

                        JpegFormat jpegFormat = new JpegFormat(original);
                        jpegFormat.CleanMetadata();
                        jpegFormat.RemoveExifInfo();
                        jpegFormat.RemoveGpsLocation();
                        jpegFormat.RemoveIptc();
                        jpegFormat.RemovePhotoshopData();
                        jpegFormat.RemoveXmpData();

                        jpegFormat.Save(original);

                        break;

                    case DocumentType.Bmp:

                        BmpFormat bmpFormat = new BmpFormat(original);
                        bmpFormat.CleanMetadata();

                        bmpFormat.Save(Utils._storagePath + "\\Cleaned_" + file);

                        break;

                    case DocumentType.Gif:

                        GifFormat gifFormat = new GifFormat(original);
                        gifFormat.CleanMetadata();
                        gifFormat.RemoveXmpData();

                        gifFormat.Save(Utils._storagePath + "\\Cleaned_" + file);

                        break;

                    case DocumentType.Msg:

                        OutlookMessage outlookMessage = new OutlookMessage(original);
                        outlookMessage.CleanMetadata();
                        outlookMessage.RemoveAttachments();

                        outlookMessage.Save(Utils._storagePath + "\\Cleaned_" + file);

                        break;

                    case DocumentType.Eml:

                        EmlFormat emlFormat = new EmlFormat(original);
                        emlFormat.CleanMetadata();
                        emlFormat.RemoveAttachments();

                        emlFormat.Save(Utils._storagePath + "\\Cleaned_" + file);

                        break;

                    case DocumentType.Dwg:

                        DwgFormat dwgFormat = new DwgFormat(original);
                        dwgFormat.CleanMetadata();

                        dwgFormat.Save(Utils._storagePath + "\\Cleaned_" + file);

                        break;

                    case DocumentType.Dxf:

                        DxfFormat dxfFormat = new DxfFormat(original);
                        dxfFormat.CleanMetadata();

                        dxfFormat.Save(Utils._storagePath + "\\Cleaned_" + file);

                        break;

                    default:

                        DocFormat defaultDocFormat = new DocFormat(original);
                        defaultDocFormat.CleanMetadata();
                        defaultDocFormat.ClearBuiltInProperties();
                        defaultDocFormat.ClearComments();
                        defaultDocFormat.ClearCustomProperties();
                        defaultDocFormat.RemoveHiddenData(new DocInspectionOptions(DocInspectorOptionsEnum.All));

                        defaultDocFormat.Save(Utils._storagePath + "\\Cleaned_" + file);

                        break;
                    }
                }
                else
                {
                    throw new Exception("File format not supported.");
                }

                using (var ms = new MemoryStream())
                {
                    original = File.OpenRead(Utils._storagePath + "\\Cleaned_" + file);
                    original.CopyTo(ms);
                    var result = new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new ByteArrayContent(ms.ToArray())
                    };
                    result.Content.Headers.ContentDisposition =
                        new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
                    {
                        FileName = "Cleaned_" + file
                    };
                    result.Content.Headers.ContentType =
                        new MediaTypeHeaderValue("application/octet-stream");

                    original.Close();
                    File.Delete(Utils._storagePath + "\\Cleaned_" + file);
                    return(result);
                }
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }