运行孟子E章(http://dotnet.aspx.cc/ShowDetail.aspx?id=45E7E33C-F149-450E-B5D5-832958C20538
)提供的c#版本代码,以下是部分代码:========================================================private void Button1_Click(object sender, System.EventArgs e)
{
HttpFileCollection MyFileColl = HttpContext.Current.Request.Files;
HttpPostedFile MyPostedFile = MyFileColl[0];
if (MyPostedFile.ContentType.ToString().ToLower().IndexOf("image") < 0)
{
Response.Write("无效的图形格式。");
return;
}
GetThumbNail(MyPostedFile.FileName,100,100,MyPostedFile.ContentType.ToString(),false,MyPostedFile.InputStream); }========================================================
以下是错误提示内容
“/create_file1”应用程序中的服务器错误。
--------------------------------------------------------------------索引超出范围。必须为非负值并小于集合大小。
参数名: index
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。
参数名: index源错误:
行 94: {
行 95: HttpFileCollection MyFileColl = HttpContext.Current.Request.Files;
行 96: HttpPostedFile MyPostedFile = MyFileColl[0];
行 97: if (MyPostedFile.ContentType.ToString().ToLower().IndexOf("image") < 0)
行 98: {
源文件: c:\inetpub\wwwroot\create_file1\webform1.aspx.cs 行: 96 堆栈跟踪:
[ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。
参数名: index]
System.Collections.ArrayList.get_Item(Int32 index) +2776397
System.Collections.Specialized.NameObjectCollectionBase.BaseGet(Int32 index) +9
System.Web.HttpFileCollection.Get(Int32 index) +5
System.Web.HttpFileCollection.get_Item(Int32 index) +4
create_file1.WebForm1.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\create_file1\webform1.aspx.cs:96
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
===========================================================
提示索引超出范围,必须为非负值并小于集合大小,baidu,goole了一下也没找出想要的答案,哪位遇到过类似的问题,请帮忙指点,谢谢!
)提供的c#版本代码,以下是部分代码:========================================================private void Button1_Click(object sender, System.EventArgs e)
{
HttpFileCollection MyFileColl = HttpContext.Current.Request.Files;
HttpPostedFile MyPostedFile = MyFileColl[0];
if (MyPostedFile.ContentType.ToString().ToLower().IndexOf("image") < 0)
{
Response.Write("无效的图形格式。");
return;
}
GetThumbNail(MyPostedFile.FileName,100,100,MyPostedFile.ContentType.ToString(),false,MyPostedFile.InputStream); }========================================================
以下是错误提示内容
“/create_file1”应用程序中的服务器错误。
--------------------------------------------------------------------索引超出范围。必须为非负值并小于集合大小。
参数名: index
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。
参数名: index源错误:
行 94: {
行 95: HttpFileCollection MyFileColl = HttpContext.Current.Request.Files;
行 96: HttpPostedFile MyPostedFile = MyFileColl[0];
行 97: if (MyPostedFile.ContentType.ToString().ToLower().IndexOf("image") < 0)
行 98: {
源文件: c:\inetpub\wwwroot\create_file1\webform1.aspx.cs 行: 96 堆栈跟踪:
[ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。
参数名: index]
System.Collections.ArrayList.get_Item(Int32 index) +2776397
System.Collections.Specialized.NameObjectCollectionBase.BaseGet(Int32 index) +9
System.Web.HttpFileCollection.Get(Int32 index) +5
System.Web.HttpFileCollection.get_Item(Int32 index) +4
create_file1.WebForm1.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\create_file1\webform1.aspx.cs:96
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
===========================================================
提示索引超出范围,必须为非负值并小于集合大小,baidu,goole了一下也没找出想要的答案,哪位遇到过类似的问题,请帮忙指点,谢谢!
解决方案 »
- 读出大量数据,只需要从中均匀取出50个,求SQL语句
- ghost xp sp2 能不能用iis 我安装后怎么不能运行
- 求一个随机取固定比率数据的SQL语句的写法
- 将SqlDataReader类型的数据,绑定到控件 DropDownLis?
- 开发群,欢迎加入!!!!!!!!!!!!!
- 打开Excel工作表出错:-2147024891
- 正则:"\\.(?<extension>\\w+)"是什么意思?
- 如何取出变量bbb的值
- 为什么这个IF语句不听话阿?
- ASP.NET如何操作当前客户机(Client)的串口?
- 现在如何能看到自己有多少分?
- 100分急求《ASP.NET办公自动化系统开发实例导航(C#)》源代码
这里面没有东西,
执行这个HttpPostedFile MyPostedFile = MyFileColl[0];之前:
if(MyFileColl.Count>0)
{.......}
HttpPostedFile MyPostedFile = MyFileColl[0];
---------------------------------------------
当MyFileColl对象为空或元素为0时,访问MyFileColl[0]就会报这样的错.
文件上传框 有没有Name属性呢???
对比孟子的代码后发现少了这段代码就不能把图片保存了,请问如何转换为c#格式的语法?