文件上传下载

前台:

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RecordManage.aspx.cs" Inherits="MemberInfo_RecordManage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
     <title>网络文件夹</title>
    <style type="text/css">
    /*给body、input和select元素同时应用css*/
    body,input,select
    {
     font-family: "宋体";
     font-size: 10pt;
     font-weight: normal;
     color: #000000;
}
    </style>

<head id="Head1" runat="server">
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <!--启用了AutoPostBack-->
            <asp:DropDownList ID="ddl_FunctionList" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddl_FunctionList_SelectedIndexChanged">
                <asp:ListItem Value="-1">选择功能</asp:ListItem>
                <asp:ListItem Value="0">上传限制</asp:ListItem>
                <asp:ListItem Value="1">上传文件</asp:ListItem>
                <asp:ListItem Value="2">管理文件</asp:ListItem>
            </asp:DropDownList>
            &nbsp;
            <asp:Label ID="lab_FolderInfo" runat="server"></asp:Label><br />
            <br />
            <asp:MultiView ID="mvFolder" runat="server">
                <!--上传限制界面开始-->
                <asp:View ID="view_Configure" runat="server">
                    允许上传文件的类型:
                    <asp:BulletedList ID="bl_FileTypeLimit" runat="server">
                    </asp:BulletedList>
                    允许上传单个文件的大小:
                    <asp:Label ID="lab_FileSizeLimit" runat="server" Text=""></asp:Label>
                </asp:View>
                <!--上传文件界面开始-->
                <asp:View ID="view_Upload" runat="server">
                    <asp:FileUpload ID="FileUpload" runat="server" Width="400px" />
                    <br />
                    <asp:Button ID="btn_Upload" runat="server" Text="上传文件" OnClick="btn_Upload_Click" />
                </asp:View>
                <!--管理文件界面开始-->
                <asp:View ID="view_Manage" runat="server">
                    <table cellpadding="5" cellspacing="0" border="0"  width="100%">
                        <tr>
                            <td>
                                <!--启用了AutoPostBack-->
                                <asp:ListBox ID="lb_FileList" runat="server" AutoPostBack="True" Width="600px" Height="400px"  SelectionMode="Multiple"
                                    OnSelectedIndexChanged="lb_FileList_SelectedIndexChanged"></asp:ListBox>
                            </td>
                            <td valign="top" width="800px">
                                <asp:Label ID="lab_FileDescription" runat="server" Text=""></asp:Label>
                            </td>
                        </tr>
                    </table>
                    <asp:Button ID="btn_Download" runat="server" Text="下载文件" OnClick="btn_Download_Click" />
                    <!--在删除前给予确认-->
                    <asp:Button ID="btn_Delete" runat="server" Text="删除文件" OnClientClick="return confirm('确定删除文件吗?')"
                        OnClick="btn_Delete_Click" /><br />
                    <asp:TextBox ID="tb_FileNewName" runat="server" Width="300px"></asp:TextBox>
                    <asp:Button ID="btn_Rename" runat="server" Text="对文件重命名" OnClick="btn_Rename_Click" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:Button   ID="btnSearch" runat="server" Text="查找" οnclick="btnSearch_Click"
                        Width="125px" />
                </asp:View>
            </asp:MultiView>
        </div>
    </form>
</body>
</html>

