How to get document type information in C# .NET Framework

Cloudmersive
2 min readFeb 3, 2020

--

It is all to common to run across files with incorrect file extensions, or even no extensions at all. Identifying these problem files is tedious enough to do manually, so don’t even get me started on setting up a function for this in .NET Framework. It’s your lucky day, though. We have a much easier solution to try out.

Ok, first thing’s first. We need to install our API client. Simply go to your Package Manager console and activate this command:

Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 2.2.0

Next we can call ConvertDocumentAutodetectGetInfo, specify a file to identify, and let the API go to work.

using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;namespace Example{public class ConvertDocumentAutodetectGetInfoExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new ConvertDocumentApi();var inputFile = new System.IO.Stream(); // System.IO.Stream | Input file to perform the operation on.try{// Get document type informationAutodetectGetInfoResult result = apiInstance.ConvertDocumentAutodetectGetInfo(inputFile);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling ConvertDocumentApi.ConvertDocumentAutodetectGetInfo: " + e.Message );}}}}

That’s all there is to it! Our data will be presented to us in this format:

{
"Successful": true,
"DetectedFileExtension": "string",
"DetectedMimeType": "string",
"PageCount": 0,
"Author": "string",
"DateModified": "2020-02-03T04:52:11.076Z",
"AlternateFileTypeCandidates": [
{
"Probability": 0,
"DetectedFileExtension": "string",
"DetectedMimeType": "string"
}
]
}

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet