JS中实现重命名并下载文件

JS中实现重命名并下载文件,第1张

js干不了这个事。可以由服务端来做这件事

Response.AddHeader("Content-Disposition", "attachmentfilename=\"" +filename+ "\"")

download.aspx

string fileName = ""//客户端保存的文件名

string filePath = Server.MapPath("")//路径

FileInfo fileInfo = new FileInfo(filePath)

Response.Clear()

Response.ClearContent()

Response.ClearHeaders()

Response.AddHeader("Content-Disposition", "attachmentfilename=" + fileName)

Response.AddHeader("Content-Length", fileInfo.Length.ToString())

Response.AddHeader("Content-Transfer-Encoding", "binary")

Response.ContentType = "application/octet-stream"

Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312")

Response.WriteFile(fileInfo.FullName)

Response.Flush()

Response.End()


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/12097020.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存