Cleiton
Cleiton

Reputation: 18113

Convert absolute path to clientrelative path

Using ASP.NET how can I convert a absolute path to a relative client path?

Eg.: Today I have a address like that: 'c:\web\site\images\somefile.some' I want to convert to "/site/images/somefile.some", It is worth to say that "site", "images" and somefile.some may change.

Upvotes: 0

Views: 470

Answers (1)

Stephen Wrighton
Stephen Wrighton

Reputation: 37819

This Question will help you: Absolute path back to web-relative path

That said, why are you using an absolute path rather than the ~/ which is suggested?

For example, if you use "~/images/somefile.some" and pass it to the [Control].ResolveUrl(url as string) method, then it would translate that into the path for somefile.some based on the root of the directory.

Upvotes: 2

Related Questions