/// <summary> /// Gets custom properties of Xls file /// </summary> public static void GetCustomProperties() { try { //ExStart:GetCustomDocumentPropertiesXlsFormat // initialize XlsFormat XlsFormat xlsFormat = new XlsFormat(Common.MapSourceFilePath(filePath)); // initialize XlsMetadata XlsMetadata xlsMetadata = xlsFormat.DocumentProperties; Console.WriteLine("\nCustom Properties"); foreach (KeyValuePair <string, PropertyValue> keyValuePair in xlsMetadata) { // check if property is not built-in if (!xlsMetadata.IsBuiltIn(keyValuePair.Key)) { // get property value PropertyValue propertyValue = xlsMetadata[keyValuePair.Key]; Console.WriteLine("Key: {0}, Type:{1}, Value: {2}", keyValuePair.Key, propertyValue.Type, propertyValue); } } //ExEnd:GetCustomDocumentPropertiesXlsFormat } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Updates document properties of Xls file and creates output file /// </summary> public static void UpdateDocumentProperties() { try { //ExStart:UpdateBuiltinDocumentPropertiesXlsFormat // initialize XlsFormat XlsFormat xlsFormat = new XlsFormat(Common.MapSourceFilePath(filePath)); // initialize XlsMetadata XlsMetadata xlsMetadata = xlsFormat.DocumentProperties; //update document property... xlsMetadata.Author = "New author"; xlsMetadata.Subject = "New subject"; //save output file... xlsFormat.Save(Common.MapDestinationFilePath(filePath)); //ExEnd:UpdateBuiltinDocumentPropertiesXlsFormat Console.WriteLine("File saved in destination folder."); } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Adds custom property in Xls file and creates output file /// </summary> public static void AddCustomProperty() { try { //ExStart:AddCustomDocumentPropertiesXlsFormat // initialize XlsFormat XlsFormat xlsFormat = new XlsFormat(Common.MapSourceFilePath(filePath)); // initialize XlsMetadata XlsMetadata metadata = xlsFormat.DocumentProperties; string propertyName = "New Custom Property"; string propertyValue = "123"; // check if property already exists if (!metadata.ContainsKey(propertyName)) { // add property metadata.Add(propertyName, propertyValue); } // save file in destination folder xlsFormat.Save(Common.MapDestinationFilePath(filePath)); //ExEnd:AddCustomDocumentPropertiesXlsFormat Console.WriteLine("File saved in destination folder."); } catch (Exception exp) { Console.WriteLine(exp.Message); } }
//ExEnd:SourceXlsFilePath #region working with builtin document properties /// <summary> /// Gets builtin document properties of Xls file /// </summary> public static void GetDocumentProperties() { try { //ExStart:GetBuiltinDocumentPropertiesXlsFormat // initialize XlsFormat XlsFormat xlsFormat = new XlsFormat(Common.MapSourceFilePath(filePath)); // initialize XlsMetadata XlsMetadata xlsMetadata = xlsFormat.DocumentProperties; // built-in properties Console.WriteLine("\nBuilt-in Properties"); foreach (KeyValuePair <string, PropertyValue> property in xlsMetadata) { // check if property is biltin if (xlsMetadata.IsBuiltIn(property.Key)) { Console.WriteLine("{0} : {1}", property.Key, property.Value); } } //ExEnd:GetBuiltinDocumentPropertiesXlsFormat } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Removes custom property of Xls file and creates output file /// </summary> public static void RemoveCustomProperties() { try { //ExStart:RemoveCustomDocumentPropertiesXlsFormat // initialize XlsFormat XlsFormat xlsFormat = new XlsFormat(Common.MapSourceFilePath(filePath)); // initialize XlsMetadata XlsMetadata metadata = xlsFormat.DocumentProperties; string propertyName = "New Custom Property"; // check if property is not built-in if (!metadata.IsBuiltIn(propertyName)) { // remove property metadata.Remove(propertyName); } else { Console.WriteLine("Can not remove built-in property."); } // save file in destination folder xlsFormat.Save(Common.MapDestinationFilePath(filePath)); //ExEnd:RemoveCustomDocumentPropertiesXlsFormat Console.WriteLine("File saved in destination folder."); } catch (Exception exp) { Console.WriteLine(exp.Message); } }
public static IWorkbook CreateWorkbook(XlsFormat fmt, Stream stream = null) { IWorkbook workbook = null; switch (fmt) { case XlsFormat.Xls: workbook = stream == null ? new HSSFWorkbook() : new HSSFWorkbook(stream); break; case XlsFormat.Xlsx: workbook = stream == null ? new XSSFWorkbook() : new XSSFWorkbook(stream); break; default: workbook = (stream == null || stream.Length == 0) ? new XSSFWorkbook() : CreateWorkbook(ConfirmXlsFormat(stream), stream); break; } return(workbook); }
/// <summary> /// Removes document properties of Xls file and creates output file /// </summary> public static void RemoveDocumentProperties() { try { //ExStart:RemoveBuiltinDocumentPropertiesXlsFormat // initialize XlsFormat XlsFormat xlsFormat = new XlsFormat(Common.MapSourceFilePath(filePath)); // clean metadata xlsFormat.CleanMetadata(); //save output file... xlsFormat.Save(Common.MapDestinationFilePath(filePath)); //ExEnd:RemoveBuiltinDocumentPropertiesXlsFormat Console.WriteLine("File saved in destination folder."); } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Gets custom properties of Xls file /// </summary> public static void GetCustomProperties() { try { //ExStart:GetCustomDocumentPropertiesXlsFormat // initialize XlsFormat XlsFormat xlsFormat = new XlsFormat(Common.MapSourceFilePath(filePath)); // initialize XlsMetadata XlsMetadata xlsMetadata = xlsFormat.DocumentProperties; Console.WriteLine("\nCustom Properties"); foreach (KeyValuePair<string, PropertyValue> keyValuePair in xlsMetadata) { // check if property is not built-in if (!xlsMetadata.IsBuiltIn(keyValuePair.Key)) { // get property value PropertyValue propertyValue = xlsMetadata[keyValuePair.Key]; Console.WriteLine("Key: {0}, Type:{1}, Value: {2}", keyValuePair.Key, propertyValue.Type, propertyValue); } } //ExEnd:GetCustomDocumentPropertiesXlsFormat } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Detects document protection /// </summary> public static void DetectProtection(string filePath) { try { //ExStart:DetectProtection FormatBase format = FormatFactory.RecognizeFormat(Common.MapSourceFilePath(filePath)); if (format.Type.ToString().ToLower() == "doc") { // initialize DocFormat DocFormat docFormat = new DocFormat(Common.MapSourceFilePath(filePath)); // determines whether document is protected by password Console.WriteLine(docFormat.IsProtected ? "Document is protected" : "Document is protected"); } else if (format.Type.ToString().ToLower() == "pdf") { // initialize DocFormat PdfFormat pdfFormat = new PdfFormat(Common.MapSourceFilePath(filePath)); // determines whether document is protected by password Console.WriteLine(pdfFormat.IsProtected ? "Document is protected" : "Document is protected"); } else if (format.Type.ToString().ToLower() == "xls") { // initialize DocFormat XlsFormat xlsFormat = new XlsFormat(Common.MapSourceFilePath(filePath)); // determines whether document is protected by password Console.WriteLine(xlsFormat.IsProtected ? "Document is protected" : "Document is protected"); } else if (format.Type.ToString().ToLower() == "ppt") { // initialize DocFormat PptFormat pptFormat = new PptFormat(Common.MapSourceFilePath(filePath)); // determines whether document is protected by password Console.WriteLine(pptFormat.IsProtected ? "Document is protected" : "Document is protected"); } else { Console.WriteLine("Invalid Format."); } //ExEnd:DetectProtection } catch (Exception exp) { Console.WriteLine("Exception occurred: " + exp.Message); } }
/// <summary> /// Gets comments and hidden sheets of Xls file /// </summary> public static void GetHiddenData() { try { //ExStart:GetHiddenDataInXls // initialize XlsFormat XlsFormat xlsFormat = new XlsFormat(Common.MapSourceFilePath(filePath)); // get hidden data XlsInspectionResult hiddenData = xlsFormat.InspectDocument(); // get hidden sheets XlsSheet[] hiddenSheets = hiddenData.HiddenSheets; // get comments XlsComment[] comments = hiddenData.Comments; if (comments.Length > 0) { foreach (XlsComment comment in comments) { Console.WriteLine("Comment: {0}, Column: {1}", comment.ToString(), comment.Column); } } else { Console.WriteLine("No comment found!"); } //ExEnd:GetHiddenDataInXls } catch (Exception exp) { Console.WriteLine(exp.Message); } }
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; } }
/// <summary> /// Clears custom properties of Xls file and creates output file /// </summary> public static void ClearCustomProperties() { try { //ExStart:ClearCustomPropertyXlsFormat // initialize XlsFormat XlsFormat xlsFormat = new XlsFormat(Common.MapSourceFilePath(filePath)); // use one of the following methods // method:1 - clear custom properties xlsFormat.ClearCustomProperties(); // method:2 - clear custom properties xlsFormat.DocumentProperties.ClearCustomData(); // save file in destination folder xlsFormat.Save(Common.MapDestinationFilePath(filePath)); //ExEnd:ClearCustomPropertyXlsFormat Console.WriteLine("File saved in destination folder."); } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Gets content type document properties of Xls file /// </summary> public static void GetContentTypeDocumentProperties() { try { //ExStart:GetContentTypeDocumentPropertiesXlsFormat // initialize XlsFormat XlsFormat xlsFormat = new XlsFormat(Common.MapSourceFilePath(filePath)); // get xls properties XlsMetadata xlsProperties = xlsFormat.DocumentProperties; // get content properties XlsContentProperty[] contentProperties = xlsProperties.ContentProperties; foreach (XlsContentProperty property in contentProperties) { Console.WriteLine("Property: {0}, value: {1}, type: {2}", property.Name, property.Value, property.PropertyType); } //ExEnd:GetContentTypeDocumentPropertiesXlsFormat } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Removes hidden data of Xls file /// </summary> public static void RemoveHiddenData() { try { //ExStart:RemoveHiddenDataInXls // initialize XlsFormat XlsFormat xlsFormat = new XlsFormat(Common.MapSourceFilePath(filePath)); // get hidden data XlsInspectionResult hiddenData = xlsFormat.InspectDocument(); // get hidden sheets XlsSheet[] hiddenSheets = hiddenData.HiddenSheets; // display hidden fields if (hiddenSheets.Length > 0) { // clear hidden sheets xlsFormat.RemoveHiddenData(new XlsInspectionOptions(XlsInspectorOptionsEnum.HiddenSheets)); Console.WriteLine("Hidden sheets removed."); // and commit changes xlsFormat.Save(); Console.WriteLine("Changes save successfully!"); } else Console.WriteLine("No sheets found."); //ExEnd:RemoveHiddenDataInXls } catch (Exception exp) { Console.WriteLine(exp.Message); } }
//ExEnd:SourceXlsFilePath #region working with builtin document properties /// <summary> /// Gets builtin document properties of Xls file /// </summary> public static void GetDocumentProperties() { try { //ExStart:GetBuiltinDocumentPropertiesXlsFormat // initialize XlsFormat XlsFormat xlsFormat = new XlsFormat(Common.MapSourceFilePath(filePath)); // initialize XlsMetadata XlsMetadata xlsMetadata = xlsFormat.DocumentProperties; // built-in properties Console.WriteLine("\nBuilt-in Properties"); foreach (KeyValuePair<string, PropertyValue> property in xlsMetadata) { // check if property is biltin if (xlsMetadata.IsBuiltIn(property.Key)) { Console.WriteLine("{0} : {1}", property.Key, property.Value); } } //ExEnd:GetBuiltinDocumentPropertiesXlsFormat } catch (Exception exp) { Console.WriteLine(exp.Message); } }
//ExEnd:ApplyLicense public static string CleanFile(string filePath) { try { try { //Apply license... ApplyLicense(); } catch (Exception exp) { MessageBox.Show("In Licence: " + exp.Message); } try { //Recognize format of file... FormatBase format = FormatFactory.RecognizeFormat(filePath); if (format.Type.ToString().ToLower() == "doc" || format.Type.ToString().ToLower() == "docx") { // initialize DocFormat... DocFormat docFormat = format as DocFormat; if (docFormat != null) { // get document properties... DocMetadata properties = new DocMetadata(); properties = docFormat.DocumentProperties; //Remove custom properties... foreach (KeyValuePair <string, PropertyValue> keyValuePair in properties) { if (!properties.IsBuiltIn(keyValuePair.Key)) { properties.Remove(keyValuePair.Key); } } //Reset built-in properties... properties.Author = ""; properties.Category = ""; properties.Comments = ""; properties.Company = ""; properties.ContentStatus = ""; properties.HyperlinkBase = ""; properties.Keywords = ""; properties.Manager = ""; properties.Title = ""; //Update metadata if file... MetadataUtility.UpdateMetadata(filePath, properties); } return("1"); } else if (format.Type.ToString().ToLower() == "xls" || format.Type.ToString().ToLower() == "xlsx") { //Initialize XlsFormat... XlsFormat xlsFormat = format as XlsFormat; if (xlsFormat != null) { //Get document properties... XlsMetadata properties = xlsFormat.DocumentProperties; //Remove custom properties... foreach (KeyValuePair <string, PropertyValue> keyValuePair in properties) { if (!properties.IsBuiltIn(keyValuePair.Key)) { properties.Remove(keyValuePair.Key); } } //Reset built-in properties... properties.Author = ""; properties.Category = ""; properties.Comments = ""; properties.Company = ""; properties.HyperlinkBase = ""; properties.Keywords = ""; properties.Manager = ""; properties.Title = ""; properties.Subject = ""; //Update metadata in files... MetadataUtility.UpdateMetadata(filePath, properties); } return("1"); } else if (format.Type.ToString().ToLower() == "ppt" || format.Type.ToString().ToLower() == "pptx") { //Initialize PptFormat... PptFormat pptFormat = format as PptFormat; if (pptFormat != null) { //Get document properties... PptMetadata properties = pptFormat.DocumentProperties; //Remove custom properties foreach (KeyValuePair <string, PropertyValue> keyValuePair in properties) { if (!properties.IsBuiltIn(keyValuePair.Key)) { properties.Remove(keyValuePair.Key); } } //Reset built-in properties... properties.Author = ""; properties.Category = ""; properties.Comments = ""; properties.Company = ""; properties.Keywords = ""; properties.Manager = ""; properties.Title = ""; properties.Subject = ""; //Update metadata of file... MetadataUtility.UpdateMetadata(filePath, properties); } return("1"); } else if (format.Type.ToString().ToLower() == "pdf") { // initialize PdfFormat... PdfFormat pdfFormat = format as PdfFormat; if (pdfFormat != null) { // get document properties... PdfMetadata properties = pdfFormat.DocumentProperties; // Remove custom properties... foreach (KeyValuePair <string, PropertyValue> keyValuePair in properties) { if (!properties.IsBuiltIn(keyValuePair.Key)) { properties.Remove(keyValuePair.Key); } } //Reset built-in properties... properties.Author = ""; properties.CreatedDate = DateTime.MinValue; properties.Keywords = ""; properties.ModifiedDate = DateTime.MinValue; properties.Subject = ""; properties.TrappedFlag = false; properties.Title = ""; //Update metadata of file... MetadataUtility.UpdateMetadata(filePath, properties); } return("1"); } else if (format.Type.ToString().ToLower() == "jpeg" || format.Type.ToString().ToLower() == "jpg") { //Get EXIF data if exists ExifMetadata exifMetadata = (ExifMetadata)MetadataUtility.ExtractSpecificMetadata(filePath, MetadataType.EXIF); //Get XMP data if exists XmpMetadata xmpMetadata = (XmpMetadata)MetadataUtility.ExtractSpecificMetadata(filePath, MetadataType.XMP); if (exifMetadata != null) { //Remove exif info... ExifInfo exifInfo = exifMetadata.Data; if (exifInfo.GPSData != null) { // set altitude, latitude and longitude to null values exifInfo.GPSData.Altitude = null; exifInfo.GPSData.Latitude = null; exifInfo.GPSData.LatitudeRef = null; exifInfo.GPSData.Longitude = null; exifInfo.GPSData.LongitudeRef = null; } exifInfo.BodySerialNumber = ""; exifInfo.CameraOwnerName = ""; exifInfo.CFAPattern = new byte[] { 0 }; } else { exifMetadata = new ExifMetadata(); } try { //Remove XMP data... XmpPacketWrapper xmpPacket = xmpMetadata.XmpPacket; if (xmpPacket != null) { if (xmpPacket.ContainsPackage(Namespaces.DublinCore)) { // if not - add DublinCore schema xmpPacket.AddPackage(new DublinCorePackage()); DublinCorePackage dublinCorePackage = (DublinCorePackage)xmpPacket.GetPackage(Namespaces.DublinCore); dublinCorePackage.Clear(); xmpMetadata.XmpPacket = xmpPacket; } } } catch { } //Update Exif info... try { MetadataUtility.UpdateMetadata(filePath, exifMetadata); } catch { } //Update XMP data... try { MetadataUtility.UpdateMetadata(filePath, xmpMetadata); } catch { } //Remove custom metadata if any... MetadataUtility.CleanMetadata(filePath); return("1"); } else if (format.Type.ToString().ToLower() == "png") { //Get XMP data... XmpMetadata xmpMetadata = (XmpMetadata)MetadataUtility.ExtractSpecificMetadata(filePath, MetadataType.XMP); try { //Remove XMP metadata... XmpPacketWrapper xmpPacket = xmpMetadata.XmpPacket; if (xmpPacket != null) { if (xmpPacket.ContainsPackage(Namespaces.DublinCore)) { // if not - add DublinCore schema xmpPacket.AddPackage(new DublinCorePackage()); DublinCorePackage dublinCorePackage = (DublinCorePackage)xmpPacket.GetPackage(Namespaces.DublinCore); dublinCorePackage.Clear(); xmpMetadata.XmpPacket = xmpPacket; //Update XMP metadata in file... MetadataUtility.UpdateMetadata(filePath, xmpMetadata); //Clean custom metadata if any... MetadataUtility.CleanMetadata(filePath); } } } catch { } return("1"); } else if (format.Type.ToString().ToLower() == "gif") { //Initialie GifFormat... GifFormat gifFormat = new GifFormat(filePath); //Check if Xmp supported... if (gifFormat.IsSupportedXmp) { //Get XMP data... XmpMetadata xmpMetadata = (XmpMetadata)MetadataUtility.ExtractSpecificMetadata(filePath, MetadataType.XMP); try { XmpPacketWrapper xmpPacket = xmpMetadata.XmpPacket; if (xmpPacket != null) { if (xmpPacket.ContainsPackage(Namespaces.DublinCore)) { // if not - add DublinCore schema xmpPacket.AddPackage(new DublinCorePackage()); DublinCorePackage dublinCorePackage = (DublinCorePackage)xmpPacket.GetPackage(Namespaces.DublinCore); dublinCorePackage.Clear(); xmpMetadata.XmpPacket = xmpPacket; //Update Xmp data in file... MetadataUtility.UpdateMetadata(filePath, xmpMetadata); //Clean custom metadata if any... MetadataUtility.CleanMetadata(filePath); } } } catch { } } return("1"); } else { return("Format not supported."); } } catch (Exception exp) { MessageBox.Show("Exception: " + exp.Message); return(exp.Message); } } catch (Exception exp) { return(exp.Message); } }
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; } }