Response.Clear();
Response.Buffer = true;
Response.Charset = "utf-8 ";
Response.AppendHeader( "Content-Disposition ", "attachment;filename=FileFlow.doc ");
Response.ContentEncoding = System.Text.Encoding.GetEncoding( "utf-8 ");
Response.ContentType = "application/ms-word ";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.RenderControl(oHtmlTextWriter);
obj.RenderControl()属性的控件
Response.Write(oStringWriter.ToString());
Response.End();
上面这段代码是将页面到处为一个doc文件.代码执行没有问题.
但我发现每次到处时,都说丢失css文件.
我用的是vs2005,里面有App_Themes目录,再下面是red,和black两个样式的目录.
如果我不用样式,到处没有问题,如果用了样式,到处就说丢失文件.
请教这是怎么回事? 应该怎么解决?
------解决方案--------------------------------------------------------
因为你的aspx中有 <link href= "aa.cs "的样式表,word打开时,找不到这个表,所以会报这个错误.解决办法:this.RenderControl(oHtmlTextWriter==> 换成一个控件.如果要导出整个页.可以把body加个id= "body " runat= "Server "后台声明一下Protected HtmlGenderControl body; 然后用this.body.RenderControl(oHtmlTextWriter)