国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

C# 文件操作(上傳 下載 刪除 文件列表...)

2024-07-21 02:26:27
字體:
來源:轉載
供稿:網友
  • 本文來源于網頁設計愛好者web開發社區http://www.html.org.cn收集整理,歡迎訪問。
  • using system.io;

    1.文件上傳
    ----------
    如下要點:
    html部分:
    <form id="form1" runat="server" method="post" enctype="multipart/form-data">
    <input id="fileupload" type="file" runat="server"/><br />
    后臺cs部分 按鈕事件
    //string strfilefullname = system.io.path.getfilename(this.fileupload.postedfile.filename);
    //this.fileupload.postedfile.saveas(server.mappath("./xmlzip/") + strfilefullname);

    2.文件下載
    ----------
    listbox的selectedindexchanged事件 設定相關下載連接
        protected void lst_downloadfilelist_selectedindexchanged(object sender, eventargs e)
        {
            try
            {
                string strjs = "window.open('xmlzip/";
                strjs += this.lst_downloadfilelist.selecteditem.text.trim();
                strjs += "'); return false; ";
                this.imgbtn_downloadfile.attributes.add("onclick", strjs);
            }
            catch (exception ex)
            {
                ex.tostring();
            }
        }
    或者也可以通過 改變label的text值 來實現點擊后實現文件下載的超級連接
    this.label1.text = "<a href=/"xmlzip/a.rar/">a.rar</a>"

    3.文件刪除
    ---------
    string strfilepath = server.mappath("../countryflowmgr/xmlzip/"+this.lst_downloadfilelist.selecteditem.text.trim());
    if (file.exists(strfilepath))
    {
       file.delete(strfilepath);
       if (file.exists(strfilepath))
       {
     response.write("ok");
       }
       else
       {
            response.write("ok");
       }
    }

    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(environment.currentdirectory);
                    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
     


    發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 武鸣县| 岱山县| 安陆市| 岚皋县| 泰宁县| 襄城县| 朝阳县| 河间市| 桃江县| 万载县| 湘潭市| 馆陶县| 沾益县| 澄江县| 衡阳市| 临沧市| 霍州市| 台安县| 宁蒗| 宁武县| 丰台区| 分宜县| 沙田区| 景洪市| 宝山区| 炉霍县| 济源市| 富顺县| 满城县| 二手房| 阳江市| 合江县| 台安县| 铜川市| 台中县| 衡东县| 胶南市| 莒南县| 石泉县| 罗田县| 嘉荫县|