Reputation: 3955
I want to get last modification date of the file that is returned by action method. I think I need a full file path. FilePathResult
has property FileName
.
Does this property return full file path or just a name? If so, can I somehow obtain full path to that file?
Thanks!
Upvotes: 0
Views: 2207
Reputation: 1039598
It returns the full path to the file. Example:
[MyActionFilter]
public ActionResult Index()
{
return File(Server.MapPath("~/web.config"), "text/xml");
}
and then:
public class MyActionFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
var fileResult = filterContext.Result as FilePathResult;
if (fileResult != null)
{
// here you will get the full absolute path to the file,
// for example c:\inetpub\wwwroot\MvcApplication1\web.config
string fileName = fileResult.FileName;
}
}
}
Upvotes: 3