I have a webserver setup in iis called WebServer, in location ex. C:\inetpub\WebServer\ I have created a virtual directory call it virtualdir where the physical path is outside of the path of my webserver for example the Virtual directory points at C:\inetput\virtualdir, everything works fine and I can access files going to www.myserver.com/virtualdir/test.txt, however I was wondering if from my default.aspx page I can reference the virtual directory as part of my project like so
File.Exists("~/virtualdir/test.txt)
or do I have to reference the complete path of the virtual directory like so
File.Exists("C:/inetpub/virtualdir/test.txt")
Thank you,
You need to convert a relative, web based path containting the "~" to a path that file.exists can deal with. in order to do that call server map path to convert one to the other. See http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath(v=vs.100).aspx
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