Search code examples
c#asp.netstringimageresizer

Parsing Image Path in ImageResizer


I'm resizing an image dynamically thus:

ImageJob i = new ImageJob(file, "~/eventimages/<guid>_<filename:A-Za-z0-9>.<ext>", 
    new ResizeSettings("width=200&height=133&format=jpg&crop=auto"));
i.Build();

I'm attempting to store the image relative URL in the DB. The i.FinalPath property gives me:

C:\inetpub\wwwroot\Church\eventimages\56b640bff5ba43e8aa161fff775c5f97_scenery.jpg

How can I obtain just the image filename - best way to parse this?

Desired string: /eventimages/56b640bff5ba43e8aa161fff775c5f97_scenery.jpg


Solution

  • something like below,

    var sitePath = MapPath(@"~");
    var relativePath= i.FinalPath.Replace(sitePath, "~");