アクションメソッドによって返されるファイルの最終変更日を取得したい。フルファイルパスが必要だと思います。FilePathResult
プロパティがありますFileName
。
このプロパティは完全なファイルパスを返しますか、それとも名前だけを返しますか?もしそうなら、どういうわけかそのファイルへのフルパスを取得できますか?
ありがとう!
アクションメソッドによって返されるファイルの最終変更日を取得したい。フルファイルパスが必要だと思います。FilePathResult
プロパティがありますFileName
。
このプロパティは完全なファイルパスを返しますか、それとも名前だけを返しますか?もしそうなら、どういうわけかそのファイルへのフルパスを取得できますか?
ありがとう!
ファイルへのフルパスを返します。例:
[MyActionFilter]
public ActionResult Index()
{
return File(Server.MapPath("~/web.config"), "text/xml");
}
その後:
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;
}
}
}