系统提示如下错误???当值<input id="IMAGINE" runat="server" type=file>为空时提示如下错误(如果正确选择图片就不会有错了).
我已经设置了条件if(magine.PostedFile!=null),但他为什么还要执行下面这个语句:
string fn=(updatefiles.Substring(updatefiles.LastIndexOf(".")).ToUpper());StartIndex 不能小于 0。参数名: startIndex 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.ArgumentOutOfRangeException: StartIndex 不能小于 0。参数名: startIndex源错误: 
行 171: {
行 172: string updatefiles=Path.GetFileName(magine.PostedFile.FileName);
行 173: string fn=(updatefiles.Substring(updatefiles.LastIndexOf(".")).ToUpper());
行 174: if(fn==".JPG"||fn==".JPEG"||fn==".GIF")
行 175: {
 源文件: c:\wk\webapplicationcsharp\new_mould.aspx.cs    行: 173 前台部分ASPX代码:<form id="Form1" method="post" runat="server" enctype="multipart/form-data">
.......................<asp:DataGrid id="DataGrid1" runat="server" CellPadding="4" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" BackColor="White" AutoGenerateColumns="False" OnUpdateCommand="DataGrid1_Update"OnCancelCommand="DataGrid1_Cancel" OnEditCommand="DataGrid1_Edit" DataKeyField="NO" OnDeleteCommand="DataGrid1_Delete">
........................
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="更新" HeaderText="编辑" CancelText="取消" EditText="编辑"
ItemStyle-Width="60" ItemStyle-HorizontalAlign="Center"></asp:EditCommandColumn>
<EditItemTemplate><input id="IMAGINE" runat="server" type=file></EditItemTemplate>
...................
</form>
后台部分CS代码:using System.IO;protected System.Web.UI.HtmlControls.HtmlInputFile IMAGINE; public void DataGrid1_Update(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
HtmlInputFile magine=(HtmlInputFile)e.Item.FindControl("IMAGINE");

if(magine.PostedFile!=null) {
string updatefiles=Path.GetFileName(magine.PostedFile.FileName);
string fn=(updatefiles.Substring(updatefiles.LastIndexOf(".")).ToUpper());
if(fn==".JPG"||fn==".JPEG"||fn==".GIF")
{

postfiles=DateTime.Now.ToString("yyyyMMddhhmmssfff")+fn;
magine.PostedFile.SaveAs(Server.MapPath("image")+"\\"  +postfiles);

}
else
{
Response.Write("<script>alert('对不起,您选择的不是图片,请重新选择')</script>");
return; } }
..........
.............................
}