I had earlier written a quick and dirty method to convert a Physical path to a virtual path (aka a url) that can be used on the client after passing through ASP.NET’s ResolveUrl method. Without much talking, here’s the method:
{syntaxhighlighter brush: csharp;fontsize: 100; first-line: 1; }public static class Globals
{
private static string applicationPath;
static Globals ()
{
Globals.applicationPath = System.Web.Hosting.HostingEnvironment.MapPath(“~/”);
}
public static string resolveVirtual (string physicalPath)
{
string url=physicalPath.Substring(Globals.applicationPath.Length).Replace(‘\\’, ‘/’).Insert(0, “~/”);
return (url);
}
}{/syntaxhighlighter}
The method Globals.resolveVirtual accepts an absolute physical path (the physical path should be an absolute path and not a relative one), strips out the path to application root from it, and then converts it to an app-relative url. You can pass it through ResolveUrl method to get a url usable on the client.
There’s a caveat though. This would work only if your ASP.NET application does not have nested virtual directories in it. IIS would allow you to define your application as a virtual directory and further create nested virtual directories that are physically outside your application’s root folder. The above method would not work for such nested virtual directory paths.
Nice Blog and this post is also gud …but i don’t get my proper solution..do u ave any idea about this?
in my project – there are 3 architecture
(1) Presentation(WPF)
(2) WCF
(3) DataAccess(ClassLibrary)
but problrem is that in DataAccess (Class Library) through i can insert,update and delete data..when i put static path(of xml file) every thing will ok but when i add key and value in web.config and write this
System.Web.Hosting.HostingEnvironment.MapPath(“~/folder/file”); in access file
then it shows the path like D://ProjectName/WCF//Folder/File but actually it was D://ProjectName/DataAccess//Folder/File
When i write Server.Mappath At that same things occur..Is there any communication necessary between WPF and WCF(Service) to access d path..bcoz my web.config in WCF and i m write this in DataAccess..but it takes service path everytime
I m doing this thing for last 3 days..but not get proper solution..
Thanks
Your Blog is really nice..thank you 4 help ..:)
How to get physical path in wcf service
Thank you so much. It helped to me.