Technology Towards Microsoft Headlines

Friday, September 12, 2008

ASP.NET Word document to text file Conversion

ASP.NET Word document to text file Conversion

Environment: Windows Server 2003ASP.NET 1.1, Office 2003

Recently I was looking for a solution to convert a word document to text file. I found code at some locations:

http://www.codeproject.com/aspnet/wordapplication.asp

http://msdn2.microsoft.com/en-us/library/tcyt0y1f(VS.80).aspx

While implementing the code I got following two errors:

Error 1. System.UnauthorizedAccessException: Access is denied.

It was occuring at below line : Word.ApplicationClass oWord = new Word.ApplicationClass();

My Research:

The problem was because of IIS Server not having appropriate rights to launch a Microsoft Word-document DCOM object.

Below solution worked for me:

a. start the tool "DCOMCNFG.EXE" (Component Services).

b. Go to Console Root --> Component Services --> Computers --> My Computer --> DCOM Config --> Microsoft Word Document --> Properties --> Security --> Launch Permissions --> edit. Add the appropriate user/group, like "NT AUTHORITY \ NETWORK SERVICE"

Error 2. Command Failed.

This error was coming at the below line:

Word.Document aDoc = vk_word_app.Documents.Open(ref fileName, ref missing, ref vk_read_only,ref missing, ref missing,ref missing, ref missing, ref missing, ref missing,ref missing, ref missing, ref vk_visible, ref missing, ref missing, ref missing,ref missing );

My Research:

The solution worked for me just by adding the below lines in the web.config file.

The same code works fine in a windows application as we have rights to open the word document there but while opening the document on web server (asp.net) the user account should be specified to open the account.

No comments:

Page copy protected against web site content infringement by Copyscape

Subscribe To Get Updates Directly To Your E-Mail

Enter your email address:

Delivered by FeedBurner