---------------------------------------------------------------------------------------后台---------------------------------------------

 

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class MemberInfo_RecordManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //防止PostBack后列表信息重复添加
        if (!IsPostBack)
        {
            //初始化文件夹信息
            InitFolderInfo();
            //初始化上传限制信息
            InitUploadLimit();
            //初始化文件列表
            InitFileList();
        }
    }
    protected void ddl_FunctionList_SelectedIndexChanged(object sender, EventArgs e)
    {
        //根据下拉框所选调用合适的页面
        mvFolder.ActiveViewIndex = Convert.ToInt16(ddl_FunctionList.SelectedValue);
    }
    protected void btn_Upload_Click(object sender, EventArgs e)
    {
        //判断用户是否选择了文件
        if (FileUpload.HasFile)
        {
            //调用自定义方法判断文件类型是否符合要求
            if (IsAllowableFileType())
            {
                //调用自定义方法判断文件大小是否符合要求
                if (IsAllowableFileSize())
                {
                    //从config中读取文件上传路径
                    string strFileUploadPath = ConfigurationManager.AppSettings["FileUploadPath"].ToString();
                    //从UploadFile中读取文件名
                    string strFileName = FileUpload.FileName;
                    //组合成物理路径
                    string strFilePhysicalPath = Server.MapPath(strFileUploadPath + strFileName);
                    //保存文件
                    FileUpload.SaveAs(strFilePhysicalPath);
                    //更新文件列表框控件
                    lb_FileList.Items.Add(strFileName);
                    //更新文件夹信息
                    InitFolderInfo();
                    //调用自定义方法显示提示
                    ShowMessageBox("文件成功上传");
                }
                else
                {
                    //调用自定义方法显示提示
                    ShowMessageBox("文件大小不符合要求,请参看上传限制");
                }
            }
            else
            {
                //调用自定义方法显示提示
                ShowMessageBox("文件类型不符合要求,请参看上传限制");
            }
        }
        else
        {
            //调用自定义方法显示提示
            ShowMessageBox("请选择一个文件");
        }
    }
    protected void btn_Download_Click(object sender, EventArgs e)
    {
        //从config中读取文件上传路径
        string strFileUploadPath = ConfigurationManager.AppSettings["FileUploadPath"].ToString();
        //从列表框控件中读取选择的文件名
        string strFileName = lb_FileList.SelectedValue;
        //组合成物理路径
        string strFilePhysicalPath = Server.MapPath(strFileUploadPath + strFileName);
        //清空输出流
        Response.Clear();
        //在HTTP头中加入文件名信息
        Response.AddHeader("Content-Disposition", "attachment;FileName=" + HttpUtility.UrlEncode(strFileName, System.Text.Encoding.UTF8));
        //定义输出流MIME类型为
        Response.ContentType = "application/octet-stream";
        //从磁盘读取文件流
        System.IO.FileStream fs = System.IO.File.OpenRead(strFilePhysicalPath);
        //定义缓冲区大小
        byte[] buffer = new byte[102400];
        //第一次读取
        int i = fs.Read(buffer, 0, buffer.Length);
        //如果读取的字节大于0,则使用BinaryWrite()不断向客户端输出文件流
        while (i > 0)
        {
            Response.BinaryWrite(buffer);
            i = fs.Read(buffer, 0, buffer.Length);
        }
        //关闭磁盘文件流
        fs.Close();
        //关闭输出流
        Response.End();
    }
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        //从config中读取文件上传路径
        string strFileUploadPath = ConfigurationManager.AppSettings["FileUploadPath"].ToString();
        //从列表框控件中读取选择的文件名
        string strFileName = lb_FileList.SelectedValue;
        //组合成物理路径
        string strFilePhysicalPath = Server.MapPath(strFileUploadPath + strFileName);
        //删除文件
        System.IO.File.Delete(strFilePhysicalPath);
        //更新文件列表框控件
        lb_FileList.Items.Remove(lb_FileList.Items.FindByText(strFileName));
        //更新文件夹信息
        InitFolderInfo();
        //更新文件描述信息
        tb_FileNewName.Text = "";
        //更新重命名文本框
        lab_FileDescription.Text = "";
        //调用自定义方法显示提示
        ShowMessageBox("文件成功删除");
    }
    protected void btn_Rename_Click(object sender, EventArgs e)
    {
        //从config中读取文件上传路径
        string strFileUploadPath = ConfigurationManager.AppSettings["FileUploadPath"].ToString();
        //从列表框控件中读取选择的文件名
        string strFileName = lb_FileList.SelectedValue;
        //从重命名文本框中读取新文件名
        string strFileNewName = tb_FileNewName.Text;
        //组合成物理路径
        string strFilePhysicalPath = Server.MapPath(strFileUploadPath + strFileName);
        //组合成物理路径
        string strFileNewPhysicalPath = Server.MapPath(strFileUploadPath + strFileNewName);
        //文件重命名
        System.IO.File.Move(strFilePhysicalPath, strFileNewPhysicalPath);
        //找到文件列表框控件中的匹配项
        ListItem li = lb_FileList.Items.FindByText(strFileName);
        //修改文字
        li.Text = strFileNewName;
        //修改值
        li.Value = strFileNewName;
        //调用自定义方法显示提示
        ShowMessageBox("文件成功重命名");
    }
    protected void lb_FileList_SelectedIndexChanged(object sender, EventArgs e)
    {
        //从config中读取文件上传路径
        string strFileUploadPath = ConfigurationManager.AppSettings["FileUploadPath"].ToString();
        //从列表框控件中读取选择的文件名
        string strFileName = lb_FileList.SelectedValue;
        //组合成物理路径
        string strFilePhysicalPath = Server.MapPath(strFileUploadPath + strFileName);
        //根据物理路径实例化文件信息类
        FileInfo fi = new FileInfo(strFilePhysicalPath);
        //获得文件大小和创建时间并赋值给标签
        lab_FileDescription.Text = string.Format("文件大小:{0} 字节 上传时间:{1}", fi.Length, fi.CreationTime);
        //把文件名赋值给重命名文本框
        tb_FileNewName.Text = strFileName;
    }
    private void InitFolderInfo()
    {
        //从config中读取文件上传路径
        string strFileUploadPath = ConfigurationManager.AppSettings["FileUploadPath"].ToString();
        //判断上传文件夹是否存在
        if (!Directory.Exists(Server.MapPath(strFileUploadPath)))
            Directory.CreateDirectory(Server.MapPath(strFileUploadPath));
        //组合成物理路径
        string strFilePath = Server.MapPath(strFileUploadPath);
        //从config中读取文件夹容量限制
        double iFolderSizeLimit = Convert.ToInt32(ConfigurationManager.AppSettings["FolderSizeLimit"]);
        //声明表示文件夹已用空间的变量并赋初始值
        double iFolderCurrentSize = 0;
        //获取文件夹中所有文件
        FileInfo[] arrFiles = new DirectoryInfo(strFilePath).GetFiles();
        //累加文件大小获得已用空间值
        foreach (FileInfo fi in arrFiles)
            iFolderCurrentSize += Convert.ToInt32(fi.Length / 1024);
        //把文件夹容量和已用空间信息赋值给标签
        //lab_FolderInfo.Text = string.Format("文件夹容量限制:{0} M 已用空间:{1:f2} M", iFolderSizeLimit / 1024, iFolderCurrentSize / 1024);
    }
    private void InitUploadLimit()
    {
        //从config中读取上传文件类型限制并根据逗号分割成字符串数组
        string[] arrFileTypeLimit = ConfigurationManager.AppSettings["UpFileType"].ToString().Split('|');
        //从config中读取上传文件大小限制
        double iFileSizeLimit = Convert.ToInt32(ConfigurationManager.AppSettings["FileSizeLimit"]);
        //遍历字符串数组把所有项加入项目编号控件
        for (int i = 0; i < arrFileTypeLimit.Length; i++)
            bl_FileTypeLimit.Items.Add(arrFileTypeLimit[i].ToString());
        //把文件大小限制赋值给标签
        lab_FileSizeLimit.Text = string.Format("{0:f2} M", iFileSizeLimit / 1024);
    }
    private void InitFileList()
    {
        //从config中读取文件上传路径
        string strFileUploadPath = ConfigurationManager.AppSettings["FileUploadPath"].ToString();
        //组合成物理路径
        string strFilePath = Server.MapPath(strFileUploadPath);
        //读取文件夹下所有文件
        FileInfo[] arrFiles = new DirectoryInfo(strFilePath).GetFiles();
        //把文件名逐一添加到列表框控件控件
        foreach (FileInfo fi in arrFiles)
            lb_FileList.Items.Add(fi.Name);
    }
    private bool IsAllowableFileSize()
    {
        //从config中读取上传文件大小限制
        double iFileSizeLimit = Convert.ToInt32(ConfigurationManager.AppSettings["FileSizeLimit"]) * 1024;
        //文件大小是否超出了大小限制?
        if (iFileSizeLimit > FileUpload.PostedFile.ContentLength)
            return true;
        else
            return false;
    }
    private bool IsAllowableFileType()
    {
        //从config中读取上传文件类型限制
        string strFileTypeLimit = ConfigurationManager.AppSettings["UpFileType"].ToString();
        //当前文件扩展名是否能在这个字符串中找到?
        if (strFileTypeLimit.IndexOf(Path.GetExtension(FileUpload.FileName).ToLower()) > -1)
            return true;
        else
            return false;
    }
    private void ShowMessageBox(string strMessaage)
    {
        ClientScript.RegisterStartupScript(this.GetType(), "", string.Format("<script>alert('{0}')</script>", strMessaage));
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        lb_FileList.ClearSelection();
        if (tb_FileNewName.Text.Trim() == string.Empty) return;
        string[] arrFileTypeLimit = ConfigurationManager.AppSettings["UpFileType"].ToString().Split('|');
        bool isExist =false ;

        if (tb_FileNewName.Text.Trim().IndexOf('.') > 0)
        {

            ListItem li = lb_FileList.Items.FindByText(tb_FileNewName.Text.Trim());
            if (li != null)
            {
                li.Selected = true;
            }
            else
            {
                ShowMessageBox("该文件不存在");
            }
        }
        else
        {
            foreach (string type in arrFileTypeLimit)
            {
                ListItem li = lb_FileList.Items.FindByText(tb_FileNewName.Text.Trim()+ type);
                if (li != null)
                {
                    isExist=true ;
                    li.Selected = true;
                }
            }
        }
        if(!isExist)
        {
            ShowMessageBox("该文件不存在");
        }
    }
}

 

