I'm currently writing a simple controller method in my MVC WEB Api application which downloads file from a Dropbox account. The problem is I can't return the file from the method: it says "The name 'File' does not exist in the current context", but in the documentation this constructor can be called.
Code:
public async Task<FileResult> GetFile(string folder, string file)
{
using (var dbx = new DropboxClient("generated token key"))
{
using (var response = await dbx.Files.DownloadAsync(folder + "/" + file))
{
var result = await response.GetContentAsStringAsync();
return File(result, file);
}
}
}
Complete DropBoxController.cs
class:
using Dropbox.Api;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Mvc;
namespace TestDropBox.Controllers
{
public class DropBoxController : ApiController
{
// GET: api/DropBox
public async Task<IEnumerable<string>> Get()
{
List<string> AccountData= new List<string>();
using (var dbx = new DropboxClient("generated token"))
{
var full = await dbx.Users.GetCurrentAccountAsync();
Console.WriteLine("{0} - {1}", full.Name.DisplayName, full.Email);
AccountData.Add(full.Name.DisplayName);
AccountData.Add(full.Email);
}
return DatiAccount;
}
[System.Web.Http.HttpGet]
public async Task<FileResult> GetFile(string folder, string file)
{
using (var dbx = new DropboxClient("generated token"))
{
using (var response = await dbx.Files.DownloadAsync(folder + "/" + file))
{
var result = await response.GetContentAsStringAsync();
return new File(result, file);
}
}
}
// GET: api/DropBox/5
public string Get(int id)
{
return "value";
}
// POST: api/DropBox
public void Post([FromBody]string value)
{
}
// PUT: api/DropBox/5
public void Put(int id, [FromBody]string value)
{
}
// DELETE: api/DropBox/5
public void Delete(int id)
{
}
}
}
How could I fix this problem? Thank you.