cancel
Showing results for 
Search instead for 
Did you mean: 

Auto-discover FileType

Tharon_Rivera
Star Collaborator
Star Collaborator

Is there a method that will auto-discover a document's FileType?  I'm looking for something that goes through the same process as if I using the Upload form in the Unity client or uses known extensions that match up to the default system file types.

10 REPLIES 10

Hi Albert.

 

SCR: #167983 was closed and not implemented back in 2017.  If you feel there is still a need for the enhancement, feel free to post an Idea on Community.

 

Best wishes.

Scott_McLean
Elite Collaborator
Elite Collaborator

I agree. Most of the time, just accessing the file's extension should get you the right file type, and since the extension is how OnBase identifies a file, that's also the access the API gives you.

In cases where the file extension is insufficient to capture the file type (custom extensions, wrong extensions, etc.), I have had to build separate custom file identification classes.

You can take advantage of urlmon.dll, which contains classes and methods for looking at a file's MIME type. However, you will find that this has some significant disadvantages. For example, all MS Office XML file types (docx, xlsx, etc.) will be identified as pkZip files, since that's what they really are. So in cases like that, you would need to interrogate the XML files inside the zipped Office file to determine which type was in use.

You can open the file stream and read the initial bytes. For types that contain a signature (magic number), you should be able to identify them this way.

If you're uploading from a web page, consider taking advantage of the HTML5 file APIs. These do a great job identifying file types, and you can pass the type information along with the file stream.

Alternately, you could use a third-party utility or DLL that has already taken these steps and save yourself some programming time. The disadvantage here is that some of them have costs associated and some are slow.

The best course is to ensure that your files have correct extensions and then use them to determine the file type to use in OnBase.

Daniel_Quill
Elite Collaborator
Elite Collaborator

Hi Albert,

 

This SCR was closed and rejected by the development team.  As an API it would not be possible to detect the type of file being imported.  This would need to be done before the calls to import into OnBase.

 

This is something that can be developed outside of the OnBase API by reading the file extension or file signature to determine this type of file.

 

Go it, but getting the file type outside OnBase it not the challenge matching that with OnBase FileType is for me the challenge. 

 

Thanks for your quick respond 

What part of matching the OnBase FileTypes is the challenge?  The full list of FileTypes is located in the OnBase Configuration (Documents -> File Fomats).  From there I would image the use of a SWITCH/CASE block that would set the correct FileType by name or ID.

 

EXAMPLE:

 Hyland.Unity.FileType fileType;
switch (fileExt)
{
   case "pdf":
      fileType = app.Core.FileTypes.Find(16);
      break;
   case "gif":
   case "jpg":
   case "tiff":
   case "png":
      fileType = app.Core.FileTypes.Find(2);
      break;
   default:
      break;
}