下面的代码用于将文件复制到目录中,但我继续得到异常“C:\ Program Files(x86)\ Common Files \ Microsoft Shared \ DevServer \ 10.0 \ abc.jpg”找不到文件错误。感谢您的任何帮助或想法。我在Windows 7机器上使用VS2010,jQuery 1.8.1(分钟),IIS 7。我的webconfig中有两个和元素都有FileUpload.ashx。
此问题仅在使用FireFox时发生。
HTML标记
var FileName = null;
$.ajax({ type: "POST",
url: "FileUpload.ashx",
data: { FileName: FileName },
async: true,
success: function (data) {
alert("Success");
}
},
error: function (data) {
alert("Error");
}
});
});
function setFileName(e) {
FileName = e.value;
}
FileUpload的代码隐藏
public void ProcessRequest(HttpContext context)
{
try
{
String FileID = Guid.NewGuid().ToString();
String sDirectory = "~/UploadedFiles/";
String sFileName = context.Request["FileName"];
String sUploadPath = String.Format("{0}/{1}", sDirectory, sFileName);
sUploadPath = context.Server.MapPath(sUploadPath);
string FileName = context.Request["FileName"];
FileInfo fn = new FileInfo(FileName);
fn.CopyTo(sUploadPath + FileID + "_" + fn.Name);
}
catch (Exception ex)
{
string message = ex.Message;
}
}