我在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);
as &#34;系统未定义&#34;
我从代码后面传递值,如下所示。
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);
如果我错了,请纠正我,或者如果有更好的选择,请告诉我。
答案 0 :(得分:0)
System.IO是一个.Net的东西,而不是一个javascript的东西。
对于使用JS下载文件,Stack Overlow上有很多或类似的问题。 like this one
就上传而言,this question的最佳答案几乎总结了它。