0

I have directory on my server that stores user profile images. They're being saved in UserImages directory.

On SQL Server, User's profile image is being saved like this:

C:\\inetpub\\wwwroot\\Project\\Project\\UserImages\\userimage.jpg

I have a GET ActionResult method that uses ET to get user data and returns it to View. The problem however is, I'm lost as to how I can pass a usable relative Path from full path as given above.

How can I make relative path from absolute path on hard drive so it can be used as src for a HTML image?

Edit: Razor won't work, since image can be updated using AJAX - when it is, I receive some JSON from server with new data.

Suren Srapyan
  • 66,568
  • 14
  • 114
  • 112
OverflowStack
  • 825
  • 1
  • 14
  • 30

1 Answers1

1

On the backend you can do something like this. Not so fancy, but it can do the job I think.

var relativePath = yourPathOnDb.Substring(0, Server.MapPath("~").Length);
Tolga Evcimen
  • 7,112
  • 11
  • 58
  • 91