Click here to Skip to main content
14,325,352 members
Rate this:
Please Sign up or sign in to vote.
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.

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 ?
Rate this:
Please Sign up or sign in to vote.

Solution 2

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
   
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 );
Karthik_Mahalingam 5-Jan-14 5:18am
   
you r right, AppendAllLines is in framework 4.0, which is not available in v 3.5..
DEbopm 5-Jan-14 5:24am
   
it worked !! thanks a lot again dude :)
Karthik_Mahalingam 5-Jan-14 5:26am
   
welcome :)
Joezer BH 5-Jan-14 11:20am
   
Hi Karthik,

TIP: When you update important info that helps the user to solve the problem, remember to update the solution above with the info, it will help future users to use the info easily!

Cheers,
Canny
Karthik_Mahalingam 5-Jan-14 11:43am
   
sure canny
i will follow your words
ya u r right..
DEbopm 5-Jan-14 12:32pm
   
hi karthik .. U there ? I have one more question to ask.

I want to move those old files to a backup location after they will be combined in a single file. How to add the steps .
Karthik_Mahalingam 6-Jan-14 0:00am
   
yes u can do it.
please visit this link
http://msdn.microsoft.com/en-us/library/cc148994.aspx
DEbopm 6-Jan-14 0:01am
   
I found the answer .. anyways thank you karthik ..
Karthik_Mahalingam 6-Jan-14 0:05am
   
:) welcome
DEbopm 6-Jan-14 0:07am
   
I have posted a question in differntly to read from text file and checking in sql server . can you please help me with that one ?
Karthik_Mahalingam 6-Jan-14 0:43am
   
ok i will check it.
DEbopm 6-Jan-14 0:45am
   
http://www.codeproject.com/Questions/706457/How-do-I-Search-in-sql-db-from-text-file-and-if-pr
Rate this:
Please Sign up or sign in to vote.

Solution 1

   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100