Any built in way to get virtual / relative path or URL from absolute path containing disk name such as?
Or how to convert this :
C:\\ProjectRoot\\Somedir\\demo.text
to this
~/Somedir/demo.text
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Request.PhysicalApplicationPath will give you the physical root of your virtual directory.
So in your case if your virtual directory was at c:\projectroot, then you’d want ~/somedir/demo.txt right?
So if you did a string replace on the file path, replacing Request.PhysicalApplicationPath into a tilde character, along with swapping \ for / , then you’d get what you needed.