Link to home
Start Free TrialLog in
Avatar of Skerw
Skerw

asked on

error on docx file conversion using doc.saveas method

I am writing code to convert docx file into a text file in ASP.net form using VB.net server side script.
My code is working fine in development environment. Where as I get an error "Object reference not set to an instence of an object" When published.

The error is coming in the line doc.SaveAs(newfilename, newfileformat)

Here is my code snippet

**************************************
Sub wrdfile(ByVal flpath As String, ByVal flnames As String, ByVal conv As String)
       Dim filepath As String = flpath
        Dim newfilename As Object = conv & flnames.ToString & ".txt"
        Dim newfileformat As Object = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDOSText
        Dim wordapp As Microsoft.Office.Interop.Word.Application = New Microsoft.Office.Interop.Word.Application()
        newfilename = conv.ToString & flnames.ToString.Replace(".", "") & ".txt"
        Dim doc As Microsoft.Office.Interop.Word.Document = wordapp.Documents.Open(filepath, False)
        doc.SaveAs(newfilename, newfileformat)

        doc.Close()
        wordapp = Nothing
End sub
************************************************

here are the error details

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 293:        Dim doc As Microsoft.Office.Interop.Word.Document = wordapp.Documents.Open(filepath, False)
Line 294:        doc.SaveAs(newfilename, newfileformat)
Line 295:
Line 296:        doc.Close()
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Any help in resolving this is greatly appreciated

Thank You
Avatar of ChadFolden
ChadFolden

You may have already double checked, but are you sure that you have MS Word installed on the machine that's getting this error (sometimes the simple things are the most difficult thing to see)?  
if you are sure that MS office is installed, it might be an authority problem. run the application under administrator account.
Avatar of Skerw

ASKER

Guys,

Thank You for your responses.

ChadFolden: Yes, I am sure the MS office (including MS word) is installed on the machine.

Integam: I am not sure what do you mean by running application under administrator account. Can you give me steps on how to set it up that way?

Thank You,
-- Sree
login in with administrative account, and run your code.
Avatar of Skerw

ASKER

Yes, I logged in as administrator and ran the website from IE. I still get the same error.

It works perfectly as expected when I am running the code in VS environment..

:(

Any help is greatly appreciated.

Thank You,
ASKER CERTIFIED SOLUTION
Avatar of ChadFolden
ChadFolden

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Skerw

ASKER

Hi,

Yes, I did made the impoersonate to true and provided specific user in the set. Please see the attached screen shots that would describe the settings and issue.

I am not sure where else to change the configuration. I made sure whereever I see the authentication, there are all using the specific user who is an admin on the computer.

I am getting desparate. Any help in resolving this would be greatly appreciated.

Thank You

CorrectlyWorkin-While-Running-wi.jpg
Error-when-Using-IIS.jpg
I think it is an IIS problem, but not sure what.
Avatar of Skerw

ASKER

yes, I think so too. But not sure as to where is the problem and what user it is using while opening the word when running via IIS. At lease if I know who is the user it is using when running via IIS so I can provide proper rights to that user.

Does anyone know how to determine what is the user a process is using?

Any help is greatly appreciated.

Thank You.
I'm still guessing you're site is still using the anonymous user (why else would you get access denied).  Can you try disabling Anonymous Access all together (looks like it is still enabled).  
If you're the only one using the server where your app is installed, you can easily see who IIS is authenticating as by making a request and then looking at the Security Log in the Event Logs
Was just thinking too ... if winword.exe is really running as a specific user as you've defined, you should be able to verify and see who that is in Task Manager too (on the processes tab, but showing User Name field).
one last thing

does the user have access to the file?
the file to open or WinWord.exe?!
usually IIS runs under NETWORK SERVICES user
Avatar of Skerw

ASKER

Guys,

Thank you very much for your support and help on resolving this issue. yes, I made sure the access to run WinWord.exe. I am very very puzzled by the behavior of this on my Vista machine. Hence I published the site on a Win 2008 server (I did not want to touch it as it is a production server )  and changed the impersonate to a real account and it started working.

So, I now decided to upgrade this vista into Windows 7 and see what is going to happen..

I appreciate your help.

Sometimes, it is what it is and it is not worth wasting time.

Thank You,
well, you do your math.

we are sorry we couldn't help, sometimes; it cannot be fixed unless we are there.