Home > Mobile >  Openning a file in a new tab instead of downloading
Openning a file in a new tab instead of downloading

Time:09-06

I am trying to open the attachement in a new tab but its prompting to be saved. Can someone help me to open the file in a new tab instead of downloading it please?

Controller:

public async Task<IActionResult> Download(string filename)
{
    if (String.IsNullOrEmpty(filename))
    {
        return Content("Le nom de fichier n'existe pas");
    }
    
    var path = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "UploadFds"));
    var combine = Path.Combine(path, filename);
    var memory = new MemoryStream();
    using (var stream = new FileStream(combine, FileMode.Open))
    {
        await stream.CopyToAsync(memory);
    }
    memory.Position = 0;
    return File(memory, GetContentType(combine), Path.GetFileName(combine));
}

view.cshtml:

<div >
    <div style="text-align:right">
        <label >Accés au FDS :</label>
        <a asp-action="Download" target="_blank" 
           asp-route-filename="@Model.Fds_Filepath">
            @Model.Fds_Filepath
        </a>
    </div>
</div>

CodePudding user response:

I've found it by myself. I've removed "Path.GetFileName(combine)" and it works for me.

  • Related