How to create a Web-Based Document Viewer in C# .NET Framework

A web-based document viewer is a great way to add easy usability to your site or app, but can be a real challenge to get working properly. I’m not going to get into all that is required to parse and display each document type that we might want to display. Instead I will show you how to get support for all of them at once within a few minutes.

First we will need our package, like so:

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

Following that, we go ahead with calling our function:

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 ViewerToolsCreateSimpleExample{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 ViewerToolsApi();var inputFile = new System.IO.Stream(); // System.IO.Stream | Input file to perform the operation on.try{// Create a web-based viewerViewerResponse result = apiInstance.ViewerToolsCreateSimple(inputFile);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling ViewerToolsApi.ViewerToolsCreateSimple: " + e.Message );}}}}

And we are already done. Easy as that.

Image for post
Image for post

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store