在服务器端打开ASP.NET操作Excel文件的权限。
 碰到操作Excel拒绝访问的错误。需要放开服务器端ASP.NET的访问权限,具体操作如下:
  在机器里找到有一个machine.config文件,用记事本打开文件,找到processModel Attributes,把它里面的userName="machine"改为userName="SYSTEM",保存,重新启动机器即可。

解决方案 »

  1.   

    http://www.dotnet247.com/247reference/msgs/26/132455.aspx
      

  2.   

    private void ToExcel(System.Web.UI.Control ctl)  
    {
    string strName = "d:\\test.xls";
    HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=" + strName);
    HttpContext.Current.Response.Charset ="UTF-8";
    HttpContext.Current.Response.ContentEncoding =System.Text.Encoding.Default;
    HttpContext.Current.Response.ContentType ="application/ms-excel";
    ctl.Page.EnableViewState =false;
    System.IO.StringWriter  tw = new System.IO.StringWriter() ;
    System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter (tw);
    ctl.RenderControl(hw);
    HttpContext.Current.Response.Write(tw.ToString());
    HttpContext.Current.Response.End();
    }试一试?
      

  3.   

    权限问题  试试在C:\WINNT\Microsoft.NET\Framework\v1.0.3705\CONFIG目录下更改machine.config文件中的<processModel 节
    将userName="machine" 改成userName="SYSTEM"