0
在我的應用我允許用戶從網址上傳文件如何從URL上傳文件
代碼上傳文件網址:
function loadURL(box) {
var box = dhtmlx.modalbox({
title: "Load URL",
text: "<div id='form_in_box'><div>Enter the URL of PDF file <hr/><input type='text' name='files' id='files' style='width: 400px; height: 27px;'></label><br></div><div><span class='dhtmlx_button'><input type='submit' value='Load URL' style='width: 86px' onclick='load_file(this)'></span><span class='dhtmlx_button'><input type='button' value='Cancel' onclick='close_file(this)' style='width:80px;'></span></label></div></div>",
width: "300px"
})
}
function load_file(box) {
var file = document.getElementById('files');
if (file == "") {
alert("Enter File URL");
return false;
}
file = file.value;
var filename = file.substring(file.lastIndexOf('/') + 1);
dhtmlx.modalbox.hide(box);
$.post("/FileUpload/UploadURL",
{ file: '' + file + ''
});
}
控制器代碼
public ActionResult UploadURL(string file)
{
string files = Path.GetFileName(file);
string myStringWebResource = "";
WebClient myWebClient = new WebClient();
myStringWebResource = file;
string path = Server.MapPath(_fileUploadPath + files);
myWebClient.DownloadFile(myStringWebResource, path);
string extFile = Server.MapPath(_fileUploadPath + files);
return View();
}
文件已成功下載。現在我想上傳相同的文件我該怎麼做?
我照你說的做了。文件正在成功下載。現在我想上傳該文件並想以表格形式顯示它。我怎麼能這樣做? – pihu
修改後的代碼 public ActionResult UploadURL(字符串文件) { string files = Path.GetFileName(file); string myStringWebResource =「」; WebClient myWebClient = new WebClient(); myStringWebResource = file; string path = Server.MapPath(_fileUploadPath + files); myWebClient.DownloadFile(myStringWebResource,path); string extFile = Server.MapPath(_fileUploadPath + files); – pihu
@pihu請將此代碼添加到您的問題中,因爲很難從評論中讀取代碼。 –