Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
string[] flines = File.ReadAllLines(filenamelocation);
string path = string.Concat(Environment.CurrentDirectory, @"\commport.txt");



and


C#
string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
              string filenamelocation = System.IO.Path.Combine(path, "commport.txt");



we have tried the above code but we couldnot get the result
Experts please help the above problem
Posted
Updated 29-Oct-14 1:04am
v2
Comments
BillWoodruff 29-Oct-14 8:56am    
What does "installing" refer to here. Are you writing a Console App where you need to create a file ? Please clarify.
mahesh483 30-Oct-14 5:02am    
installing means executable file converting console application into set up file

1 solution

Try this

Include namespace "System.IO"

C#
//write
string path = @"D:\YourPath\Test.txt";
if (!File.Exists(path))
{
    File.Create(path);
    TextWriter tw = new StreamWriter(path);
    tw.WriteLine("test line 1!");
    tw.Close();
}
else if (File.Exists(path))
{
    TextWriter tw = new StreamWriter(path, true);
    tw.WriteLine("test line 2!");
    tw.Close(); 
}

//read
string texts = ReadAllText(@"D:\YourPath\Test.txt");
System.Console.WriteLine("File Test.txt contains = {0}", texts);


In case, this doesn't solve your problem, please reply.
 
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