Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following code and I want to run it in VS2008. But it is giving the error like :

The type or namespace name Linq does not exists in the namespace system.

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = "D:/Project/";
            //string[] fileNames = { "A_L_PRTD_432124.txt", "A_L_PRTD_021345.txt" };
            string fileNameStartsWIth = "A_L_PRTD_";
            string[] fileNames = Directory
                 .GetFiles(path, "*.txt", SearchOption.AllDirectories)
                 .Select(f => Path.GetFileName(f)).Where(k => k.StartsWith(fileNameStartsWIth)).ToArray();

            string finalFile = "L_PRTD_" + DateTime.Now.ToString("ddMMyyyy") + ".txt";

          List<string> lstLines = new List<string>();
            foreach (string file in fileNames)
            {
                string[] content = File.ReadAllLines(path + file).Select(k => k.Trim()).Distinct().ToArray();
                lstLines.AddRange(content);
            }
            var data = lstLines.Distinct();
            File.AppendAllLines(path + finalFile, data);


        }
    }
}


Please help.
Posted
Updated 26-Feb-19 23:32pm
Comments
Kornfeld Eliyahu Peter 5-Jan-14 4:23am    
Missing reference?
Check your project's references...
DEbopm 5-Jan-14 4:28am    
how to add reference ?

Right click your project -> Add Reference -> select Framework tab -> select System.Core.Dll 3.5 version... -> click ok


if u r not able to locate the dll , you can download from this system.core.dll[^]


AppendAllLines is in framework 4.0, which is not available in v 3.5..
you can use WriteAllLines instead of it incase of v 3.5
 
Share this answer
 
v3
Comments
DEbopm 5-Jan-14 5:00am    
hello karthik ,

Its me again :) .. Actually I am using .net framework 3.5 in client system where I will need to code this . But it is saying me error in this line : File.AppendAllLines(path + finalFile, data);
Error:System.IO.file does not contain definition for AppendAllLines. kindly help.
Karthik_Mahalingam 5-Jan-14 5:08am    
System.IO is available in mscorlib.dll ...

then how you r getting this error ???
Karthik_Mahalingam 5-Jan-14 5:13am    
ok wait
DEbopm 5-Jan-14 5:10am    
I have checked and found that AppendAllLines is a method for .net4.0 and above and not for .net3.5 .. How can it be passed?
Karthik_Mahalingam 5-Jan-14 5:17am    
try this..

var data = lstLines.Distinct().ToArray();
File.WriteAllLines(path + finalFile, data );
 
Share this answer
 

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