asp.net 獲取指定文件夾下所有子目錄及文件(樹形)
/****************************************
* 函數(shù)名稱:GetFoldAll(string Path)
* 功能說明:獲取指定文件夾下所有子目錄及文件(樹形)
* 參 數(shù):Path:詳細(xì)路徑
* 調(diào)用示列:
* string strDirlist = Server.MapPath("templates");
* this.Literal1.Text = EC.FileObj.GetFoldAll(strDirlist);
*****************************************/
/// <summary>
/// 獲取指定文件夾下所有子目錄及文件
/// </summary>
/// <param name="Path">詳細(xì)路徑</param>
public static string GetFoldAll(string Path)
{
string str = "";
DirectoryInfo thisOne = new DirectoryInfo(Path);
str = ListTreeShow(thisOne, 0, str);
return str;
}
/// <summary>
/// 獲取指定文件夾下所有子目錄及文件函數(shù)
/// </summary>
/// <param name="theDir">指定目錄</param>
/// <param name="nLevel">默認(rèn)起始值,調(diào)用時(shí),一般為0</param>
/// <param name="Rn">用于迭加的傳入值,一般為空</param>
/// <returns></returns>
public static string ListTreeShow(DirectoryInfo theDir, int nLevel, string Rn)//遞歸目錄 文件
{
DirectoryInfo[] subDirectories = theDir.GetDirectories();//獲得目錄
foreach (DirectoryInfo dirinfo in subDirectories)
{
if (nLevel == 0)
{
Rn += "├";
}
else
{
string _s = "";
for (int i = 1; i <= nLevel; i++)
{
_s += "│ ";
}
Rn += _s + "├";
}
Rn += "<b>" + dirinfo.Name.ToString() + "</b><br />";
FileInfo[] fileInfo = dirinfo.GetFiles(); //目錄下的文件
foreach (FileInfo fInfo in fileInfo)
{
if (nLevel == 0)
{
Rn += "│ ├";
}
else
{
string _f = "";
for (int i = 1; i <= nLevel; i++)
{
_f += "│ ";
}
Rn += _f + "│ ├";
}
Rn += fInfo.Name.ToString() + " <br />";
}
Rn = ListTreeShow(dirinfo, nLevel + 1, Rn);
}
return Rn;
}
/****************************************
* 函數(shù)名稱:GetFoldAll(string Path)
* 功能說明:獲取指定文件夾下所有子目錄及文件(下拉框形)
* 參 數(shù):Path:詳細(xì)路徑
* 調(diào)用示列:
* string strDirlist = Server.MapPath("templates");
* this.Literal2.Text = EC.FileObj.GetFoldAll(strDirlist,"tpl","");
*****************************************/
/// <summary>
/// 獲取指定文件夾下所有子目錄及文件(下拉框形)
/// </summary>
/// <param name="Path">詳細(xì)路徑</param>
///<param name="DropName">下拉列表名稱</param>
///<param name="tplPath">默認(rèn)選擇模板名稱</param>
public static string GetFoldAll(string Path,string DropName,string tplPath)
{
string strDrop = "<select name=\"" + DropName + "\" id=\"" + DropName + "\"><option value=\"\">--請(qǐng)選擇詳細(xì)模板--</option>";
string str = "";
DirectoryInfo thisOne = new DirectoryInfo(Path);
str = ListTreeShow(thisOne, 0, str,tplPath);
return strDrop+str+"</select>";
}
/// <summary>
/// 獲取指定文件夾下所有子目錄及文件函數(shù)
/// </summary>
/// <param name="theDir">指定目錄</param>
/// <param name="nLevel">默認(rèn)起始值,調(diào)用時(shí),一般為0</param>
/// <param name="Rn">用于迭加的傳入值,一般為空</param>
/// <param name="tplPath">默認(rèn)選擇模板名稱</param>
/// <returns></returns>
public static string ListTreeShow(DirectoryInfo theDir, int nLevel, string Rn,string tplPath)//遞歸目錄 文件
{
DirectoryInfo[] subDirectories = theDir.GetDirectories();//獲得目錄
foreach (DirectoryInfo dirinfo in subDirectories)
{
Rn += "<option value=\"" + dirinfo.Name.ToString() + "\"";
if (tplPath.ToLower() == dirinfo.Name.ToString().ToLower())
{
Rn += " selected ";
}
Rn += ">";
if (nLevel == 0)
{
Rn += "┣";
}
else
{
string _s = "";
for (int i = 1; i <= nLevel; i++)
{
_s += "│ ";
}
Rn += _s + "┣";
}
Rn += "" + dirinfo.Name.ToString() + "</option>";
FileInfo[] fileInfo = dirinfo.GetFiles(); //目錄下的文件
foreach (FileInfo fInfo in fileInfo)
{
Rn += "<option value=\"" + dirinfo.Name.ToString()+"/"+fInfo.Name.ToString() + "\"";
if (tplPath.ToLower() == fInfo.Name.ToString().ToLower())
{
Rn += " selected ";
}
Rn += ">";
if (nLevel == 0)
{
Rn += "│ ├";
}
else
{
string _f = "";
for (int i = 1; i <= nLevel; i++)
{
_f += "│ ";
}
Rn += _f + "│ ├";
}
Rn += fInfo.Name.ToString() + "</option>";
}
Rn = ListTreeShow(dirinfo, nLevel + 1, Rn, tplPath);
}
return Rn;
}
#endregion
- Jquery.TreeView結(jié)合ASP.Net和數(shù)據(jù)庫生成菜單導(dǎo)航條
- ASP.NET生成樹形顯示的GridView實(shí)現(xiàn)思路
- 常用的在數(shù)據(jù)庫中建立無限級(jí)樹形菜單的asp.net代碼
- asp.net實(shí)現(xiàn)遞歸方法取出菜單并顯示在DropDownList中(分欄形式)
- ASP.NET遞歸法求階乘解決思路
- 遞歸輸出ASP.NET頁面所有控件的類型和ID的代碼
- asp.net實(shí)現(xiàn)DropDownList,TreeView,ListBox的無限極分類目錄樹
- asp.net TreeView與XML三步生成列表樹
- Asp.net treeview實(shí)現(xiàn)無限級(jí)樹實(shí)現(xiàn)代碼
- asp.net TreeView遞歸循環(huán)子節(jié)點(diǎn)生成樹形菜單實(shí)例
相關(guān)文章
關(guān)于.NET Attribute在數(shù)據(jù)校驗(yàn)中的應(yīng)用教程
這篇文章主要給大家介紹了關(guān)于.NET Attribute在數(shù)據(jù)校驗(yàn)中的應(yīng)用的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用.NET具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05
在IIS上部署ASP.NET Core Web API的方法步驟
這篇文章主要介紹了在IIS上部署ASP.NET Core Web API的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08
ASP.NET Session的七點(diǎn)認(rèn)識(shí)小結(jié)
ASP.NET Session的使用當(dāng)中我們會(huì)遇到很多的問題,那么這里我們來談下經(jīng)常出現(xiàn)的一些常用ASP.NET Session的理解2011-07-07
asp.net 擴(kuò)展GridView 增加單選按鈕列的代碼
asp.net 擴(kuò)展GridView 增加單選按鈕列的代碼2010-02-02
Visual?Studio?2022常見的報(bào)錯(cuò)以及處理方案圖文詳解
許多用戶在使用Visual Studio的過程中常會(huì)遇到各種問題,下面這篇文章主要給大家介紹了關(guān)于Visual?Studio?2022常見的報(bào)錯(cuò)以及處理方案的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下2023-04-04
asp.net中virtual和abstract的區(qū)別分析
這篇文章主要介紹了asp.net中virtual和abstract的區(qū)別,較為詳細(xì)的分析了virtual與abstract的概念與具體用法,并以實(shí)例的形式予以總結(jié)歸納,需要的朋友可以參考下2014-10-10
asp.net文件上傳功能(單文件,多文件,自定義生成縮略圖,水印)
上傳功能,是大家經(jīng)常用到了,可能每一個(gè)項(xiàng)目都可以會(huì)用到。網(wǎng)上到處都有上傳功能的代碼。比我寫的好的有很多。我這里也僅是分享我的代碼。2011-09-09
調(diào)試ASP.NET應(yīng)用程序的方法和技巧
調(diào)試ASP.NET應(yīng)用程序的方法和技巧...2006-09-09
asp.net AjaxControlToolKit--TabContainer控件的介紹
ModalPopup控件允許一個(gè)asp頁面的部分內(nèi)容以對(duì)話框的模式顯示給用戶,同時(shí)會(huì)限制用戶于頁面的其他部分交互。對(duì)話框顯示的內(nèi)容可以是一個(gè)層級(jí),這個(gè)層級(jí)的背景可以使用戶自定義的格式,簡單的理解好比是一個(gè)對(duì)話框彈出來后,主頁面會(huì)顯示灰色,且不可操作。2009-06-06
.NET Core/Framework如何創(chuàng)建委托大幅度提高反射調(diào)用的性能詳解
反射是一種很重要的技術(shù),下面這篇文章主要給大家介紹了關(guān)于.NET Core/Framework如何創(chuàng)建委托大幅度提高反射調(diào)用性能的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2018-09-09

