Index was outside the bounds of the array exception in CSVLibraryAK.CSVLibraryAK.Import().

 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Index was outside the bounds of the array exception in CSVLibraryAK.CSVLibraryAK.Import().

tjfan001
Test01.csv

The attached file can be loaded into Excel without any problems, but produces an "Index was outside the bounds of the array" exception in CSVLibraryAK.CSVLibraryAK.Import() function.

I'd like to know the cause of the exception and how to resolve it.

Also, if possible, I'd like to see Import() returns more meaningful information such as which line and/or which characters contribute to the error.

Reply | Threaded
Open this post in threaded view
|

Re: Index was outside the bounds of the array exception in CSVLibraryAK.CSVLibraryAK.Import().

asmak9
Administrator
Dear TJFan01,

Thank you for reporting this issue. The support for columns with comma inside quotes was not added in the library previous. Now, the support for columns with comma inside quotes is added in the latest release of CSVLibraryAK v1.1.1. Kindly, update library to the latest version. Also, in the provided attach file your CSV header has columns in separate lines, so, fix that in the CSV file via notepad as header columns needs to be in a single line. Find attach your file with header columns fix i.e. Test01.csv
Thanks & Regards.
Asma's Blog

Like, Share, Support, Subscribe!!!
YouTube Subscribe: https://bit.ly/2sY1aBb

Website: https://www.asmak9.com/
E-Store Bytezaar: https://www.bytezaar.com/
Facebook: https://www.facebook.com/AK.asmak9/
LinkedIn: https://www.linkedin.com/company/asmak9
Twitter: https://twitter.com/asmak/
Reply | Threaded
Open this post in threaded view
|

Re: Index was outside the bounds of the array exception in CSVLibraryAK.CSVLibraryAK.Import().

tjfan001
Thank you for the update.

Just want to remind that this file (column header with carriage returns) was read fine by Excel. Maybe (hopefully) in your future version, you can accommodate this as well?
Reply | Threaded
Open this post in threaded view
|

Re: Index was outside the bounds of the array exception in CSVLibraryAK.CSVLibraryAK.Import().

asmak9
Administrator
Here is a thing when you open CSV in excel by double clicking the file then excel open the file not in standard CSV format but in one of excel's own default data format, similarly, when you try to save the file as CSV format then you will see warning message about formatting and UTF character files will convert into question marks that way. If you try to open your original file from this thread into SQL server or even in excel as CSV you will notice the issue in the header of the CSV file i.e. on separate rows which will happen in any tool that follow the CSV file standards, same thing is happening with my library as it is following the CSV standards. Original CSV file that you provide Test01.csv will show as follow in excel if you open it as CSV i.e.


File Test02.csv that contains correct header in the CSV and open in excel as CSV will show header correctly i.e.


I hope I am able to clarify few things here. Enjoy!!!
Thanks & Regards.
Asma's Blog

Like, Share, Support, Subscribe!!!
YouTube Subscribe: https://bit.ly/2sY1aBb

Website: https://www.asmak9.com/
E-Store Bytezaar: https://www.bytezaar.com/
Facebook: https://www.facebook.com/AK.asmak9/
LinkedIn: https://www.linkedin.com/company/asmak9
Twitter: https://twitter.com/asmak/
Reply | Threaded
Open this post in threaded view
|

Re: Index was outside the bounds of the array exception in CSVLibraryAK.CSVLibraryAK.Import().

tjfan001
Not sure what you meant by "opening Excel as CSV".

The only option (I tried both Office 365 and Microsoft Office Professional 2013) I have is to open it as a text file.



and it shows up as normal (no breaks in header).

Maybe you are using a different versions of Excel?

My point is that, hopefully , future build of CSVLibraryAK can accommodate these unwanted carriage returns (e.g., removing them) as Excel does.
Reply | Threaded
Open this post in threaded view
|

Re: Index was outside the bounds of the array exception in CSVLibraryAK.CSVLibraryAK.Import().

asmak9
Administrator
New update is available for CSVLibraryAK library. Support has been added for unwanted carriage returns i.e columns on multiple lines. Now your provided test file will be loaded without any issue.
Thanks & Regards.
Asma's Blog

Like, Share, Support, Subscribe!!!
YouTube Subscribe: https://bit.ly/2sY1aBb

Website: https://www.asmak9.com/
E-Store Bytezaar: https://www.bytezaar.com/
Facebook: https://www.facebook.com/AK.asmak9/
LinkedIn: https://www.linkedin.com/company/asmak9
Twitter: https://twitter.com/asmak/
Reply | Threaded
Open this post in threaded view
|

Re: Index was outside the bounds of the array exception in CSVLibraryAK.CSVLibraryAK.Import().

tjfan001
Thank you so much!