kez kez - 1 year ago 101
C# Question

Image path return getting as string value

I have following method to get an Image path in a Project

public ActionResult RenderImage(string imageid, string pathvalue)
var URL = System.Configuration.ConfigurationManager.AppSettings[pathvalue].ToString();
var path = Path.Combine(URL, imageid + ".jpg");
return base.File(path, "image/jpeg");
catch (Exception)

I want to take this returning Image path as string , for that I tried something like this

ControllerName ns = new ControllerName ();

var path = ns .RenderImage("id", "path");
string imageurl = path.ToString();

but this is not getting image path as "C:/User/Data/Image.jpg" its getting value as "System.Web.Mvc.FilePathResult"

How to solve this

Answer Source


var ns = new ControllerName ();

var path = ns.RenderImage("id", "path");  

 var fileResult = path  as FilePathResult;

    if (fileResult != null)

        string imageurl = fileResult.FileName;
        imageurl = imageurl.Replace(@"\\", @"\");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download