javascript - 使用Javascript-按钮的Onclickevent,需要下载一个exe文件,直接存放在系统的temp文件夹中
问题描述
当我单击一个按钮时,存储在根目录中的 .exe 文件应该直接下载到系统的 temp 文件夹中。我需要使用 JavaScript 来做到这一点。我尝试使用 c#,但我的要求是使用 JavaScript。你能帮我吗,因为我是 JavaScript 新手。
public void AutoClose() {
string filename = "AutoClosure.exe";
if (filename != "") {
string path = Server.MapPath(@ "~\AutoClose\AutoClosure.exe");
System.IO.FileInfo file = new System.IO.FileInfo(path);
if (file.Exists) {
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
Response.End();
} else {
Response.Write("This file does not exist.");
}
}
}
解决方案
推荐阅读
- vb.net - 验证从 VB.net 发送的 Outlook 电子邮件是否实际发送
- python - PyAutoGui - 单击特定位置后,它会单击未定义的位置
- android - 如何在 Kotlin 中创建一个简单的倒数计时器?
- c# - C# 如何向连接到我的服务器的所有客户端发送数据?
- reactjs - 如何通过属性删除reactjs中的元素?
- c++ - 不能在函数 C++ 中使用覆盖
- dart - Flutter - 如何更新 Sqflite 中的表结构?
- connection - Weave 无法解密 TCP 消息
- android - 从联系人列表中选择联系人并为该联系人选择特定的电子邮件
- mysql - str_to_date() 不适用于正确的语法