How can I get the relative virtual path from the physical path in asp.net? The reverse method is like below:
Server.MapPath("Virtual Path Here");
But what is the reverse of the upper method?
MapPath method is used to map the virtual path to a physical path.
Physical path - This is the actual path the file is located by IIS. Virtual path - This is the logical path to access the file which is pointed to from outside of the IIS application folder.
A virtual path (VP) is a collection of virtual channel connections (VC) made through an ATM network. Each VP or VC can be either permanently established or set up dynamically for the time needed to transmit information through the network.
Generally this physical and virtual path problem occurred whenever we refer “Server. MapPath” value multiple times while using folder path in applications. To solve this e:is a physical path but a virtual path was expected we need to use Server.
Maybe this question is what you're looking for. There they suggest:
String RelativePath = AbsolutePath.Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"], String.Empty);
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