注册本站  论坛  繁體中文

电脑技巧
手机 | MP3 | MP4 | 显卡 | 主板 | 显示器 | 光存储 | 笔记本 | 网络设备 | 移动存储 | 数码相机
键鼠 | CPU | 音箱 | GPS | 电视 | 服务器 | 投影机 | 机箱电源 | 品牌电脑 | 办公打印 |
| 网站首页 | Cisco | Windows | Linux | Java | Dotnet | Oracle | 网页设计 | 平面设计 | 安全 | 软件应用 | 电脑维修 | 办公维修 |
您现在的位置: 电脑技巧 >> Dotnet >> C# >> Dotnet正文

C#上传 下载 删除 文件列表

文章来源:中国IT实验室收集整理 作者:佚名 更新时间:2008-6-28 20:38:51 【 】 【加入收藏

    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

  • 上一篇Dotnet:

  • 下一篇Dotnet:
  • 最 新 热 门
     web.config配置文件中的 元素
     为网站添加业务层
     用SqlDataSource实现DataList嵌套DataList
     Visual Studio 2003插件的编写
     千条DOS命令收藏
     IIS 常见问题
     IIS需要的最小NTFS权限
     优化 .NET的性能
     设计模式与VB .net代码 外观模式,合成模式
     VB.net中介者模式
    最 新 推 荐
     Windows via C/C++ —进程(一)
     C#邮件发送程序
     扩展 ASP.NET 的客户端验证
     实现DataGridView中行的上下移动
     C#中的委托和事件
     与IDE相关的Attribute属性
     C#中using关键字的使用介绍
     C#FileStream复制大文件
     C#实用技巧:轻松实现对文件的操作
     C#实现所有经典排序算法
    相 关 文 章

    C#通过ADO.NET建表点实现方法
    asp.net+C#实现文件上传实现代码
    C#邮件发送程序
    C#中的委托和事件
    C#中using关键字的使用介绍
    C#FileStream复制大文件
    C#实用技巧:轻松实现对文件的操作
    C#实现所有经典排序算法
    c#生成的word文档
    C#编程技巧:轻松实现对文件的操作

    | 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 网站公告

     

    Copyright 2006-2008 pcjx.com All Rights Reserved
    电脑技巧 版权所有 粤ICP备06059145号 地图
    本网站所有内容未经许可不得转载或做其他使用