Reputation: 2215
I have get my website path using HttpRuntime.AppDomainAppPath
(like this C:/personal/Website/page.aspx
)
Web service is always located on page.aspx parent of parent folder (like this C:/personal/Service/service.asmx
). I get the webservice-path using a ABC.dll in servicePath
variable like this string servicePath="C:/personal/Service/service.asmx"
.
How to check service path against website path?
If (GetWebPath()== GetServicePath())
{
// ... do something
}
private string GetWebPath()
{
string path = HttpRuntime.AppDomainAppPath;
string[] array = path.Split('\\');
string removeString = "";
for(int i = array.Length; --i >= 0; )
{
removeString = array[array.Length - 2];
break;
}
path = path.Replace(@"\" + removeString + @"\", "");
return path;
}
private string GetServicePath()
{
string path = @"C:\MNJ\OLK\ABC.asmx"
string[] array = path.Split('\\');
string removeString = "";
for(int i = array.Length; --i >= 0; )
{
removeString = @"\" + array[array.Length - 2] + @"\" + array[array.Length - 1];
path = path.Replace(removeString, "");
break;
}
return path;
}
Upvotes: 4
Views: 979
Reputation: 2509
string webPath = @"C:\blabla\CS_Web\website\";
string servicePath = @"C:\blabla\CS_Web\SPM\Server.asmx";
if(Path.GetDirectory(Path.GetDirectoryName(servicePath))==Path.GetDirectoryName(webPath)
{
//You do something here
}
You have to up page to parent folder using Path.GetDirectoryName()
Upvotes: 1
Reputation: 2240
Providing you want to check the following pathes:
string webPath = @"C:\blabla\CS_Web\website\";
string servicePath = @"C:\blabla\CS_Web\SPM\Server.asmx";
you should call
string webPathParentDir = GetParentDirectoryName(webPath);
string servicePathParentDir = GetParentDirectoryName(servicePath);
if (servicePathParentDir.Equals(webPathParentDir, StringComparison.OrdinalIgnoreCase))
{
// ... do something
}
with method:
private string GetParentDirectoryName(string path)
{
string pathDirectory = Path.GetDirectoryName(servicePath);
return new DirectoryInfo(pathDirectory).Parent.FullName;
}
Upvotes: 1
Reputation: 9583
Try this:
System.Web.Server.MapPath(webPath);
This will return the physical file path of the currently executing web file.
More information can be found here: System.Web.Server
Upvotes: 1