Subject: Create word file in asp.net,c#
Posted By: mohini Post Date: 2/14/2006 7:50:05 AM
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??

Reply By: bmains Reply Date: 2/14/2006 1:00:31 PM
How are you trying to create the word file?

Brian
Reply By: mohini Reply Date: 2/15/2006 1:51:18 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);
    oWordDoc.Activate();
    oWordApp.Selection.TypeText("This is the text");
    oWordApp.Selection.TypeParagraph();
    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?



Reply By: Imar Reply Date: 2/15/2006 3:34:13 AM
Isn't the solution in the very verbose error message you're getting? It almost explains step by step what to do.....

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply By: mohini Reply Date: 2/15/2006 6:05:49 AM
I have tried for the steps given in the error but still it is not working

Reply By: bmains Reply Date: 2/15/2006 8:36:33 AM
Add the ASPNET account write access to the folder you are trying to write to.  That is what Imar was talking about.

Brian
Reply By: mohini Reply Date: 2/17/2006 5:28:52 AM
I have added aspnet user and given the access right for read write ,then also it is not working

Reply By: bmains Reply Date: 2/17/2006 8:07:58 AM
Imar, could this be a dcomcnfg setup problem?

Brian
Reply By: Imar Reply Date: 2/17/2006 1:50:59 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
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply By: manish.sharma04 Reply Date: 3/2/2006 9:06:59 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.

Thanks,
Manish Sharma


Reply By: mohini Reply Date: 3/7/2006 11:52:14 PM
Thanks Manish ,



I added the line  <identity impersonate="true"></identity>
in web.config and it works fine

Thank you a lot
Bye,


Go to topic 40877

Return to index page 349
Return to index page 348
Return to index page 347
Return to index page 346
Return to index page 345
Return to index page 344
Return to index page 343
Return to index page 342
Return to index page 341
Return to index page 340