首页 > 解决方案 > 使用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.");
    }
  }
}

标签: javascripttemp

解决方案


推荐阅读