首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

C# 檔案操作實戰:上傳、下載、刪除與列表(二)

     編輯:關於C語言

4. 取得資料夾下的檔案清單

#region 取得目前可用的檔案清單
/// <summary>
/// 取得目前可用的檔案清單
/// </summary>
/// <param name="IsAlert">是否需要彈出提示訊息</param>
private void fn_getCurrFileList(bool IsAlert)
{
    try
    {
        // 尋找 XMLzip 資料夾下屬於本身 UnitCoding 的相關 zip 檔案
        string strXmlZipDirectory = Server.MapPath("../XMLzip/");
        if (Directory.Exists(strXmlZipDirectory))
        {
            DirectoryInfo di = new DirectoryInfo(strXmlZipDirectory);
            FileInfo[] FI = di.GetFiles("*.zip"); // 僅查詢 .zip 檔案
            if (FI.Length > 0)
            {
                lst_DownLoadFileList.Items.Clear();
                foreach (FileInfo tmpFI in FI)
                {
                    ListItem tmpItem = new ListItem();
                    tmpItem.Text = tmpFI.Name;
                    lst_DownLoadFileList.Items.Add(tmpItem);
                }
                lst_DownLoadFileList.SelectedIndex = 0;
            }
            else
            {
                if (IsAlert)
                {
                    Response.Write("查無可下載的檔案!");
                }
            }
        }
    }
    catch (Exception ex)
    {
        ex.ToString(); // 建議記錄日誌
    }
}
#endregion

更多詳細內容將於後續補充。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved