FileFormatUtil.DetectFileFormat fails to detect text file

to reproduce:

  1. unzip the attached file
    call Aspose.Words.FileFormatUtil.DetectFileFormat for the text file
    expected to get Txt, but got Unknown

data_1000chars_Uknown.txt.zip (805 Bytes)

@Buffer2018

Based on your issue, it looks like Aspose.Words.FileFormatUtil.DetectFileFormat is not detecting the text file correctly. The file extension .txt is supported by Aspose.Words and typically supports plain text files. Here’s a step-by-step guide to troubleshoot this issue:

Steps to Reproduce the Issue

  1. Unzip the attachment:

    • Unzip the data_1000chars_Uknown.txt.zip file to extract data_1000chars_Uknown.txt.
  2. Call the method:

    Aspose.Words.FileFormatUtil.DetectFileFormat("path_to_your_extracted_file");
    

Expected Result

The expected result is to detect the file format as “Txt,” but it is detected as “Unknown.”

Troubleshooting Guide

  1. Verify the File Content:

    • Ensure that the file data_1000chars_Uknown.txt contains plain text without any encoded data or corruption.
    • Open it with a text editor to check the content.
  2. Verify Aspose Product Version:

    • Ensure that you are using the latest version of Aspose.Words.
    • You can download the latest version or check for updates here.
  3. Check the File Path:

    • Ensure that the file path provided to the DetectFileFormat method is accurate and accessible.
    • You can use an absolute path to avoid any path-related issues.
  4. Run a Simplified Code:

    • Test with a simple code to ensure there are no external factors causing the issue.
    using Aspose.Words;
    
    public class Program
    {
        public static void Main()
        {
            string filePath = "C:\\path_to_your_file\\data_1000chars_Uknown.txt";
            Aspose.Words.FileFormatInfo formatInfo = FileFormatUtil.DetectFileFormat(filePath);
            Console.WriteLine(formatInfo.FileFormat);
        }
    }
    

Example Youtube Video

You can check out the following Youtube Video demonstrating how to use FileFormatUtil.DetectFileFormat method with Aspose.Words.

Reference Documentation

For further details, please refer to the DetectFileFormat documentation on the Aspose website.

Conclusion

Please follow these steps and verify your setup. If the issue persists, you may want to contact Aspose support with more detailed information about your environment and the files used.

Should I ask anything further from you to better assist you with this issue?

the file can be opened with notepad / notepad++ without an issue.

@Buffer2018 Actually any file can be considered as TXT document, to properly detect TXT format it is required to exclude other formats. TXT is kind of “last resort format” for a file.
Even if FileFormatUtil.DetectFileFormat cannot detect your document as TXT. You can load the document using the following code and it will be loaded as TXT:

Document doc = new Document(@"C:\Temp\in.txt");
Console.WriteLine(doc.OriginalLoadFormat);

i understand, but the functionality im looking here is to identify (with some kind of certainty) that a file contains text. the attached file is a plain UTF-8 text file, but still is detected as Unknown and not as Txt.

@Buffer2018
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-28484

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.