Reputation: 761
i was trying to get physical path of a file, and got the information that Server.MapPath
will give you. But for me in my windowform i am not getting that even i used namespace using System.Web;
but still not getting?
for example if i have a file named "myTestClass.xml" somewhere in my system, and i need to get the physical path, what i need to do in button click event
Upvotes: 1
Views: 11670
Reputation: 4629
In WinForm application you don't need to use Server.MapPath.
Instead you can use combine path relative to your application StartupPath.
For example:
Directory.GetCurrentDirectory()
EDIT:
If you want to find file in directory you can use function, example:
string fileNameToFind = "*.txt";
string directoryToSearch = @"C:\Path\To\Folder\To\Search\In";
string[] files = Directory.GetFileSystemEntries(directoryToSearch, fileNameToFind, SearchOption.AllDirectories);
foreach (string f in files)
{
Console.WriteLine("File: " + f);
}
Console.WriteLine("Total of " + files.Length + " files found.");
Upvotes: 1