文件上传
在上传控件的onchange事件中用一个textbox记录下上传的路径:
function SelectValue(obj){
if (obj)
{
if (window.navigator.userAgent.indexOf("MSIE") >= 1)
{
obj.select();
document.getElementById("txtUp").value=document.selection.createRange().text;
}
else
{
document.getElementById("txtUp").value=obj.value;
}
}
}
在以下函数中,出现“找不到D:xx.xls文件”,路径中的"\"怎么不见了?我点击浏览后,textbox中显示的路径是对的,
为什么导入的时候出这个错?而且系统发布后,在我们公司的局域网中是没问题的,怎么一到客户那去就出现这个问题?
public string LoadFile2(Page Mpage, string filePath)//filePath为textbox值
{
string fileExtName = "", mFileName = "", mPath = "", res = "";
try
{
if (filePath != "")
{
fileExtName = filePath.Substring(filePath.LastIndexOf("."));
if (fileExtName.ToLower() == ".xls")
{
mPath = Mpage.Server.MapPath("..\\ExcelFile\\");//取得与 Web 服务器上的指定虚拟路径相对应的物理文件路径。
mFileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";//设置上传文件名
File.Copy(filePath, mPath + mFileName, false);
res = mPath + mFileName;
}
else
{
Mpage.ClientScript.RegisterStartupScript(typeof(string), "", "<script>alert('只能导入Excel文件!')</script>");
}
}
else
{
Mpage.ClientScript.RegisterStartupScript(typeof(string), "", "<script>alert('请选择需导入的文件!')</script>");
}
}
catch (Exception ex)
{
Mpage.ClientScript.RegisterStartupScript(typeof(string), "", "<script>alert('"+ex.Message+"')</script>");
}
return res;
}