C# .NET / Excel To Pdf / Configure IIS Server For Interop Services
In this article, we will write a convert method from Excel to Pdf with C#.NET and we will set the necessary configuration to host on windows IIS server.
First, let’s open a project that we will work on for the pdf conversion process.
We will create a web api project, and then deploy to IIS server, so we will convert the files in a web api method.
Add a empty webapi controller to the project that named ConvertController.cs
And then, add a class library project that named CoreWinUtility, and right after we add a class named ConvertHelper.cs. We have Microsoft.Office.Interop.Excel library to add as a reference,
Here is our excel to pdf conversion method;
We will call the convertion method at our api controller;
When we call our api controller from the browser, we will get a series of errors, because there are some configurations we need to do on our IIS directory and on the windows server, like user permissions.
First of all, let’s give the read/write permission to the directory where located source excel files and pdf files will be created.
!! But I have to say that Microsoft Excel must be installed on the server !!
Ok, what is the next .. Let’s move on to other permissions and configurations now;
Find excel.exe file location and give permission its folder, for IIS_IUSRS user .
Open IIS Manager, and chhose yopur application pool, and then open advanced settings with right menu,
If your Excel program is 32 bit, you should enable app pool for 32bit programs also..( this option for older office programs)
Well.. in order to configure for dcom components ;
Go to [Start] -> [Run] and enter dcomcnfg
Find “Microsoft Excel Application” , open Identity tab, and set user/password for an server user,
After that, open security tab, and give permissions to IIS_USRS,
That’s all ! Call your conversion endpoint and check the result..