索引超出范围。必须为非负值并小于集合大小。参数名: index ????????
上传图片按钮
private void Button1_Click(object sender, System.EventArgs e)
{
HttpFileCollection MyFileColl = HttpContext.Current.Request.Files;
HttpPostedFile MyPostedFile = MyFileColl[1]; // 提示此句出错
if (MyPostedFile.ContentType.ToString().ToLower().IndexOf("image") < 0)
{
Response.Write("无效的图形格式。");
return;
}
.............
索引超出范围。必须为非负值并小于集合大小。参数名: index
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。参数名: index
源错误:
行 194:
行 195: HttpFileCollection MyFileColl = HttpContext.Current.Request.Files;
行 196: HttpPostedFile MyPostedFile = MyFileColl[1];
行 197:
行 198: if (MyPostedFile.ContentType.ToString().ToLower().IndexOf("image") < 0)
源文件: c:\inetpub\wwwroot\sheji\shangchuan.aspx.cs 行: 196
堆栈跟踪:
[ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。
参数名: index]
System.Collections.ArrayList.get_Item(Int32 index) +91
System.Collections.Specialized.NameObjectCollectionBase.BaseGet(Int32 index) +10
System.Web.HttpFileCollection.Get(Int32 index)
System.Web.HttpFileCollection.get_Item(Int32 index)
sheji.shangchuan.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\sheji\shangchuan.aspx.cs:196
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()