word文档服务器多人打开后就损坏,打开word文档损坏

我正在尝试将Word文档(在ASP .NET服务器和Microsoft.Office.Interop.Word中生成)发送到客户端,但每次我尝试在客户端使用IE9打开时,它都说它可以'打开它,因为它已损坏,但如果我尝试保存并打开它,它工作正常。那问题出在哪里?

以下是代码:

string nombreDoc = @"C:\tempDocs\Test.doc";

generateIndex(nombreDoc); //this is an internal operation using Interop.Word

FileStream sourceFile = new FileStream(nombreDoc, FileMode.Open);

float FileSize;

FileSize = sourceFile.Length;

byte[] getContent = new byte[(int)FileSize];

sourceFile.Read(getContent, 0, (int)sourceFile.Length);

sourceFile.Close();

HttpContext.Current.Response.ClearContent();

HttpContext.Current.Response.ClearHeaders();

HttpContext.Current.Response.Clear();

HttpContext.Current.Response.Cache.SetNoServerCaching();

HttpContext.Current.Response.Buffer = true;

HttpContext.Current.Response.ContentType = "application/vnd.ms-word.document";

HttpContext.Current.Response.AddHeader("Content-Length", getContent.Length.ToString());

HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=Test.doc");

HttpContext.Current.Response.BinaryWrite(getContent);

HttpContext.Current.Response.Flush();

HttpContext.Current.Response.End();

File.Delete(nombreDoc);

我尝试使用WriteFile而不是BynaryWrite,问题仍然存在。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值