public void SetEncoding() { //ExStart //ExFor:LoadOptions.Encoding //ExSummary:Shows how to set the encoding with which to open a document. // A FileFormatInfo object will detect this file as being encoded in something other than UTF-7. FileFormatInfo fileFormatInfo = FileFormatUtil.DetectFileFormat(MyDir + "Encoded in UTF-7.txt"); Assert.AreNotEqual(Encoding.UTF7, fileFormatInfo.Encoding); // If we load the document with no loading configurations, Aspose.Words will detect its encoding as UTF-8. Document doc = new Document(MyDir + "Encoded in UTF-7.txt"); // The contents, parsed in UTF-8, create a valid string. // However, knowing that the file is in UTF-7, we can see that the result is incorrect. Assert.AreEqual("Hello world+ACE-", doc.ToString(SaveFormat.Text).Trim()); // In cases of ambiguous encoding such as this one, we can set a specific encoding variant // to parse the file within a LoadOptions object. LoadOptions loadOptions = new LoadOptions { Encoding = Encoding.UTF7 }; // Load the document while passing the LoadOptions object, then verify the document's contents. doc = new Document(MyDir + "Encoded in UTF-7.txt", loadOptions); Assert.AreEqual("Hello world!", doc.ToString(SaveFormat.Text).Trim()); //ExEnd }
public void WorkWithEncryptedDocument(SaveFormat saveFormat) { //ExStart //ExFor:OdtSaveOptions.#ctor(String) //ExSummary:Shows how to load and change odt/ott encrypted document. Document doc = new Document(MyDir + "Encrypted" + FileFormatUtil.SaveFormatToExtension(saveFormat), new LoadOptions("@sposeEncrypted_1145")); DocumentBuilder builder = new DocumentBuilder(doc); builder.MoveToDocumentEnd(); builder.Writeln("Encrypted document after changes."); // Saving document using new instance of OdtSaveOptions doc.Save(ArtifactsDir + "OdtSaveOptions.WorkWithEncryptedDocument" + FileFormatUtil.SaveFormatToExtension(saveFormat), new OdtSaveOptions("@sposeEncrypted_1145")); //ExEnd // Check that document is still encrypted with a password FileFormatInfo docInfo = FileFormatUtil.DetectFileFormat(ArtifactsDir + "OdtSaveOptions.WorkWithEncryptedDocument" + FileFormatUtil.SaveFormatToExtension(saveFormat)); Assert.IsTrue(docInfo.IsEncrypted); }
public void SaveDocumentEncryptedWithAPassword(SaveFormat saveFormat) { //ExStart //ExFor:OdtSaveOptions.#ctor(SaveFormat) //ExFor:OdtSaveOptions.Password //ExFor:OdtSaveOptions.SaveFormat //ExSummary:Shows how to encrypted your odt/ott documents with a password. Document doc = new Document(MyDir + "Document.docx"); OdtSaveOptions saveOptions = new OdtSaveOptions(saveFormat); saveOptions.Password = "******"; // Saving document using password property of OdtSaveOptions doc.Save(ArtifactsDir + "OdtSaveOptions.SaveDocumentEncryptedWithAPassword" + FileFormatUtil.SaveFormatToExtension(saveFormat), saveOptions); //ExEnd // Check that all documents are encrypted with a password FileFormatInfo docInfo = FileFormatUtil.DetectFileFormat( ArtifactsDir + "OdtSaveOptions.SaveDocumentEncryptedWithAPassword" + FileFormatUtil.SaveFormatToExtension(saveFormat)); Assert.IsTrue(docInfo.IsEncrypted); }
public void DetectDocumentEncryption() { //ExStart //ExFor:FileFormatUtil.DetectFileFormat(String) //ExFor:FileFormatInfo //ExFor:FileFormatInfo.LoadFormat //ExFor:FileFormatInfo.IsEncrypted //ExSummary:Shows how to use the FileFormatUtil class to detect the document format and encryption. Document doc = new Document(); // Configure a SaveOptions object to encrypt the document // with a password when we save it, and then save the document. OdtSaveOptions saveOptions = new OdtSaveOptions(SaveFormat.Odt); saveOptions.Password = "******"; doc.Save(ArtifactsDir + "File.DetectDocumentEncryption.odt", saveOptions); // Verify the file type of our document, and its encryption status. FileFormatInfo info = FileFormatUtil.DetectFileFormat(ArtifactsDir + "File.DetectDocumentEncryption.odt"); Assert.AreEqual(".odt", FileFormatUtil.LoadFormatToExtension(info.LoadFormat)); Assert.True(info.IsEncrypted); //ExEnd }
public void DetectDigitalSignatures() { //ExStart //ExFor:FileFormatUtil.DetectFileFormat(String) //ExFor:FileFormatInfo //ExFor:FileFormatInfo.LoadFormat //ExFor:FileFormatInfo.HasDigitalSignature //ExSummary:Shows how to use the FileFormatUtil class to detect the document format and presence of digital signatures. // Use a FileFormatInfo instance to verify that a document is not digitally signed. FileFormatInfo info = FileFormatUtil.DetectFileFormat(MyDir + "Document.docx"); Assert.AreEqual(".docx", FileFormatUtil.LoadFormatToExtension(info.LoadFormat)); Assert.False(info.HasDigitalSignature); CertificateHolder certificateHolder = CertificateHolder.Create(MyDir + "morzal.pfx", "aw", null); DigitalSignatureUtil.Sign(MyDir + "Document.docx", ArtifactsDir + "File.DetectDigitalSignatures.docx", certificateHolder, new SignOptions() { SignTime = DateTime.Now }); // Use a new FileFormatInstance to confirm that it is signed. info = FileFormatUtil.DetectFileFormat(ArtifactsDir + "File.DetectDigitalSignatures.docx"); Assert.True(info.HasDigitalSignature); // We can load and access the signatures of a signed document in a collection like this. Assert.AreEqual(1, DigitalSignatureUtil.LoadSignatures(ArtifactsDir + "File.DetectDigitalSignatures.docx").Count); //ExEnd }
static void Main(string[] args) { // Check for license and apply if exists string licenseFile = AppDomain.CurrentDomain.BaseDirectory + "Aspose.Words.lic"; if (File.Exists(licenseFile)) { // Apply Aspose.Words API License Aspose.Words.License license = new Aspose.Words.License(); // Place license file in Bin/Debug/ Folder license.SetLicense("Aspose.Words.lic"); } // The path to the document which is to be processed. string filePath = "../../data/document.doc"; FileFormatInfo info = FileFormatUtil.DetectFileFormat(filePath); if (info.HasDigitalSignature) { Console.WriteLine(string.Format("Document {0} has digital signatures, they will be lost if you open/save this document with Aspose.Words.", new FileInfo(filePath).Name)); } else { Console.WriteLine("Document has no digital signature."); } }
static void Main(string[] args) { // Check for an Aspose.Words license file in the local file system and apply it, if it exists. string licenseFile = AppDomain.CurrentDomain.BaseDirectory + "Aspose.Words.lic"; if (File.Exists(licenseFile)) { Aspose.Words.License license = new Aspose.Words.License(); // Use the license from the bin/debug/ Folder. license.SetLicense("Aspose.Words.lic"); } string filePath = "../../data/document.doc"; // Determine whether this document contains a digital signature. FileFormatInfo info = FileFormatUtil.DetectFileFormat(filePath); if (info.HasDigitalSignature) { Console.WriteLine($"Document {new FileInfo(filePath).Name} has digital signatures, they will be lost if you open/save this document with Aspose.Words.", new FileInfo(filePath).Name); } else { Console.WriteLine("Document has no digital signature."); } }
public void VerifyEncryptedDocument() { //ExStart:VerifyEncryptedDocument FileFormatInfo info = FileFormatUtil.DetectFileFormat(MyDir + "Encrypted.docx"); Console.WriteLine(info.IsEncrypted); //ExEnd:VerifyEncryptedDocument }
public static void VerifyODTdocument(string dataDir) { // ExStart:VerifyODTdocument FileFormatInfo info = FileFormatUtil.DetectFileFormat(dataDir + @"encrypted.odt"); Console.WriteLine(info.IsEncrypted); // ExEnd:VerifyODTdocument }
static void Main(string[] args) { string filePath = @"..\..\..\..\Sample Files\"; FileFormatInfo info = FileFormatUtil.DetectFileFormat(filePath + "MyDocument.docx"); Console.WriteLine("The document format is: " + FileFormatUtil.LoadFormatToExtension(info.LoadFormat)); Console.WriteLine("Document is encrypted: " + info.IsEncrypted); Console.WriteLine("Document has a digital signature: " + info.HasDigitalSignature); }
static void Main(string[] args) { string MyDir = @"E:\Aspose\Aspose Vs VSTO\Aspose.Words Features missing in VSTO 1.1\Sample Files\"; FileFormatInfo info = FileFormatUtil.DetectFileFormat(MyDir + "Detect_the_File_Format.doc"); Console.WriteLine("The document format is: " + FileFormatUtil.LoadFormatToExtension(info.LoadFormat)); Console.WriteLine("Document is encrypted: " + info.IsEncrypted); Console.WriteLine("Document has a digital signature: " + info.HasDigitalSignature); }
public void OpenChmFile() { FileFormatInfo info = FileFormatUtil.DetectFileFormat(MyDir + "HTML help.chm"); Assert.AreEqual(info.LoadFormat, LoadFormat.Chm); LoadOptions loadOptions = new LoadOptions(); loadOptions.Encoding = Encoding.GetEncoding("windows-1251"); Document doc = new Document(MyDir + "HTML help.chm", loadOptions); }
public FileNode(string name, string absolutePath, string extension, bool isShared, bool isRegional, ulong offset, ulong compressedSize, ulong decompressedSize, bool isCompressed, Func <List <string> > getSharedFiles) : base(name, absolutePath, isShared, isRegional) { Extension = extension; Offset = offset; IsCompressed = isCompressed; CompressedSize = compressedSize; DecompressedSize = decompressedSize; Description = FileFormatInfo.GetDescription(Extension); this.getSharedFiles = getSharedFiles; }
public static void Run() { // ExStart:DetectDifferentFileFormats // The path to the File directory. string dataDir = RunExamples.GetDataDir_Email(); // Detect file format and Gets the detected load format FileFormatInfo info = FileFormatUtil.DetectFileFormat(dataDir + "message.msg"); Console.WriteLine("The message format is: " + info.FileFormatType); // ExEnd:DetectDifferentFileFormats }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Load File FileFormatInfo finfo = FileFormatUtil.DetectFileFormat(dataDir + "sample.xls"); Console.WriteLine(finfo.FileFormatType == FileFormatType.Excel95); // ExEnd:1 }
public bool CheckWordFileForDigitalSignatures(string fileLocation) { FileFormatInfo info = FileFormatUtil.DetectFileFormat(fileLocation); if (info.HasDigitalSignature) { return(true); } else { return(false); } }
public void DetectDocumentSignatures() { //ExStart:DetectDocumentSignatures FileFormatInfo info = FileFormatUtil.DetectFileFormat(MyDir + "Digitally signed.docx"); if (info.HasDigitalSignature) { Console.WriteLine( $"Document {Path.GetFileName(MyDir + "Digitally signed.docx")} has digital signatures, " + "they will be lost if you open/save this document with Aspose.Words."); } //ExEnd:DetectDocumentSignatures }
internal SearchDocumentFormatInfoObject(FileFormatInfo ffInfo) : base(new SimpleProviderPropertyBag()) { base.SetExchangeVersion(ExchangeObjectVersion.Current); this[SimpleProviderObjectSchema.Identity] = new SearchDocumentFormatId(ffInfo.Id); this[SearchDocumentFormatInfoSchema.DocumentClass] = ffInfo.DocumentClass; this[SearchDocumentFormatInfoSchema.Enabled] = ffInfo.Enabled; this[SearchDocumentFormatInfoSchema.Extension] = ffInfo.Extension; this[SearchDocumentFormatInfoSchema.FormatHandler] = ffInfo.FormatHandler; this[SearchDocumentFormatInfoSchema.IsBindUserDefined] = ffInfo.IsBindUserDefined; this[SearchDocumentFormatInfoSchema.IsFormatUserDefined] = ffInfo.IsFormatUserDefined; this[SearchDocumentFormatInfoSchema.MimeType] = ffInfo.Mime; this[SearchDocumentFormatInfoSchema.Name] = ffInfo.Name; }
public static void Run() { // ExStart:1 //Source directory string sourceDir = RunExamples.Get_SourceDirectory(); var filename = sourceDir + "encryptedBook1.out.tmp"; Stream stream = File.Open(filename, FileMode.Open); FileFormatInfo fileFormatInfo = FileFormatUtil.DetectFileFormat(stream, "1234"); // The password is 1234 Console.WriteLine("File Format: " + fileFormatInfo.FileFormatType); // ExEnd:1 }
public static void Run() { // ExStart:DetectFileFormatAndEncryption // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); //Detect file format FileFormatInfo info = FileFormatUtil.DetectFileFormat(dataDir + "Book1.xlsx"); //Gets the detected load format Console.WriteLine("The spreadsheet format is: " + FileFormatUtil.LoadFormatToExtension(info.LoadFormat)); //Check if the file is encrypted. Console.WriteLine("The file is encrypted: " + info.IsEncrypted); // ExEnd:DetectFileFormatAndEncryption }
public void DetectFileFormat() { //ExStart //ExFor:FileFormatUtil.DetectFileFormat(String) //ExFor:FileFormatInfo //ExFor:FileFormatInfo.LoadFormat //ExFor:FileFormatInfo.IsEncrypted //ExFor:FileFormatInfo.HasDigitalSignature //ExSummary:Shows how to use the FileFormatUtil class to detect the document format and other features of the document. FileFormatInfo info = FileFormatUtil.DetectFileFormat(MyDir + "Document.doc"); Console.WriteLine("The document format is: " + FileFormatUtil.LoadFormatToExtension(info.LoadFormat)); Console.WriteLine("Document is encrypted: " + info.IsEncrypted); Console.WriteLine("Document has a digital signature: " + info.HasDigitalSignature); //ExEnd }
public static void Run() { //Source directory string sourceDir = RunExamples.Get_SourceDirectory(); //Detect file format FileFormatInfo info = FileFormatUtil.DetectFileFormat(sourceDir + "sampleDetectFileFormatAndEncryption"); //Gets the detected load format Console.WriteLine("The spreadsheet format is: " + info.FileFormatType); //Check if the file is encrypted. Console.WriteLine("The file is encrypted: " + info.IsEncrypted); Console.WriteLine("DetectFileFormatAndEncryption executed successfully."); }
public static void Run() { //ExStart:DetectDocumentSignatures // The path to the documents directory. string dataDir = RunExamples.GetDataDir_LoadingAndSaving(); // The path to the document which is to be processed. string filePath = dataDir + "Document.Signed.docx"; FileFormatInfo info = FileFormatUtil.DetectFileFormat(filePath); if (info.HasDigitalSignature) { Console.WriteLine(string.Format("Document {0} has digital signatures, they will be lost if you open/save this document with Aspose.Words.", Path.GetFileName(filePath))); } //ExEnd:DetectDocumentSignatures }
static void Main(string[] args) { // The path to the document which is to be processed. string filePath = "../../data/document.doc"; FileFormatInfo info = FileFormatUtil.DetectFileFormat(filePath); if (info.HasDigitalSignature) { Console.WriteLine(string.Format("Document {0} has digital signatures, they will be lost if you open/save this document with Aspose.Words.", new FileInfo(filePath).Name)); } else { Console.WriteLine("Document has no digital signature."); } }
public void DetectEncoding() { //ExStart //ExFor:FileFormatInfo.Encoding //ExFor:FileFormatUtil //ExSummary:Shows how to detect encoding in an html file. // 'DetectFileFormat' not working on a non-html files FileFormatInfo info = FileFormatUtil.DetectFileFormat(MyDir + "Document.docx"); Assert.AreEqual(LoadFormat.Docx, info.LoadFormat); Assert.IsNull(info.Encoding); // This time the property will not be null info = FileFormatUtil.DetectFileFormat(MyDir + "Document.html"); Assert.AreEqual(LoadFormat.Html, info.LoadFormat); Assert.IsNotNull(info.Encoding); //ExEnd }
public void DetectDocumentSignatures() { //ExStart //ExFor:FileFormatUtil.DetectFileFormat(String) //ExFor:FileFormatInfo.HasDigitalSignature //ExId:DetectDocumentSignatures //ExSummary:Shows how to check a document for digital signatures before loading it into a Document object. // The path to the document which is to be processed. String filePath = MyDir + "Document.Signed.docx"; FileFormatInfo info = FileFormatUtil.DetectFileFormat(filePath); if (info.HasDigitalSignature) { Console.WriteLine("Document {0} has digital signatures, they will be lost if you open/save this document with Aspose.Words.", Path.GetFileName(filePath)); } //ExEnd }
public void DetectFileFormat_EnumConversions() { //ExStart //ExFor:FileFormatUtil.DetectFileFormat(Stream) //ExFor:FileFormatUtil.LoadFormatToExtension(LoadFormat) //ExFor:FileFormatUtil.ExtensionToSaveFormat(String) //ExFor:FileFormatUtil.SaveFormatToExtension(SaveFormat) //ExFor:FileFormatUtil.LoadFormatToSaveFormat(LoadFormat) //ExFor:Document.OriginalFileName //ExFor:FileFormatInfo.LoadFormat //ExSummary:Shows how to use the FileFormatUtil methods to detect the format of a document without any extension and save it with the correct file extension. // Load the document without a file extension into a stream and use the DetectFileFormat method to detect it's format. // These are both times where you might need extract the file format as it's not visible FileStream docStream = File.OpenRead( MyDir + "Document.FileWithoutExtension"); // The file format of this document is actually ".doc" FileFormatInfo info = FileFormatUtil.DetectFileFormat(docStream); // Retrieve the LoadFormat of the document. LoadFormat loadFormat = info.LoadFormat; // Let's show the different methods of converting LoadFormat enumerations to SaveFormat enumerations. // // Method #1 // Convert the LoadFormat to a String first for working with. The String will include the leading dot in front of the extension. String fileExtension = FileFormatUtil.LoadFormatToExtension(loadFormat); // Now convert this extension into the corresponding SaveFormat enumeration SaveFormat saveFormat = FileFormatUtil.ExtensionToSaveFormat(fileExtension); // Method #2 // Convert the LoadFormat enumeration directly to the SaveFormat enumeration. saveFormat = FileFormatUtil.LoadFormatToSaveFormat(loadFormat); // Load a document from the stream. Document doc = new Document(docStream); // Save the document with the original file name, " Out" and the document's file extension. doc.Save( ArtifactsDir + "Document.WithFileExtension" + FileFormatUtil.SaveFormatToExtension(saveFormat)); //ExEnd Assert.AreEqual(".doc", FileFormatUtil.SaveFormatToExtension(saveFormat)); }
public void DetectEncoding() { //ExStart //ExFor:FileFormatInfo.Encoding //ExFor:FileFormatUtil //ExSummary:Shows how to detect encoding in an html file. FileFormatInfo info = FileFormatUtil.DetectFileFormat(MyDir + "Document.html"); Assert.AreEqual(LoadFormat.Html, info.LoadFormat); // The Encoding property is used only when we create a FileFormatInfo object for an html document. Assert.AreEqual("Western European (Windows)", info.Encoding.EncodingName); Assert.AreEqual(1252, info.Encoding.CodePage); //ExEnd info = FileFormatUtil.DetectFileFormat(MyDir + "Document.docx"); Assert.AreEqual(LoadFormat.Docx, info.LoadFormat); Assert.IsNull(info.Encoding); }
public void DetectEncoding() { //ExStart //ExFor:FileFormatInfo.Encoding //ExFor:FileFormatUtil //ExSummary:Shows how to detect encoding in an html file. // 'DetectFileFormat' not working on a non-html files FileFormatInfo info = FileFormatUtil.DetectFileFormat(MyDir + "Document.doc"); Assert.AreEqual(LoadFormat.Doc, info.LoadFormat); Assert.IsNull(info.Encoding); // This time the property will not be null info = FileFormatUtil.DetectFileFormat(MyDir + "Document.LoadFormat.html"); Assert.AreEqual(LoadFormat.Html, info.LoadFormat); Assert.IsNotNull(info.Encoding); // It now has some more useful information Assert.AreEqual("iso-8859-1", info.Encoding.BodyName); //ExEnd }
public static void Run() { // ExStart:DetectVisioFileFormat // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Intro(); // Load an existing Visio file in the stream FileStream st = new FileStream(dataDir + "Drawing1.vsdx", FileMode.Open); // Detect file format using the direct file path FileFormatInfo info = FileFormatUtil.DetectFileFormat(dataDir + "Drawing1.vsdx"); // Detect file format using the direct file path FileFormatInfo infoFromStream = FileFormatUtil.DetectFileFormat(st); // Get the detected file format Console.WriteLine("The spreadsheet format is: " + info.FileFormatType); // Get the detected file format from the file stream Console.WriteLine("The spreadsheet format is (from the file stream): " + info.FileFormatType); // ExEnd:DetectVisioFileFormat }