How to validate an MSG Outlook File in C# .NET Framework

Cloudmersive
2 min readJul 26, 2020

--

Having the ability to validate MSG files will save you from so many problems later on. By eliminating these invalid files early, they won’t have a chance to throw a wrench in the works. The problem is that validating MSG format isn’t really that easy to do when approaching it manually. So instead we will be using an API that can handle MSG validation for us.

First we will need its client package to be installed using this command for NuGet:

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

Now we can move on to calling our function using the following lines of code:

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 ValidateDocumentMsgValidationExample{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 ValidateDocumentApi();var inputFile = new System.IO.Stream(); // System.IO.Stream | Input file to perform the operation on.try{// Validate if an MSG file is executableDocumentValidationResult result = apiInstance.ValidateDocumentMsgValidation(inputFile);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling ValidateDocumentApi.ValidateDocumentMsgValidation: " + e.Message );}}}}

And just like that, it’s all done with.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet