LEADTOOLS Support
Document
Document SDK Questions
DocumentFactory throws Invalid File Format error while loading a txt file without extension
#1
Posted
:
Tuesday, October 27, 2020 3:49:08 AM(UTC)
Groups: Registered
Posts: 60
I'm trying to load a txt file without extension(create a txt file and rename and remove extension). Now load the the txt document without extension using DocumentFactory. This throws invalid File Format Error. But this works if I do the same for pptx(create a pptx and rename and remove extension and load using DocumentFactory).
Code:
using var ms = new MemoryStream();
File.CopyTo(ms);
var bytes = ms.ToArray();
var leadDoc = DocumentFactory.LoadFromStream(Common.GetStreamFromBytes(bytes), new LoadDocumentOptions());
var extension = RasterCodecs.GetMimeTypeExtension(leadDoc.MimeType);
Please assist on what I'm missing.
#2
Posted
:
Tuesday, October 27, 2020 10:47:45 AM(UTC)
Groups: Registered, Manager, Tech Support, Administrators
Posts: 107
Was thanked: 9 time(s) in 9 post(s)
#3
Posted
:
Wednesday, October 28, 2020 11:31:59 AM(UTC)
Groups: Registered
Posts: 60
Dear Marcus Andra,
Thanks for the reply. txt files are loading in my code. But if I rename the txt file and remove the extension and try to load the file I get "Invalid file format". I noticed the file mime type becomes "application/octet-stream" when I remove the extension. So I tried loading the text file without .txt extension by whitelisting DocumentFactory.MimeTypes.Entries.Add("application/octet-stream", DocumentMimeTypeStatus.Allowed); but still I get the same error. please assist.
Thanks,
Abdul Rahman
#4
Posted
:
Wednesday, October 28, 2020 12:38:07 PM(UTC)
Groups: Registered, Manager, Tech Support, Administrators
Posts: 107
Was thanked: 9 time(s) in 9 post(s)
Hi Abdul,
When you load in a document, DocumentFactory checks the MIME type of the document, and it will make a call to DocumentMimeTypes.GetStatus. This method will check the entries dictionary and if the mime type key is found, it will output what's going on with your current workflow. The GetStatus method checks if the mime type is Allowed, Denied, or Unspecified. What are you currently seeing when calling GetStatus? Ideally if you see Allowed being passed, you should be able to load in the file.
https://www.leadtools.com/help/sdk/v21/dh/dox/documentmimetypes-getstatus.htmlhttps://www.leadtools.com/help/sdk/v21/dh/dox/documentmimetypestatus.htmlIn addition to this, what do you mean when you say that you are renaming the text file and removing the extension? Do you mean that you are saving it to a byte array and loading it through the use of MemoryStream for DocumentFactory.LoadFromStream?
Thanks,
Marcus Andra
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Document
Document SDK Questions
DocumentFactory throws Invalid File Format error while loading a txt file without extension
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.