【发布时间】:2014-09-04 19:02:32
【问题描述】:
我想直接从 dropbox 下载文件。我能够检索我想直接从 dropbox 下载的文件的内容。我无法通过流将文件发送到浏览器。 以下异常: mscorlib.dll 中出现“System.UnauthorizedAccessException”类型的异常,但未在用户代码中处理
附加信息:对路径“C:\Program Files (x86)\IIS Express\FirstLab_1.pdf”的访问被拒绝。 在线 使用 (FileStream fileStream = new FileStream(filename, FileMode.Create))
以下是我的代码:
public FileStreamResult Download(string bkpath)
{
string bookname = bkpath;
var accessToken = new OAuthToken("d2iwy26brzqhetr0", "xxxxxxxxxxxx");
var api = new DropboxApi(ConsumerKey, ConsumerSecret, accessToken);
var file = api.DownloadFile("dropbox", bookname);
string path = file.Path;
string filename = Path.GetFileName(path);
// Create random data to write to the file.
byte[] dataArray = new byte[file.Data.Length];
new Random().NextBytes(dataArray);
using (FileStream fileStream = new FileStream(filename, FileMode.Create))
{
// Write the data to the file, byte by byte.
for (int i = 0; i < dataArray.Length; i++)
{
fileStream.WriteByte(dataArray[i]);
}
// Set the stream position to the beginning of the file.
fileStream.Seek(0, SeekOrigin.Begin);
// Read and verify the data.
for (int i = 0; i < fileStream.Length; i++)
{
if (dataArray[i] != fileStream.ReadByte())
{
Response.Write("Error writing data.");
}
}
return new FileStreamResult(fileStream, "application/pdf");
}
}
请帮助我直接从保管箱下载文件,因为我正在解决这个异常大约很长时间并且无法获得解决方案。
【问题讨论】:
标签: asp.net-mvc file dropbox-api access-token filestreamresult