0
我在javascript中使用下面的代碼從網絡下載或上傳文件。如何使用javascript下載或上傳文件(客戶端腳本)
$(document).ready(function DirectoryCopy(sourceDirName, destDirName, copySubDirs, test) {
debugger;
try {
var dir = new System.IO.DirectoryInfo.ctor(sourceDirName);
var directory_stop = dir.get_Name();
var dirs = dir.GetDirectories();
if (!dir.get_Exists()) {
throw $CreateException(new System.IO.DirectoryNotFoundException.ctor$$String("Source directory does not exist or could not be found: " + sourceDirName), new Error());
}
if (!System.IO.Directory.Exists(destDirName)) {
System.IO.Directory.CreateDirectory$$String(destDirName);
}
if (test == true) {
System.IO.Directory.CreateDirectory$$String(destDirName + "\\" + "Complete");
}
var files = dir.GetFiles();
for (var $i2 = 0, $l2 = files.length, file = files[$i2]; $i2 < $l2; $i2++, file = files[$i2]) {
var temppath = System.IO.Path.Combine$$String$$String(destDirName, file.get_Name());
file.CopyTo$$String$$Boolean(temppath, true);
}
if (copySubDirs) {
for (var $i3 = 0, $l3 = dirs.length, subdir = dirs[$i3]; $i3 < $l3; $i3++, subdir = dirs[$i3]) {
var temppath = System.IO.Path.Combine$$String$$String(destDirName, subdir.get_Name());
DirectoryCopy(subdir.get_FullName(), temppath, copySubDirs, false);
}
return dirs.length;
}
return files.length;
}
catch (ex) {
var path = "d:\\tempnew\\MyTest.txt";
var sw = System.IO.File.CreateText(path);
try {
sw.WriteLine$$String(ex.toString());
}
finally {
sw.Dispose();
}
return 0;
}
});
但我對
var dir = new System.IO.DirectoryInfo.ctor(sourceDirName);
爲得到一個錯誤「系統未定義」
,如下圖所示,我從代碼傳遞值後面。
TextBox1.Text = @"\" + "\\10.66.3.82" + @"\" + "ipadqc" + @"\" + "IPAD Titles" + @"\" + JobName.Text + @"\" + Issue.Text;
string Macid = (string)(Session["Name"]);
string path = "D:" + @"\" + "Ipad Download" + @"\" + Macid + @"\" + Process.Text + @"\" + JobName.Text + @"\" + Issue.Text;
string a;
ClientScript.RegisterStartupScript(typeof(Page), "script", a = "DirectoryCopy('" + TextBox1.Text + "','"+path+"', true, true);", true);
請糾正我,如果我錯了或請讓我知道,如果有更好的選擇做到這一點。
你期望'System'來自哪裏?它應該是什麼? – 2014-09-25 05:57:00
@FelixKling我真的不知道,但我簡單地將C#代碼轉換爲Javascript。 – 2014-09-25 06:04:34
那麼,C#和JavaScript兩種完全不同的語言:) – 2014-09-25 14:18:45