p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Professional (http://p2p.wrox.com/forumdisplay.php?f=215)
-   -   Create word file in asp.net,c# (http://p2p.wrox.com/showthread.php?t=38464)

mohini February 14th, 2006 08:50 AM

Create word file in asp.net,c#
Hi friends,
   I want to create a word file in asp.net in c#.But it is giving me error like asp.net dont't have valid access for the requested resource.plz tell me how to do it??

bmains February 14th, 2006 02:00 PM

How are you trying to create the word file?


mohini February 15th, 2006 02:51 AM

I have add reference to Micosoft.word dll in my project.This is the code:

Object missing=System.Reflection.Missing.Value;
    Object filename="D:\\DocFiles\\myfile.doc";
    object readOnly = false;
    object isVisible = true;

    Word.ApplicationClass oWordApp= new ApplicationClass();
    Word.Document oWordDoc=oWordApp.Documents.Add(ref missing,ref missing, ref missing,ref missing);
    oWordApp.Selection.TypeText("This is the text");
    oWordDoc.SaveAs(ref filename,ref missing,ref missing,ref missing,
        ref missing,ref missing,ref missing,ref missing,ref missing,
        ref missing,ref missing,
    ref missing,ref missing,ref missing,ref missing,ref missing);

    oWordApp.Application.Quit(ref missing,ref missing, ref missing);

but it is giving me error:

Access is denied.

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

Source Error:

Line 50: object isVisible = true;
Line 51: object missing = System.Reflection.Missing.Value;
Line 52: Word.ApplicationClass oWordApp = new Word.ApplicationClass();
Line 53:

please[?] tell me what is the solution.Should It requires some IIS settings?

Imar February 15th, 2006 04:34 AM

Isn't the solution in the very verbose error message you're getting? It almost explains step by step what to do.....

Imar Spaanjaars
Everyone is unique, except for me.

mohini February 15th, 2006 07:05 AM

I have tried for the steps given in the error but still it is not working

bmains February 15th, 2006 09:36 AM

Add the ASPNET account write access to the folder you are trying to write to. That is what Imar was talking about.


mohini February 17th, 2006 06:28 AM

I have added aspnet user and given the access right for read write ,then also it is not working

bmains February 17th, 2006 09:07 AM

Imar, could this be a dcomcnfg setup problem?


Imar February 17th, 2006 02:50 PM

Yeah, that's quite possible. I never tried to create Word files on the server in ASP.NET, but that might indeed be necessary to make it work.

Mohini: check out this thread: http://p2p.wrox.com/topic.asp?TOPIC_ID=14057

Imar Spaanjaars
Everyone is unique, except for me.

manish.sharma04 March 2nd, 2006 10:06 AM

 This is the common error while providing an access to any file.
Error itself contains the answer of the problem.
Please do <identity impersonate="true"> in web.config
check if it is working fine otherwise create one local user and set the identity impersonate = true for it.

It should work fine.

Manish Sharma

All times are GMT -4. The time now is 02:58 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.