Index was outside the bounds of the array

Posted by: aubyone on 8 September 2017, 8:29 am EST

  • Posted 8 September 2017, 8:29 am EST

    I am tying to save to excel this works for same data but the largest Page of data I have will not save the sheet is 10 * 200 .



    this the error I am getting.







    Index was outside the bounds of the array







    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.







    Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.







    Source Error:











    Line 211: {



    Line 212: string File = XLSPath + “FileData.xls”;



    Line 213: FpSpread1.SaveExcel(File);







    [IndexOutOfRangeException: Index was outside the bounds of the array.]



    c.a(String A_0, Stream A_1, IncludeHeaders A_2, ExcelWarningList A_3)



    c.d(String A_0)



    FarPoint.Web.Spread.FpSpread.SaveExcel(String fileName)



    MarkBook.MarkBook.SaveMarkBook() in c:\inetpub\wwwroot\pcschool\markbook\markbook.aspx.cs:213



    MarkBook.MarkBook.FpSpread1_ManageBtn_Command(Object sender, SpreadCommandEventArgs e) in c:\inetpub\wwwroot\pcschool\markbook\markbook.aspx.cs:187



    FarPoint.Web.Spread.FpSpread.OnButtonCmd(String cmd, Int32 row, Int32 column)



    FarPoint.Web.Spread.FpSpread.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String id)



    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)



    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)



    System.Web.UI.Page.ProcessRequestMain()















    Any ideas what it could be?

  • Posted 8 September 2017, 8:29 am EST

    Sorry this should be in import/export!







    Found what the prooblem is. The radio button will not save across to excel. How do do I fix this so it saves

  • Posted 8 September 2017, 8:29 am EST

    Hello,







    First of all, make sure you are using the latest maintenance release of Spread for Web Forms (version 1.0.5.0). We are constantly making changes to the excel import/export code to improve it. If there is still a problem, could you email us at fpsupport@fpoint.com you spread file (using the Save method to export it to a file) for us to debug?

  • Posted 8 September 2017, 8:29 am EST

    Hello,







    The Radiobutton celltype will not get exported to Excel. The value stored in the cell containing the RadioButtonListCellType should be exported.

  • Posted 8 September 2017, 8:29 am EST

    Scott,







    Download last update still will not same with radio buttons, take the radio cell format off and it saves fine.







    Have e-mailed a small project that has the error.

  • Posted 8 September 2017, 8:29 am EST

    Hello,







    I was able to reproduce this problem and have reported this as a bug (14582). The problem is in the call we are making to do a BinarySearch for the value in the cell in the arraylist of values for the celltype. It is not returning to us the expected value all the time. The development team is searching for a fix for this bug. For now, you can change your DataSet to use numbers (0,1,2,etc) to choose the correct radio button and then not set up a Values array for the celltype. This problem should be fixed in the next maintenance release.

  • Posted 8 September 2017, 8:29 am EST

    I have downloaded the latest release the problem does not seem to be fixed?

  • Posted 8 September 2017, 8:29 am EST

    Hello,







    With the 1.0.6.0 version of Spread for Web Forms, this problem should be fixed. I used the test project you sent me and with the 1.0.5.0 version of the Spread for Web Forms, I was able to reproduce the same problem you are seeing, but once I changed the project to use the 1.0.6.0 version, the Excel file exported correctly. What problems are you seeing when using the latest maintenance release?

  • Posted 8 September 2017, 8:29 am EST

    Hi Scott,







    I made no changes to my code I just waited for the new release to come out this is the error I got







    Specified cast is not valid.



    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.







    Exception Details: System.InvalidCastException: Specified cast is not valid.







    Source Error:







    Line 1259: {



    Line 1260: string File = Server.MapPath(“.”) + “/FileData.xls”;



    Line 1261: FpSpread1.SaveExcel(File, FarPoint.Web.Spread.Model.IncludeHeaders.None);



    Line 1262:



    Line 1263: Response.ContentType=“application/ms-excel”;







    [InvalidCastException: Specified cast is not valid.]



    c.a(String A_0, Stream A_1, IncludeHeaders A_2, ExcelWarningList A_3)



    c.a(String A_0, IncludeHeaders A_1, ExcelWarningList A_2)



    FarPoint.Web.Spread.FpSpread.SaveExcel(String fileName, IncludeHeaders includeHeaders, ExcelWarningList warningList)



    FarPoint.Web.Spread.FpSpread.SaveExcel(String fileName, IncludeHeaders includeHeaders)



    WebPCSchool.MarkBook.SaveMarkBook() in c:\inetpub\wwwroot\webpcschool\markbook.aspx.cs:1261



    WebPCSchool.MarkBook.FpSpread1_ManageBtn_Command(Object sender, SpreadCommandEventArgs e) in c:\inetpub\wwwroot\webpcschool\markbook.aspx.cs:1235



    FarPoint.Web.Spread.FpSpread.OnButtonCmd(String cmd, Int32 row, Int32 column)



    FarPoint.Web.Spread.FpSpread.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String id)



    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)



    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)



    System.Web.UI.Page.ProcessRequestMain() +1277











    This only does this when they are combo or radio etc when straight data it works fine







    Aubery

  • Posted 8 September 2017, 8:29 am EST

    The last was for the radio







    this was with the Combo box







    Index was outside the bounds of the array.



    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.







    Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.







    Source Error:







    Line 1259: {



    Line 1260: string File = Server.MapPath(“.”) + “/FileData.xls”;



    Line 1261: FpSpread1.SaveExcel(File);



    Line 1262:



    Line 1263: Response.ContentType=“application/ms-excel”;











    IndexOutOfRangeException: Index was outside the bounds of the array.]



    c.a(String A_0, Stream A_1, IncludeHeaders A_2, ExcelWarningList A_3)



    c.d(String A_0)



    FarPoint.Web.Spread.FpSpread.SaveExcel(String fileName)



    WebPCSchool.MarkBook.SaveMarkBook() in c:\inetpub\wwwroot\webpcschool\markbook.aspx.cs:1261



    WebPCSchool.MarkBook.FpSpread1_ManageBtn_Command(Object sender, SpreadCommandEventArgs e) in c:\inetpub\wwwroot\webpcschool\markbook.aspx.cs:1235



    FarPoint.Web.Spread.FpSpread.OnButtonCmd(String cmd, Int32 row, Int32 column)



    FarPoint.Web.Spread.FpSpread.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String id)



    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)



    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)



    System.Web.UI.Page.ProcessRequestMain() +1277

  • Posted 8 September 2017, 8:29 am EST

    Hello,







    Could you resend the small project you are using to reproduce this problem, so I can debug the problem you are seeing?

  • Posted 8 September 2017, 8:29 am EST

    will do so may take a couple days sa there a other important thing I must do

  • Posted 11 January 2022, 4:02 pm EST

    This exception means that you’re trying to access a collection item by index, using an invalid index. An index is invalid when it’s lower than the collection’s lower bound or greater than or equal to the number of elements it contains. Indexing an empty list will always throw an exception. Use a method like Add to append the item to the end of the list, or Insert to place the item in the middle of the list somewhere, etc. You cannot index into a c# list if that offset doesn’t exist. IndexOutOfRangeException exception is thrown as a result of developer error. Instead of handling the exception, you should diagnose the cause of the error and correct your code.

    Handling the Exception:

    Use for-each loop: This automatically handles indices while accessing the elements of an array.

    Use Try-Catch: Consider enclosing your code inside a try-catch statement and manipulate the exception accordingly. As mentioned, C# won’t let you access an invalid index and will definitely throw an IndexOutOfRangeException. However, we should be careful inside the block of the catch statement, because if we don’t handle the exception appropriately, we may conceal it and thus, create a bug in your application.

    http://csharp.net-informations.com/collection/list.htm

  • Posted 13 January 2022, 3:00 am EST

    Hi,

    Thank you for your response and suggestion on this.

    Regards,

    Manish Gupta

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels