0
我想獲取操作方法返回的文件的最後修改日期。我想我需要一個完整的文件路徑。 FilePathResult
有財產FileName
。如何在asp.net mvc 3中獲取FilePathResult文件的完整文件路徑?
此屬性是否返回完整的文件路徑或只是一個名稱?如果是這樣,我可以以某種方式獲得該文件的完整路徑嗎?
謝謝!
我想獲取操作方法返回的文件的最後修改日期。我想我需要一個完整的文件路徑。 FilePathResult
有財產FileName
。如何在asp.net mvc 3中獲取FilePathResult文件的完整文件路徑?
此屬性是否返回完整的文件路徑或只是一個名稱?如果是這樣,我可以以某種方式獲得該文件的完整路徑嗎?
謝謝!
它返回文件的完整路徑。例如:
[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;
}
}
}
感謝答案。我指望它返回完整的文件路徑。我想設置文件的最後修改日期(首先我需要得到它)。出於某種原因,我無法正確設置(或獲取)修改日期。你能檢查我的更新嗎?提前致謝! – 2013-02-17 17:54:01
@AleseseiChepovoi,這是一個完全不同的questoin與你原來的問題沒有任何關係,並且是這個副本:http://stackoverflow.com/questions/14914228/client-side-caching-using-last-modified- header-and-outputcacheattribute -in-asp-n請不要發表重複的問題。在這裏,您最初詢問'FileName'屬性是否返回文件的完整路徑,並且答案是肯定的。如果你需要討論一些其他的代碼,讓它發生在適當的地方。 – 2013-02-17 17:56:21