在运行以下代码时获取损坏的文件以下载文件。有人可以建议我纠正它吗? [英] Getting corrupt file on running the below code to download files. Can someone suggest me to rectify it?

查看:105
本文介绍了在运行以下代码时获取损坏的文件以下载文件。有人可以建议我纠正它吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

internal static HttpResponseMessage DownloadFile1(string blobName, string fileName)
{
   HttpResponseMessage response = new HttpResponseMessage();
   string path = @"D:\Project\Newfolder\";
   string filePath = Path.Combine(path + fileName);
   MemoryStream responseStream = new MemoryStream();
   byte[] info = new UTF8Encoding(true).GetBytes(blobName);
   File.SetAttributes(path, FileAttributes.Normal);
   Stream fileStream = System.IO.File.OpenWrite(filePath);
   responseStream.Position = 0;
   fileStream.Write(info, 0, info.Length);
   response.Content = new StreamContent(responseStream);
   string contentDisposition = string.Concat("attachment; filename=", fileName);
   response.Content.Headers.ContentDisposition =
   ContentDispositionHeaderValue.Parse(contentDisposition);
   fileStream.Flush();
   return response;
}





我的尝试:



我尝试重构这段代码,但是当我尝试使用SSMS恢复它时收到错误信息文件已损坏。



What I have tried:

I tried restructuring this code but getting the error message that the file is corrupted when i tried to restore it using SSMS.

推荐答案

第一件事检查是:在下载代码涉及之前文件是否已损坏?



首先使用浏览器下载它,看看你得到了什么。它有用吗?如果没有 - 有你的问题。

如果是,请将你的代码下载的文件与原始,已知的好版本进行比较。它们的大小相同吗?十六进制编辑器说的是什么?文件比较实用程序怎么样?



我们无法修复代码而没有数据来运行它 - 所以你需要开始积累数据以找出它是如何失败的 - 没有你,你只是猜测问题是什么!
The first thing to check is: is the file already corrupted before your download code gets involved?

Start by downloading it with a browser and see what you get. Does it work? If not - there is your problem.
If it does, then compare the file your code downloaded to the "original", known good version. Are they the same size? What does a hex editor say is in them? How about a file compare utility?

We can't fix code without data to run it against - so you need to start accumulating data to find out how it's failing - without that you are just guessing what the problem is!


这篇关于在运行以下代码时获取损坏的文件以下载文件。有人可以建议我纠正它吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