从C#错误打开Office 2010文档
我正在尝试通过为用户加载office文档从C#错误打开Office 2010文档,c#,file,mime-types,C#,File,Mime Types,我正在尝试通过为用户加载office文档 HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name); HttpContext.Current.Response.ContentType = MIMETypesDictionary[fileExt]; HttpContext.Current.Response.BinaryWrite(fileArray); 我
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
HttpContext.Current.Response.ContentType = MIMETypesDictionary[fileExt];
HttpContext.Current.Response.BinaryWrite(fileArray);
我的MIMETypesDictionary有这个(缩写)
文字错误
The file filename.docx cannot be opened because there are problems with the contents.
如果我单击Yes,它会加载,文档看起来也不错。当然,对于用户来说,这个错误不会出现。我是否为这些文件使用了正确的mime类型?我还尝试了application/vnd.ms-word.document.12、application/vnd.ms-excel.12和application/octet-stream,得到了相同的错误
谢谢 解决了!必须建立响应代码
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
HttpContext.Current.Response.ContentType = MIMETypesDictionary[fileExt];
HttpContext.Current.Response.BinaryWrite(fileArray);
HttpContext.Current.Response.End();
HttpContext.Current.Response.Flush();
我保留了文件类型的八位字节流值,效果非常好 您是否尝试过仅使用“应用程序/八位字节流”作为内容类型。我刚刚为流文件编写了一些东西,仅使用它就足以处理docx文件。
The file filename.docx cannot be opened because there are problems with the contents.
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
HttpContext.Current.Response.ContentType = MIMETypesDictionary[fileExt];
HttpContext.Current.Response.BinaryWrite(fileArray);
HttpContext.Current.Response.End();
HttpContext.Current.Response.Flush();