Question: There are multiple files in a folder that the code should read one by one. I have to extract some key value from the file to perform some business logic.

the file look like this, 

```
x-sender: 
x-receiver: 
Received: 
X-AuditID:
Received: 
Received: 
From: 
To: 
Subject: 
Thread-Topic: 
Thread-Index: 
Date: 
Message-ID: 
Accept-Language: 
Content-Language: 
X-MS-Has-Attach:

```

There are multiple keys that can increase and decrease as per file. The order of the key could also be changed. Every key has some value. 

Code:

```
 private void BtnStart_Click(object sender, EventArgs e)
        {
            // searches current directory

                foreach (string file in Directory.EnumerateFiles(NetWorkPath, "*.eml"))
                {

                    var dic = File.ReadAllLines(file)
                                .Select(l => l.Split(new[] { ':' }))
                                .ToDictionary(s => s[0].Trim(), s => s[1].Trim());
                    string myUser = dic["From"];

            }
        }

```

I was trying to read the file and convert that into dictionary , So that i can access by using Keys. But it is giving me an error `"An item with the same key has already been added.".`

Any help??

Answer: 
That's because `Receieved` is in there multiple times and `Dictionary` doesn't allow duplicate entries for it's key value.

You could use a [`Tuple<string, string>`](http://msdn.microsoft.com/en-us/library/system.tuple.aspx), that would allow duplicates.

If you don't want to return it though, you could just use an anonymous type:

```
foreach (string file in Directory.EnumerateFiles(NetWorkPath, "*.eml"))
{

    var items = myList
        .Select(l => l.Split(new [] {':' }, StringSplitOptions.RemoveEmptyEntries))
        .Where(l => l != null && l.Count() == 2)
        .Select(l => new
        {
            Key = l[0],
            Value = l[1],
        })
        .ToList();

    string myUser = items.First(i => i.Key == "From").Value;
}

```
It is means that you have already added in dictionary the same key twice,
for content of your file it is Received: