ASP.NET Word导出服务器权限配置[windows 2003]

System Requirements

  1. Microsoft Windows Server 2003 with Service Pack 1
  2. MS Word 2003
  3. .Net 2.0

Create a web application. Right click on reference and click on add reference. Select Com tab. Double click on Microsoft Word 11.0 Object Library.

Add following code to create a word file at a folder in root directory at server it is Word folder in my case.

Object missing = System.Reflection.Missing.Value;

string file = "myfile";

Object filename = Server.MapPath("Word/") + file;            

object readOnly = false;

object isVisible = true;

Microsoft.Office.Interop.Word.Application oWordApp;

try

{

// initializing Word Application

oWordApp= new Microsoft.Office.Interop.Word.Application();

// initializing Word Document  

Microsoft.Office.Interop.Word.Document oWordDoc = oWordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);

           

try

{

  oWordDoc.Activate();

    oWordApp.Selection.TypeText("This is the text");

    oWordApp.Selection.TypeParagraph();

    // Saving Word file

    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);

    }

    catch (Exception ex)

    {

       Response.Write(ex.Message);

    }

    finally

    {

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

       // Oppening Word file

       Response.Redirect("~/Word/"+file,true);

    }

}

catch (Exception Wex)

{
    Response.Write(Wex.Message);

}

Now set the Security Permission to the Folder and Com Server

  1. Right click on Word Folder select Properties.
  2. Go to Security tab and assign the following permissions to the users listed below:
    Security AccountPermissions
    ASP.NET Machine AccountModify, Read, Write
    IIS_WPGModify, Read, Write
    Internet Guest Account (IUSR_<MachineName>) *Read, Write
                            
    * These all the account created when IIS installed on the machine.Basicaly IUSR_<MachineName> is used for anonymous user to access the your website by default. But we can change this user to some other user.So please make sure that Internet Guest Account is the same security account that is used for Basic Authentication for anonymous access for this application. If not then give same permission to that user as IUSR_<MachineName>)

    Note: If any of the above given security accounts are not already present in the user list then please add the user by following the steps given below:
    1. Click on Add


    2. Click on Advanced -> Find Now
    3. Select the Particular user
    4. Click on ok


  3. DCOM Config changes

    • Go to Run and type coming and click OK.
    • Go to Component Services/Computers/My Computer/DCOM Config
    • Right click on Microsoft Word Application and go to Properties
    • Go to Security Tab
    • Click on Customize and Edit for each section and give Allow permission for each section to following users
      1. 1. ASP.NET Machine Account
      2. 2. IIS_WPG,
      3. 3. Internet Guest Account(IUSR_<MachineName>) *

       

      * Please make sure that Internet Guest Account is the same security account that is used for Basic Authentication for anonymous access for this application. If not then give same permission to that user as IUSR_<MachineName>

      Note: If any of the above mentioned user is not present in user list then please add that user as mentioned in step10 above.

    • Go to the Identity tab. Click on This User and assign a user having administrative privileges on the machine.

      Note: The Administrative user should have invoked MS Word at least once by logging on to the machine or a complete installation of MS Word 2003 should have been performed. No part of the installation should be remaining.


      原文来自:http://hi.baidu.com/upjoyce/blog/item/9c7233385290c82db9998f40.html


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值