If you are on a asp.net web page model then Server.MapPath("~/")
works to get the root of the site so pass the path you need. You might need to call
HttpContext.Current.Server.MapPath("~/");
For instance a folder where the text files are saved:
string directoryOfTexts = HttpContext.Current.Server.MapPath("~/txtdata/");
To just read from it once you have it you can StreamReader it:
string directoryOfTexts = HttpContext.Current.Server.MapPath("~/txtdata/");
string path = directoryOfTexts + "myfile.txt";
string alltextinfile = "";
if (File.Exists(path))
{
using (StreamReader sr = new StreamReader(path))
{
//This allows you to do one Read operation.
alltextinfile = sr.ReadToEnd());
}
}
If this is for a desktop application then the Applcation class has all this information:
http://msdn.microsoft.com/en-us/library/system.windows.forms.application.startuppath.aspx
Application.StartupPath
All properties list other appdata folders and stuff but once you have the application path to the executable this gives you context such as Application.LocalUserAppDataPath
.
http://msdn.microsoft.com/en-us/library/system.windows.forms.application_properties.aspx
If the content is small enough you could also just save them in a HashTable
or a Generic List<String>
before saving to the database as well.