1. 程式人生 > >學習日記19、獲取某個文件路徑下所有的文件信息

學習日記19、獲取某個文件路徑下所有的文件信息

視圖 app avi sele () oar bst cto 獲取文件信息

public JsonResult GetView(string suoshu)
{
string url = "";
Dictionary<string,string> strlist = new Dictionary<string,string>();
if (suoshu == "zf")
{
url = Server.MapPath("~/Areas/X/Views/Mesf");//返回物理路徑
}
else if(suoshu=="xxy")
{
url = Server.MapPath("~/Areas/X/Views/Mesy");//返回物理路徑
}
else
{
return Json(null, JsonRequestBehavior.AllowGet);
}
//初始化
DirectoryInfo dir = new DirectoryInfo(url);
//返回文件類
FileInfo[] fi = dir.GetFiles();
if (fi.Length > 0)
{
//循環獲取文件信息
foreach(FileInfo dChild in fi)
{
if (dChild.Extension.ToLower() == ".cshtml")
{
strlist.Add(dChild.Name.Substring(0, dChild.Name.IndexOf(‘.‘)), dChild.Name.Substring(0, dChild.Name.IndexOf(‘.‘)));
}
}
}
var json =new {
rows=(from r in strlist
select new
{
Id = r.Key,
Name = r.Value
}).ToArray()
};
return Json(json,JsonRequestBehavior.AllowGet);
}

這是我的一個獲取mvc某個視圖文件下所有視圖的方法

學習日記19、獲取某個文件路徑下所有的文件信息