$.ajax({
url: "/ProjBaseManage/CostBudgetInfo/downloadFile",
data: { filePath: filePath, fileName: fileName },
type: "post",
dataType: "json",
success: function (data) {
var res = data;
location.href = res.substring(1);
},
});
}
[HttpPost]
public ActionResult downloadFile(string filePath, string fileName)
{
string pathGuid = Guid.NewGuid().ToString();
string virtualPath1 = filePath;
string virtualPath2 = string.Format("~/Resource/TempFile/CostBudgetInfo/{0}/{1}", pathGuid, fileName);
string fullFileName1 = this.Server.MapPath(virtualPath1);
string fullFileName2 = this.Server.MapPath(virtualPath2);
string path = Path.GetDirectoryName(fullFileName2);
Directory.CreateDirectory(path);
if (System.IO.File.Exists(fullFileName1))
{
System.IO.File.Copy(fullFileName1, fullFileName2, true);
}
string data = virtualPath2;
return ToJsonResult(data);
}