Hi I wonder if you guys could help please.
I'm writing a application that is going to live on multiple servers and therefore multiple IP's and instead of using the exact IP and directory structure I'd like to just 'step back' a folder from where the application is actually running. So for instance....
The folder structure is
\controls\ ---- This contains the aspx file that is going to check if an xml file exists in the blogengine folder.
\blogengine\ This should contain xml files
The code that I'm using is......
string[] filePaths = Directory.GetFiles(@"\\94.175.237.35\inetpub$\wwwroot\mytest\BlogEngine\", "*.xml");
Which will find the files on a particular server but I need to find the files relative to the server that the application is running on, so that I don't have to keep changing the file path. So I'd need something like
string[] filePaths = Directory.GetFiles(@"..\BlogEngine\", "*.xml");
But I can't find the correct syntax in order to do this?
Does anyone know??
Thanks in advance, Craig
Use the Server.MapPath()
method to map a relative path (based on current directory or web-site root) to an absolute accessible path.
For example:
string folderPath = Server.MapPath("~/BlogEngine");
string[] filePaths = Directory.GetFiles(folderPath, "*.xml");
The tilde character represents the root of your web-site, if you specify a relative path then it'll be resolved as relative to the directory where your ASP.NET page resides.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With