Reputation: 1988
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.
Upvotes: 0
Views: 1486
Reputation: 4642
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.
Upvotes: 2