Wrox Programmer Forums
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 14th, 2006, 08:50 AM
Authorized User
 
Join Date: Jan 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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??

 
Old February 14th, 2006, 02:00 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

How are you trying to create the word file?

Brian
 
Old February 15th, 2006, 02:51 AM
Authorized User
 
Join Date: Jan 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?



 
Old February 15th, 2006, 04:34 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old February 15th, 2006, 07:05 AM
Authorized User
 
Join Date: Jan 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old February 15th, 2006, 09:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

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

Brian
 
Old February 17th, 2006, 06:28 AM
Authorized User
 
Join Date: Jan 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old February 17th, 2006, 09:07 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Imar, could this be a dcomcnfg setup problem?

Brian
 
Old February 17th, 2006, 02:50 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old March 2nd, 2006, 10:06 AM
Authorized User
 
Join Date: Mar 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

 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







Similar Threads
Thread Thread Starter Forum Replies Last Post
to create PDF from word file sunilbedre Excel VBA 0 November 29th, 2007 06:39 AM
How to create MS Word like Callout in .NET ashu_from_india Visual Studio 2005 0 July 12th, 2007 06:48 AM
Access denied, can't create xml file from ASP.NET goldablasha C# 3 February 27th, 2007 05:50 AM
Reading word file in asp.net 1.1 anujrathi ASP.NET 1.0 and 1.1 Professional 0 August 4th, 2006 01:09 AM
Can I create my own File Field control in ASP.Net vbmazza ASP.NET 1.0 and 1.1 Professional 1 February 22nd, 2006 11:45 AM





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