Last post Feb 23, 2017 03:11 AM by Eric Du
Feb 22, 2017 02:39 AM|robby32|LINK
I have a project and in the project I have a folder called DataFolder and a folder called Data1 and in there is a number of files , How can i get the pathe to that and get all files below using c#
I have tried using
string Documents = System.IO.Directory.GetFiles(@"DataFolder /Data1");
this gives an exception directory not found
what am i doing wrong here ?
Feb 22, 2017 05:18 AM|ignatandrei|LINK
First, it is a space here:
Second, does the folder exists in bin/debug ?
If not, right click any file inside the folder , properties, "Copy to output directory" => true.
Feb 23, 2017 03:11 AM|Eric Du|LINK
According to your description, please use the following code to read file in root of the project.
AppDomain.CurrentDomain.BaseDirectory method will get the path of this project.
App_Data\Names.txt is the file folder and file name.
Path.Combine method will combine both of paths.
protected void Button1_Click(object sender, EventArgs e)
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"App_Data\Names.txt");
string files = File.ReadAllLines(path);