------------------------------------------------------------------------------webconfig----------------------------------------------------

 

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class MemberInfo_RecordManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //防止PostBack后列表信息重复添加
        if (!IsPostBack)
        {
            //初始化文件夹信息
            InitFolderInfo();
            //初始化上传限制信息
            InitUploadLimit();
            //初始化文件列表
            InitFileList();
        }
    }
    protected void ddl_FunctionList_SelectedIndexChanged(object sender, EventArgs e)
    {
        //根据下拉框所选调用合适的页面
        mvFolder.ActiveViewIndex = Convert.ToInt16(ddl_FunctionList.SelectedValue);
    }
    protected void btn_Upload_Click(object sender, EventArgs e)
    {
        //判断用户是否选择了文件
        if (FileUpload.HasFile)
        {
            //调用自定义方法判断文件类型是否符合要求
            if (IsAllowableFileType())
            {
                //调用自定义方法判断文件大小是否符合要求
                if (IsAllowableFileSize())
                {
                    //从config中读取文件上传路径
                    string strFileUploadPath = ConfigurationManager.AppSettings["FileUploadPath"].ToString();
                    //从UploadFile中读取文件名
                    string strFileName = FileUpload.FileName;
                    //组合成物理路径
                    string strFilePhysicalPath = Server.MapPath(strFileUploadPath + strFileName);
                    //保存文件
                    FileUpload.SaveAs(strFilePhysicalPath);
                    //更新文件列表框控件
                    lb_FileList.Items.Add(strFileName);
                    //更新文件夹信息
                    InitFolderInfo();
                    //调用自定义方法显示提示
                    ShowMessageBox("文件成功上传");
                }
                else
                {
                    //调用自定义方法显示提示
                    ShowMessageBox("文件大小不符合要求,请参看上传限制");
                }
            }
            else
            {
                //调用自定义方法显示提示
                ShowMessageBox("文件类型不符合要求,请参看上传限制");
            }
        }
        else
        {
            //调用自定义方法显示提示
            ShowMessageBox("请选择一个文件");
        }
    }
    protected void btn_Download_Click(object sender, EventArgs e)
    {
        //从config中读取文件上传路径
        string strFileUploadPath = ConfigurationManager.AppSettings["FileUploadPath"].ToString();
        //从列表框控件中读取选择的文件名
        string strFileName = lb_FileList.SelectedValue;
        //组合成物理路径
        string strFilePhysicalPath = Server.MapPath(strFileUploadPath + strFileName);
        //清空输出流
        Response.Clear();
        //在HTTP头中加入文件名信息
        Response.AddHeader("Content-Disposition", "attachment;FileName=" + HttpUtility.UrlEncode(strFileName, System.Text.Encoding.UTF8));
        //定义输出流MIME类型为
        Response.ContentType = "application/octet-stream";
        //从磁盘读取文件流
        System.IO.FileStream fs = System.IO.File.OpenRead(strFilePhysicalPath);
        //定义缓冲区大小
        byte[] buffer = new byte[102400];
        //第一次读取
        int i = fs.Read(buffer, 0, buffer.Length);
        //如果读取的字节大于0,则使用BinaryWrite()不断向客户端输出文件流
        while (i > 0)
        {
            Response.BinaryWrite(buffer);
            i = fs.Read(buffer, 0, buffer.Length);
        }
        //关闭磁盘文件流
        fs.Close();
        //关闭输出流
        Response.End();
    }
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        //从config中读取文件上传路径
        string strFileUploadPath = ConfigurationManager.AppSettings["FileUploadPath"].ToString();
        //从列表框控件中读取选择的文件名
        string strFileName = lb_FileList.SelectedValue;
        //组合成物理路径
        string strFilePhysicalPath = Server.MapPath(strFileUploadPath + strFileName);
        //删除文件
        System.IO.File.Delete(strFilePhysicalPath);
        //更新文件列表框控件
        lb_FileList.Items.Remove(lb_FileList.Items.FindByText(strFileName));
        //更新文件夹信息
        InitFolderInfo();
        //更新文件描述信息
        tb_FileNewName.Text = "";
        //更新重命名文本框
        lab_FileDescription.Text = "";
        //调用自定义方法显示提示
        ShowMessageBox("文件成功删除");
    }
    protected void btn_Rename_Click(object sender, EventArgs e)
    {
        //从config中读取文件上传路径
        string strFileUploadPath = ConfigurationManager.AppSettings["FileUploadPath"].ToString();
        //从列表框控件中读取选择的文件名
        string strFileName = lb_FileList.SelectedValue;
        //从重命名文本框中读取新文件名
        string strFileNewName = tb_FileNewName.Text;
        //组合成物理路径
        string strFilePhysicalPath = Server.MapPath(strFileUploadPath + strFileName);
        //组合成物理路径
        string strFileNewPhysicalPath = Server.MapPath(strFileUploadPath + strFileNewName);
        //文件重命名
        System.IO.File.Move(strFilePhysicalPath, strFileNewPhysicalPath);
        //找到文件列表框控件中的匹配项
        ListItem li = lb_FileList.Items.FindByText(strFileName);
        //修改文字
        li.Text = strFileNewName;
        //修改值
        li.Value = strFileNewName;
        //调用自定义方法显示提示
        ShowMessageBox("文件成功重命名");
    }
    protected void lb_FileList_SelectedIndexChanged(object sender, EventArgs e)
    {
        //从config中读取文件上传路径
        string strFileUploadPath = ConfigurationManager.AppSettings["FileUploadPath"].ToString();
        //从列表框控件中读取选择的文件名
        string strFileName = lb_FileList.SelectedValue;
        //组合成物理路径
        string strFilePhysicalPath = Server.MapPath(strFileUploadPath + strFileName);
        //根据物理路径实例化文件信息类
        FileInfo fi = new FileInfo(strFilePhysicalPath);
        //获得文件大小和创建时间并赋值给标签
        lab_FileDescription.Text = string.Format("文件大小:{0} 字节 上传时间:{1}", fi.Length, fi.CreationTime);
        //把文件名赋值给重命名文本框
        tb_FileNewName.Text = strFileName;
    }
    private void InitFolderInfo()
    {
        //从config中读取文件上传路径
        string strFileUploadPath = ConfigurationManager.AppSettings["FileUploadPath"].ToString();
        //判断上传文件夹是否存在
        if (!Directory.Exists(Server.MapPath(strFileUploadPath)))
            Directory.CreateDirectory(Server.MapPath(strFileUploadPath));
        //组合成物理路径
        string strFilePath = Server.MapPath(strFileUploadPath);
        //从config中读取文件夹容量限制
        double iFolderSizeLimit = Convert.ToInt32(ConfigurationManager.AppSettings["FolderSizeLimit"]);
        //声明表示文件夹已用空间的变量并赋初始值
        double iFolderCurrentSize = 0;
        //获取文件夹中所有文件
        FileInfo[] arrFiles = new DirectoryInfo(strFilePath).GetFiles();
        //累加文件大小获得已用空间值
        foreach (FileInfo fi in arrFiles)
            iFolderCurrentSize += Convert.ToInt32(fi.Length / 1024);
        //把文件夹容量和已用空间信息赋值给标签
        //lab_FolderInfo.Text = string.Format("文件夹容量限制:{0} M 已用空间:{1:f2} M", iFolderSizeLimit / 1024, iFolderCurrentSize / 1024);
    }
    private void InitUploadLimit()
    {
        //从config中读取上传文件类型限制并根据逗号分割成字符串数组
        string[] arrFileTypeLimit = ConfigurationManager.AppSettings["UpFileType"].ToString().Split('|');
        //从config中读取上传文件大小限制
        double iFileSizeLimit = Convert.ToInt32(ConfigurationManager.AppSettings["FileSizeLimit"]);
        //遍历字符串数组把所有项加入项目编号控件
        for (int i = 0; i < arrFileTypeLimit.Length; i++)
            bl_FileTypeLimit.Items.Add(arrFileTypeLimit[i].ToString());
        //把文件大小限制赋值给标签
        lab_FileSizeLimit.Text = string.Format("{0:f2} M", iFileSizeLimit / 1024);
    }
    private void InitFileList()
    {
        //从config中读取文件上传路径
        string strFileUploadPath = ConfigurationManager.AppSettings["FileUploadPath"].ToString();
        //组合成物理路径
        string strFilePath = Server.MapPath(strFileUploadPath);
        //读取文件夹下所有文件
        FileInfo[] arrFiles = new DirectoryInfo(strFilePath).GetFiles();
        //把文件名逐一添加到列表框控件控件
        foreach (FileInfo fi in arrFiles)
            lb_FileList.Items.Add(fi.Name);
    }
    private bool IsAllowableFileSize()
    {
        //从config中读取上传文件大小限制
        double iFileSizeLimit = Convert.ToInt32(ConfigurationManager.AppSettings["FileSizeLimit"]) * 1024;
        //文件大小是否超出了大小限制?
        if (iFileSizeLimit > FileUpload.PostedFile.ContentLength)
            return true;
        else
            return false;
    }
    private bool IsAllowableFileType()
    {
        //从config中读取上传文件类型限制
        string strFileTypeLimit = ConfigurationManager.AppSettings["UpFileType"].ToString();
        //当前文件扩展名是否能在这个字符串中找到?
        if (strFileTypeLimit.IndexOf(Path.GetExtension(FileUpload.FileName).ToLower()) > -1)
            return true;
        else
            return false;
    }
    private void ShowMessageBox(string strMessaage)
    {
        ClientScript.RegisterStartupScript(this.GetType(), "", string.Format("<script>alert('{0}')</script>", strMessaage));
    }
protected void btnSearch_Click(object sender, EventArgs e)
    {
        lb_FileList.ClearSelection();
        if (tb_FileNewName.Text.Trim() == string.Empty) return;
        string[] arrFileTypeLimit = ConfigurationManager.AppSettings["UpFileType"].ToString().Split('|');
        bool isExist =false ;

        if (tb_FileNewName.Text.Trim().IndexOf('.') > 0)
        {

            ListItem li = lb_FileList.Items.FindByText(tb_FileNewName.Text.Trim());
            if (li != null)
            {
                li.Selected = true;
            }
            else
            {
                ShowMessageBox("该文件不存在");
            }
        }
        else
        {
            foreach (string type in arrFileTypeLimit)
            {
                ListItem li = lb_FileList.Items.FindByText(tb_FileNewName.Text.Trim()+ type);
                if (li != null)
                {
                    isExist=true ;
                    li.Selected = true;
                }
            }
            if (!isExist)
            {
                ShowMessageBox("该文件不存在");
            }
        }

    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值