石家庄建站平台

十年经验 优惠价格 贴心服务

服务热线 15383239821

一个简单的asp.net 管理Web站点文件的页面程序

发布时间:2013-10-30    来源:

先看效果

 

WebFileManager

 代码如下
<!--
Author: 张浩华
DateTime: 2012-07-06 03:25
-----------------------------------
管理Web站点下文件的页面程序。
提供上传、重命名、删除、创建文件夹、下载等功能。
-->
<%@ Page Language="C#" %>

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

<script runat="server">
    string Msg = string.Empty;
    static string _CURRENT_PATH = "";
   
    protected void Page_Load(object sender, EventArgs e)
    {
        InitFiles();
        switch (Request["action"])
        {
            case "Root":
                Root();
                break;
            case "Back":
                Back();
                break;
            case "Open":
                Open(Request["FileName"]);
                break;
            case "Delete":
                Delete(Request["FileName"]);
                break;
        }
    }

    protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (fuFile.HasFile)
        {
            string currentPath = GetCurrentPath();
            string fileName = fuFile.FileName;
            if (rbCover.Checked)
            {
            }
            else if (rbRename.Checked)
            {
                while (System.IO.File.Exists(currentPath + fileName))
                {
                    fileName = "new_" + fileName;
                }
            }
            fuFile.SaveAs(currentPath + fileName);
        }
        InitFiles();
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        string oleFileName = hfOldName.Value;
        string newFileName = txtNewName.Text;
        if (string.IsNullOrEmpty(newFileName))
        {
            Msg = "The file name can't for empty !";
            return;
        }
       
        string currentPath = GetCurrentPath();
        string oldPath = currentPath + oleFileName;
        string newPath = currentPath + newFileName;
        if (IsFile(oldPath))
        {
            if (System.IO.File.Exists(newPath))
            {
                Msg = "The file name repeated, please reset.";
                return;
            }
            System.IO.File.Move(oldPath, newPath);
        }
        else
        {
            if (string.IsNullOrEmpty(oleFileName))
            {
                System.IO.Directory.CreateDirectory(newPath);
            }
            else
            {
                System.IO.Directory.Move(oldPath, newPath);
            }
        }
        InitFiles();
    }

    private void Back()
    {
        string path = GetCurrentPath();
        string parent = new System.IO.DirectoryInfo(path).Parent.FullName + "\";
        if (parent.IndexOf(Server.MapPath("~/")) >= 0)
        {
            _CURRENT_PATH = parent;
        }
        Response.Redirect(Request.Url.AbsolutePath);       
    }
   
    private void Delete(s

还没开展互联网业务? 马上开始

关注多多建站公众号
扫码加好友