首页 新闻 搜索 专区 学院

发生了DDE错误,并且说明由于文件名或路径太长,请尝试重新命名该文件或将其复制到其他文件夹中

0
悬赏园豆:30 [已解决问题] 解决于 2008-12-22 15:03

在页面上下载EXECL文件时出错: 发生了DDE错误,并且该错误的说明由于太长而不能显示。如果文件名或路径太长,请尝试重新命名该文件或将其复制到其他文件夹中。
可是同样的路径同样的文件名下载WORD或者图片文件都没问题,而且只有EXECL文件会出这个错,请问这个问题如何解决?

问题补充: /// <summary> /// 将Web控件或页面信息导出(带文件名参数) /// </summary> /// <param name="source">控件实例</param> /// <param name="DocumentType">导出类型:Excel或Word</param> /// <param name="filename">保存文件名</param> public void ExportControl(System.Web.UI.Control source, string DocumentType, string filename) { //设置Http的头信息,编码格式 if (DocumentType == "Excel") { //Excel HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+ HttpUtility.UrlEncode(filename+".xls",System.Text.Encoding.UTF8)); HttpContext.Current.Response.ContentType = "application/ms-excel"; } HttpContext.Current.Response.Charset = "UTF-8"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8; //关闭控件的视图状态 source.Page.EnableViewState =false; //初始化HtmlWriter System.IO.StringWriter writer = new System.IO.StringWriter() ; System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(writer); source.RenderControl(htmlWriter); //输出 HttpContext.Current.Response.Write(writer.ToString()); HttpContext.Current.Response.End(); } 出错的地方在:HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+ HttpUtility.UrlEncode(filename+".xls",System.Text.Encoding.UTF8)); HttpContext.Current.Response.ContentType = "application/ms-excel"; 如果文件名过长就会报错,如果改为filename="+ filename+".xls",System.Text.Encoding.UTF8),导出打开正常,但会乱码?
飛雪飄寒的主页 飛雪飄寒 | 初学一级 | 园豆:30
提问于:2008-12-15 15:31
< >
分享
最佳答案
0

看下面这个微软的说明,word 文档的最大路径长度为254字符,Excel为218,这就是为什么word可以,Excel不可以的原因。我觉得没有其他办法,只有通过缩短文件路径名来解决。

http://support.microsoft.com/kb/325573

his issue occurs because of a 256-character limitation on creating and saving files in the Office products. Also, you receive an error message when you save or open a file if the path of the file meets the following situations.

Microsoft Word: The total length of the path and the file name, including file name extension, exceeds 254 characters.

Microsoft PowerPoint: The total length of the path and the file name, including file name extension, exceeds 258 characters.

Microsoft Access: The total length of the path and the file name, including file name extension exceeds 258 characters.

Microsoft Outlook: The total length of the path and the file name, including file name extension, exceeds 258 characters.

Microsoft Excel: The total length of the path and the file name, including file name extension, exceeds 218 characters.

Note This limitation includes the three characters that represent the drive, the characters in folder names, the backslash character between folders, and the characters in the file name.

 

eaglet | 专家六级 |园豆:17119 | 2008-12-16 09:36
其他回答(2)
0

有可能是编码的问题,检查一下response.setHeader的设置与filename的URLEncoder.encode编码之后的情况。你可以把名字尽量缩短点试试看!另外

mimetype最好写清楚

Response.ContentType   =   "application/ms-excel";

GUO Xingwang | 园豆:3885 (老鸟四级) | 2008-12-15 15:47
0

路过,学习了....

Jared.Nie | 园豆:1940 (小虾三级) | 2008-12-15 23:18
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册