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: 
Instead of `ToDictionary`, You can use `ToLookup`

```
......same code....
.Where(s => s.Length>1)
.ToLookup(s => s[0].Trim(), s => s[1].Trim());

```

Then you can check as

```
string myUser = dic["From"].FirstOrDefault();

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