Click here to Skip to main content
15,077,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,
My task is to import contacts from Outlook.
user going to export the file in .csv format I have to parse that data and take firstname, lastname and Email from that file.

Part of that is this.. I am able to separate into each lines then I want to separate comma's but I am getting an error in my for loop....
implicit conversion is not possible?????

No idea why??? How can I get firstname and email details from that array?????/


C#
using (Stream s = file.InputStream)
          {
              string[] numberOfUsers;
              var sr = new StreamReader(s);
              string contacts = sr.ReadToEnd();
              contacts = contacts.Replace("\r\n", "\n");
              string[] separateLines = contacts.ToString().Split('\n');
              for (int i = 0; i <= ((separateLines.Length) - 1); i++)
              {
                  numberOfUsers[i] = (separateLines[i + 1].ToString()).Split(',');
              }
Posted
Updated 14-Oct-10 0:47am
v2

foreach (string line in separateLines)
{
    numberOfUsers = line.Split(',');
    // now you can go through the field
    foreach( string fieldOnLine in numberOfUsers )
    {
        // process fieldOnLine here
    }
}


string.spilt() return a string[] not a string i.e numberOfUser[i] is a string. numberOfUser is a string[]
   
v2
You may want to look at this tool, FileHelpers v2.0 - Delimited (CSV) or Fixed Data Import/Export Framework[^]

You have not initialized the numberOfUsers array, only declared it. Since there can be a variable number of contacts per file I would have used a List<string> rather than an array.

For future reference, in this line the ToString is not necessary since seperateLines is already a string array;

separateLines[i + 1].ToString()
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900