I am trying to convert docx file into pdf and I have been successful to convert pdf on my local pc.
Steps which i have followed in visual studio 2010
is to
click on Add reference --> Click to COM -->select "Microsoft Word 12.0 Object Library" and cliked ok
My web config gets modified and added the assembly
<add assembly="Microsoft.Office.Interop.Word, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"/>
My .cs code for converting doc to pdf is
using Microsoft.Office.Interop.Word;//Name Space
protected void Page_Load(object sender, EventArgs e)//Coading on page load
{
Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();
wordDocument = appWord.Documents.Open(Server.MapPath("~/convert/goodquest.docx"));
wordDocument.ExportAsFixedFormat(Server.MapPath("~/convert/goodquest.pdf"), WdExportFormat.wdExportFormatPDF);
}
public Microsoft.Office.Interop.Word.Document wordDocument { get; set; }
All works fine in local
but when i upload
all this changes on web
.
Errors such as
Could not load file or assembly 'Microsoft.Office.Interop.Word, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.
are showing up.
How should i resolve this problem
I have also tried downloading "Microsoft Office 2010: Primary Interop Assemblies Redistributable" from link Here but it converted my "Version=12.0.0.0" to "Version=14.0.0.0" when i follow steps which i have told you about before as " click on Add reference --> Click to COM........"
Copy paste the Microsoft.Office.Interop.Word.dll
into bin folder in server.
It's may be added in this path
%ProgramFiles%\Microsoft Visual Studio 12.0\Visual Studio Tools for Office\PIA\
but i don't know is it correct : more details please see this MSDN Link
else, You can download this dll : https://stackoverflow.com/a/6309218/2218635
Have you copied DLL (Microsoft.Office.Interop.Word) to the executable path?
you have to copy this DLL to local path else the Microsoft office must be installed on this server.
Looking into error it seems that application is not able to find the file in specified path.
By default application will find the DLL first into GAC else into local path. There can be other reason like the version is different, in such case also you will get similar error.
You have missed the dell version.
Please download correct version of the dll.
Correct procedure to use Word in C# Projects is:
- Add reference to Word Interop Library(Assembly)
- Add Excel in
using
section
- Now use it in your coding.
The first step will work if you have Office(Word) Installed in your PC. If not then install. Then add reference to Microsoft.Office.Interop.Word
of the version you need.
a. If list doesn't shows the desire version then you may have another vision of Office with Word installed. By The Way, you can use any.
b. If you don't find anything like Microsoft.Office.Interop
THEN may be office not installed OR you have Office 2013 or later. For higher version you can add assembly by going into COM tab of add-reference windows and add Microsoft Word {version-no} Object Library
. This will add the same.
c. If you already have Microsoft.Office.Interop...
in References with yellow-triangle-mark THEN remove it first.
After that second step will totally work: using Word=Microsoft.Office.Interop.Word;
And finally as a third step you can create Word object by Word.Application wApp = new Word.Application();
.