Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Tuesday, October 27, 2020 3:49:08 AM(UTC)
Abdul Rahman

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.
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Tuesday, October 27, 2020 10:47:45 AM(UTC)
Marcus Andra

Groups: Registered, Manager, Tech Support, Administrators
Posts: 107

Was thanked: 9 time(s) in 9 post(s)

Hello Abdul,

I believe you are running into this issue because by default loading of a text file is disabled. You can find more information about this here:
https://www.leadtools.com/help/sdk/v21/dh/to/file-formats-text-file-format-txt.html
https://www.leadtools.com/support/forum/posts/t13906-

I see that you are wanting to load a txt file through the use of the DocumentFactory.LoadFromStream method. If this is the case, you'll want to first whitelist support of this file format through use of the DocumentMimeTypes Class. We have several examples on how you can approach both allowing and whitelisting file formats which should fix this issue you are seeing:
https://www.leadtools.com/help/sdk/v21/dh/dox/documentmimetypes.html

Thanks,
Marcus Andra
Developer Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 
#3 Posted : Wednesday, October 28, 2020 11:31:59 AM(UTC)
Abdul Rahman

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)
Marcus Andra

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.html

https://www.leadtools.com/help/sdk/v21/dh/dox/documentmimetypestatus.html

In 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.
LEAD Logo
 
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.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.059 seconds.