0

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!

Aleksei Chepovoi
  • 3,915
  • 8
  • 39
  • 77

1 Answers1

3

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;
        }
    }
}
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • thanks for answer. I was counting on that it returns full file path. I want to set last modification date of the file (first I need to get it). For some reason I can't set (or get) the modification date properly. Can You check my update please? Thanks in advance! – Aleksei Chepovoi Feb 17 '13 at 17:54
  • @AlekseiChepovoi, that's a completely different questoin which has nothing to do with your original question and is a duplicate of this one: http://stackoverflow.com/questions/14914228/client-side-caching-using-last-modified-header-and-outputcacheattribute-in-asp-n Please do not post duplicate questions. Here you initially asked if the `FileName` property returns the full path to the file and the answer to this is yes. If you need to discuss some other code let that happen at the appropriate place. – Darin Dimitrov Feb 17 '13 at 17:56