Loading CSV fileds(Excel) into sharepoint List

Hi ,

i had loaded the CSV Field data into list but i have one problem while importing the data.

Text fields in the csv file could run over more than one line

In the future the program should not split each line of the csv file into field data.

It should take care that cs v text fields could run over more than one line.

Thanks 










November 7th, 2013 5:41am

Hi Sunitha,

are you doing with code or manually export / import excel ?

I would suggest first open your csv in ms excle, see if it opens correctly ( If its comma issue, columns in some rows will vary), try to replace comma in text fields with some other char e.g. semicolon(;) then replace \r\n with <br /> then see if it opens correctly in ms excel...

In any case (code or manual) if it opens correctly in excel it should not have problem in importing.

Then again you can iterate a loop to replace semicolon(;) with comma (,) once imported successfully. OR edit in excel and find and replace characters if manually.

Free Windows Admin Tool Kit Click here and download it now
November 7th, 2013 6:00am

Hi Niren ,

am using the C# Code to reading the CSv , Yes you answer is suits 100 % to me 

have confusion where i need o keep this <br/> in my loop, can you please sugeest me .


                    {
                        var line = csvreader.ReadLine();
                        var values = new string[0];
                        //// the first line contains the field names
                        if (bFirstLine)
                        {
                            bFirstLine = false;
                            //// check if the csv divider = ','.
                            //// if not than it should be ';'
                            if (!line.Contains(cCSVDivider))
                            {
                                cCSVDivider = ';';
                                cResetChar = ',';
                            }
                            //if(line.IndexOfAny(
                            values = line.Split(cCSVDivider);
                            for (int i = 0; i < values.Length; i++)
                            {
                                sFieldNames[i] = values[i];
                            }
                        }
                        else
                        {

                            //// If the line contains '"' then the field contains a ',' in the value
                            if (line.Contains('"'))
                            {
                                line = lineCorrection(line);
                            }
                            values = line.Split(cCSVDivider);
                            iLines++;
                            //// the first line contains the field names

                            bReadOk = loadGlossaryList(values, sFieldNames);

Regards.

Sunitha.


November 7th, 2013 6:41am

how you are importing the csv?

check this powershell script: http://davidlozzi.com/2012/02/29/loading-sharepoint-lists-from-excel/

or here is nice 3rdparty tool.

http://www.simego.com/Blog/2010/03/sharepoint-import-csv-excel-data-file

Free Windows Admin Tool Kit Click here and download it now
November 9th, 2013 1:46am

Hi Sunitha,

It's bad design that your field value can run over more than one line.And it doesn't matter at the end if everything migrated well in SharePoint , but it matters how you store the value in csv file.

Ideally you csv file should satisfy this conditions.

1. Each line represent each row in list.

2. If your field values has comma(,) , Put the value under double quotes ("")

After that you can use power shell script to migrate the value to SharePoint.

$file = Import-Csv C:\EmployeeList.csv

    foreach($csv in $file)
    {
        
     // Put your code to create the listem i
      
    }

or  you can write your custom CSV parser.Please let me know if you need.

Regards,

Jayant

*Please remember to mark your question as answered & Vote helpful,if this solves/helps your problem.* 

November 9th, 2013 6:26am

Hi jayant ,

all your answers are so much help full me, finally i had loaded successfully. Thank you so much for spending valuable time for answering me. 

  

Free Windows Admin Tool Kit Click here and download it now
November 19th, 2013 5:28am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics