Downloaded file from folder includes %2F char on .NET Core


  • This must be a dumb question. I have a web API Rest on c# that have an endpoint to generate and download an excel file. I use NPOI library.

    It works fine if the file is generated within the root of my site. But when I try to move my file to a folder, file name include folder and de %2F char. I suppose this is an URL encode problem, but don't know how to fix it. This is my code.

        public async Task<IActionResult> ExportExcel(int activos = 1, int idarticulo = -1, string filtro = "", string ordenar = "", int ordenarsentido = 1)
            var memory = new MemoryStream();
            var newFile = @"Export/Articulos.xlsx";
            //IArticulosService articulosService = new ArticulosService(_validation.sConnectionString, _validation.sEmpresa);
            var mycon = _validation.GetConnectionStringFromClientID("ClientId1");
            IArticulosService articulosService = new ArticulosService(mycon, "Ciatema");
                // Genero el excel con el listado
                articulosService.ExportarExcel(newFile, activos, filtro, ordenar, ordenarsentido);
                using (var stream = new FileStream(newFile, FileMode.Open))
                    await stream.CopyToAsync(memory);
                memory.Position = 0;
                return File(memory, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", newFile);
            catch (QueryFormatException ex)
                return BadRequest(ex.Message);
            catch (Exception ex)
                return StatusCode(StatusCodes.Status500InternalServerError);

    Donwload filename is: Export%2FArticulos.xlsx when i need it to be only Articulos.xlsx. Thanks!

    • Dipindahkan oleh CoolDadTxMVP 30 April 2018 13:43 ASP.NET related
    29 April 2018 15:24

Semua Balasan