我有一个数据库表(tbl_document),其中包含随时间上传到其中的文件的详细信息。
我想编写一个控制台应用程序来将这些文件下载到给定位置。
该表包含三个信息,我应该使用它们:
格式的文件varbinary
内容;每个文件的MIME 类型( contentType ),采用 nvarchar 格式,例如:
application/x-zip-compressed application/msword application/vnd.openxmlformats-officedocument.wordprocessingml.document application/pdf application/pdf
在 MVC 中,我会做这样的事情来执行这个任务:
public FileContentResult DownloadFile()
{
FileContentResult result = new FileContentResult(file.FileContents, file.ContentType);
result.FileDownloadName = file.FileName;
return result;
}
我尝试了其他方法来做到这一点,例如:
WebClient myWebClient = new WebClient();
FileContentResult result = new FileContentResult(fileContents, contentType);
我无法使用上述任何方法来保存文件。请你帮忙。
非常感谢。