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!

1 Answer 1

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;
        }
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

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!
@AlekseiChepovoi, that's a completely different questoin which has nothing to do with your original question and is a duplicate of this one: stackoverflow.com/questions/14914228/… 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.