Dovberman
asked on
How to specify a relative path
The following code works on the local machine but not on the server:
strSourcePath = "C:\\Develop\\Apps\\StockP ro\\Data\\ ";
// Fill Local files listbox
lstSourceFiles.Items.Clear ();
string strFileName = "";
int intFileCount = 0;
foreach (string FileName in Directory.GetFiles(strSour cePath, "*.txt", SearchOption.TopDirectoryO nly))
{
intFileCount += 1;
strFileName = FileName;
lstSourceFiles.Items.Add(s trFileName );
}
A file not found error is returned.
I know that I need to specify a relative path to "C:\\Develop\\Apps\\StockP ro\\Data\\ "
How is this done?
Thanks,
strSourcePath = "C:\\Develop\\Apps\\StockP
// Fill Local files listbox
lstSourceFiles.Items.Clear
string strFileName = "";
int intFileCount = 0;
foreach (string FileName in Directory.GetFiles(strSour
{
intFileCount += 1;
strFileName = FileName;
lstSourceFiles.Items.Add(s
}
A file not found error is returned.
I know that I need to specify a relative path to "C:\\Develop\\Apps\\StockP
How is this done?
Thanks,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
string strMapPath = Server.MapPath("");
strMapPath = "C:\\Develop\\Apps\\StockP ro\\Admin"
// Local directory
strSourcePath = "C:\\Develop\\Apps\\StockP ro\\Data\\ ";
strSourcePath = MapPath("~/Data/");
returns
"C:/Develop/Apps/StockPro/ Data/";
This works on the local machine.
I will now try it on the server.
strMapPath = "C:\\Develop\\Apps\\StockP
// Local directory
strSourcePath = "C:\\Develop\\Apps\\StockP
strSourcePath = MapPath("~/Data/");
returns
"C:/Develop/Apps/StockPro/
This works on the local machine.
I will now try it on the server.
ASKER
This works on the local machine but not on the server.
strSourcePath = MapPath("~/Data/");
returns
"C:/Develop/Apps/StockPro/ Data/"; // This is where the .txt file is.
There is no error message.
intFileCount returns zero.
foreach (string FileName in Directory.GetFiles(strSour cePath, "*.txt", SearchOption.TopDirectoryO nly))
{
intFileCount += 1;
strFileName = FileName;
lstSourceFiles.Items.Add(s trFileName );
}
intFileCount returns zero.
Yet there is a .txt file in the directory.
Suggestions?
Thanks,
strSourcePath = MapPath("~/Data/");
returns
"C:/Develop/Apps/StockPro/
There is no error message.
intFileCount returns zero.
foreach (string FileName in Directory.GetFiles(strSour
{
intFileCount += 1;
strFileName = FileName;
lstSourceFiles.Items.Add(s
}
intFileCount returns zero.
Yet there is a .txt file in the directory.
Suggestions?
Thanks,
Does it return anything if you change the wildcard to *.*?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The mis-understanding was mine.
I did not realize that mappath refers to directories on the server.
I was attempting to access directories on my local machine.
I did not realize that mappath refers to directories on the server.
I was attempting to access directories on my local machine.
ASKER
Thank you
http://dotnetperls.com/mappath
So in this case it would be something like this...
strSourcePath = MapPath("~/Data/");