使用iis发布的web解决思路
使用iis发布的web
上传excel文件时,iis报错提示参数超出范围,错误提示如下:
ArgumentOutOfRangeException
StartIndex 不能小于 0。参数名: startIndex 在 System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) 在 System.String.Substring(Int32 startIndex) 在 CurriculaVariable.Test.UpLoadExcel()
UpLoadExcel()代码如下:
private void UpLoadExcel()
{
string XLS_Path = "";
string XLS_Name = getfilename();
string fileExtName = "";
string fileName = fl.PostedFile.FileName.Substring(fl.PostedFile.FileName.LastIndexOf(".") - 9);
//将上传文件保存至web服务器
#region
if (fl.PostedFile.ContentLength > 0)
{
try
{
fileExtName = fl.PostedFile.FileName.Substring(fl.PostedFile.FileName.LastIndexOf("."));
if (fileExtName != ".xls" || fileExtName.Length < 1)
{
Response.Write("<script language=javascript>alert('数据导入失败.可能是文件格式或路径不正确!');</script>");
return;
}
fl.PostedFile.SaveAs(Server.MapPath("uploadexcel/") + XLS_Name + fileExtName);
XLS_Path = Server.MapPath("uploadexcel/") + XLS_Name + fileExtName;
}
catch (Exception ex)
{
Response.Write("<script language=javascript>alert('数据加载至web服务器端时产生异常(" + ex.Message + ")!');</script>");
}
}
else
{
Response.Write("<script language=javascript>alert('请选择文件后再上传!!!');</script>");
return;
}
#endregion
麻烦帮忙看看是是哪里的问题!非常感谢!
------解决思路----------------------
目测,你选择的FileName长度小于9的时候,报错。
上传excel文件时,iis报错提示参数超出范围,错误提示如下:
ArgumentOutOfRangeException
StartIndex 不能小于 0。参数名: startIndex 在 System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) 在 System.String.Substring(Int32 startIndex) 在 CurriculaVariable.Test.UpLoadExcel()
UpLoadExcel()代码如下:
private void UpLoadExcel()
{
string XLS_Path = "";
string XLS_Name = getfilename();
string fileExtName = "";
string fileName = fl.PostedFile.FileName.Substring(fl.PostedFile.FileName.LastIndexOf(".") - 9);
//将上传文件保存至web服务器
#region
if (fl.PostedFile.ContentLength > 0)
{
try
{
fileExtName = fl.PostedFile.FileName.Substring(fl.PostedFile.FileName.LastIndexOf("."));
if (fileExtName != ".xls" || fileExtName.Length < 1)
{
Response.Write("<script language=javascript>alert('数据导入失败.可能是文件格式或路径不正确!');</script>");
return;
}
fl.PostedFile.SaveAs(Server.MapPath("uploadexcel/") + XLS_Name + fileExtName);
XLS_Path = Server.MapPath("uploadexcel/") + XLS_Name + fileExtName;
}
catch (Exception ex)
{
Response.Write("<script language=javascript>alert('数据加载至web服务器端时产生异常(" + ex.Message + ")!');</script>");
}
}
else
{
Response.Write("<script language=javascript>alert('请选择文件后再上传!!!');</script>");
return;
}
#endregion
麻烦帮忙看看是是哪里的问题!非常感谢!
------解决思路----------------------
string fileName = fl.PostedFile.FileName.Substring(fl.PostedFile.FileName.LastIndexOf(".") - 9);
目测,你选择的FileName长度小于9的时候,报错。