c#根据下载请求动态重命名文件

尝试下载文件时是否可以重命名文件? 例如,我想使用他们的id将文件存储到文件夹,但是当用户下载文件时,我想返回原始文件名。

只需在这里更改文件名

Response.AppendHeader("Content-Disposition","attachment; filename=LeftCorner.jpg"); 

例如

  string filename = "orignal file name.ext"; Response.AppendHeader("Content-Disposition","attachment; filename="+ filename +""); 

在ASP.NET中使用“另存为”对话框下载文件

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(); }