0

I'm working in a function to download pdfs from DropBox, I'm using ASP.net Core , everything works good. The only thing is that when you click in the download link it doesn't show any message and downloads the file. I would like to show the download progress like usually happens when we download something from Internet, I don't want any dialog to appear, just to show that the file was downloaded like normally happens in any browser like Chrome or IE and then have the choices 'Show in Folder' and things like that, what would I need to add?

 public async Task DownloadPdf()
            {
                DropboxClient client2 = new DropboxClient("cU5M-a4exaAAAAAAAAABDVZsKdpPteNmwHslOeFEo-HByuOr4v4ONvXoAMCFyOXH");
                string folder = "MyFolder";
                string file = "Test PDF.pdf";
                using (var response = await client2.Files.DownloadAsync("/" + folder + "/" + file))
                {
                    using (var fileStream = System.IO.File.Create(@"C:\Users\User\Downloads\Test.pdf"))
                    {
                        (await response.GetContentAsStreamAsync()).CopyTo(fileStream);                    
                    }
                }
            }
AlexGH
  • 2,735
  • 5
  • 43
  • 76
  • 1
    See here http://stackoverflow.com/q/74019/5311735 (content-disposition header). – Evk Oct 06 '16 at 13:20
  • @Evk The only thing is that I'm using ASP.net Core and we can't find the namespace System.Wen in Core, how could I do this in Core? – AlexGH Oct 06 '16 at 13:29
  • I'm not familiar with asp.net core, but I think it's not hard to google about how to add header to response there (that's very basic operation). – Evk Oct 06 '16 at 13:31
  • have you tried importing system.web as a reference if its not there as standard/ – Simon Price Oct 06 '16 at 13:42
  • @SimonPrice I've tried but I'm getting this error: N`et core only support referencing .net framework assemblies in this release. to reference other assemblies, they need to be included in a NuGet package and reference that package` . I'm trying to figure it out – AlexGH Oct 06 '16 at 13:55

1 Answers1

2

I have a asp.net core project with an API that returns a file:

[HttpGet("{id}")]
public IActionResult Get(int id) {
  byte[] fileContent = READ_YOUR_FILE();
  FileContentResult result = new FileContentResult(fileContent, "application/octet-stream") {
    FileDownloadName = id.ToString()
  };
  return result;
}

If I access in my browser the URL from this API (myapp/api/mycontroller/id), then I can see the file downloading.

Fabricio Koch
  • 1,395
  • 12
  • 20