Anonymous
Anonymous

Reputation: 1988

Absolute path with disk name (C:\\) to relative path (~/)

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

Answers (1)

bgs264
bgs264

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

Related Questions