c# dynamically rename file upon download request

前端 未结 3 1348
独厮守ぢ
独厮守ぢ 2021-01-11 22:35

Is it possible to rename file when trying to download it? For example, I would like to store files to folders using their id\'s but when user downloads file I\'d like to ret

3条回答
  •  再見小時候
    2021-01-11 23:29

    nombre = nombre del archivo + extension (ejemplo.txt)

    public void DownloadFile(string ubicacion, string nombre)
    {
            Response.Clear();
            Response.ContentType = @"application\octet-stream";
            System.IO.FileInfo file = new System.IO.FileInfo(ubicacion);
            Response.AddHeader("Content-Disposition", "attachment; filename=" + nombre);
            Response.AddHeader("Content-Length", file.Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.WriteFile(file.FullName);
            Response.Flush();
    }
    

提交回复
热议问题