网站下载文件管理的逻辑代码

2017-03-04 08:11:53  访问(3346) 赞(0) 踩(0)


相关下载:AdmHPlus.zip     

  •  
        protected string NavButton = "";
    
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected string GetRootDirName()
        {
    
            return Request.PhysicalApplicationPath + "Soft\\";
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dir"></param>
        /// <returns></returns>
        protected string GetCurDir(string dir)
        {
            string rootDir = GetRootDirName();
    
            return rootDir + dir;
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dir"></param>
        /// <returns></returns>
        protected string ToDir(string dir)
        {
    
            if (dir == null || dir.Length == 0)
                return "";
    
            dir = dir.Trim();
    
            if (dir.Length == 0)
                return "";
    
            if (dir.StartsWith("/") || dir.StartsWith("\\"))
                dir = dir.Substring(1);
    
            if (dir.EndsWith("/") || dir.EndsWith("\\"))
            {
                dir = dir.Substring(0, dir.Length - 1);
            }
    
            return dir;
        }
    
        /// <summary>
        /// 数据绑定
        /// </summary>
        protected void DataBindTheControls()
        {
            string dir = Request.QueryString["dir"];
    
            if (dir != null)
            {
                dir = HttpUtility.UrlDecode(dir);
            }
    
            string newDir = ToDir(dir);
    
            List<FileSystemInfo> theList = FileSystemInfoListGet(newDir);
    
            mainRepeater.DataSource = theList;
            mainRepeater.DataBind();
    
            BuildNav(newDir);
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="strDirName"></param>
        /// <param name="strTitle"></param>
        /// <param name="strName"></param>
        /// <returns></returns>
        protected string BuildButtonItem
            (
                string strDirName,
                string strTitle,
                string strName
            )
        {
            string hrefUrl = "";
    
            if (strDirName == null || strDirName.Length == 0)
            {
                hrefUrl = "default.aspx";
            }
            else
            {
                hrefUrl = "default.aspx?dir=" + Server.UrlEncode(strDirName);
            }
    
            string hrefHtml = "<a  class=\"btn btn-white btn-sm\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"" + StringConvertQuot(strTitle) + "\" href=\"" + hrefUrl + "\">" + strName + "</a>";
    
            // return "<button>" + hrefHtml + "</button>";
            return hrefHtml;
        }
    
    
        protected void BuildNav(string newDir)
        {
            if (newDir == null || newDir.Length == 0)
            {
                return;
            }
    
            newDir = newDir.Replace("/", "\\");
    
            string[] sA = newDir.Split('\\');
    
            int iLen = sA.Length;
            string sItem = null;
            StringBuilder sb = new StringBuilder();
    
    
            sItem = BuildButtonItem("", "根目录", "根目录");
            sb.Append(sItem);
    
    
            string curDir = "";
    
            for (int i = 0; i < iLen; ++i)
            {
                if (curDir.Length == 0)
                    curDir = sA[i];
                else
                    curDir += "\\" + sA[i];
    
                sItem = BuildButtonItem(curDir, curDir, sA[i]);
    
                sb.Append(sItem);
            }
    
            NavButton = sb.ToString();
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected List<FileSystemInfo> FileSystemInfoListGet(string newDir)
        {
            List<FileSystemInfo> theList = new List<FileSystemInfo>();
    
    
    
            string fullDir = GetCurDir(newDir);
    
            DirectoryInfo dirInfo = new DirectoryInfo(fullDir);
    
            if (!dirInfo.Exists)
                return theList;
    
            DirectoryInfo[] dA = dirInfo.GetDirectories();
    
            foreach (DirectoryInfo di in dA)
            {
                theList.Add(di);
            }
    
            FileInfo[] fA = dirInfo.GetFiles();
    
            foreach (FileInfo fi in fA)
            {
                theList.Add(fi);
            }
    
            return theList;
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        protected string GetTrCssClass(object o)
        {
            if (o is DirectoryInfo)
                return "unread";
    
            return "read";
        }
    
    

  • 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="idx"></param>
        /// <returns></returns>
        public string GetLengthName(int idx)
        {
            switch (idx)
            {
                case 0:
                    return "";
                case 1:
                    return "KB";
                case 2:
                    return "MB";
                case 3:
                    return "GB";
                case 4:
                    return "TB";
                default:
                    return "TB";
            }
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        protected string GetFileSize(object o)
        {
            if (o is DirectoryInfo)
                return "&nbsp;";
    
            FileInfo fi = o as FileInfo;
    
            if (fi == null)
                return "&nbsp;";
    
            double dLen = (double)fi.Length;
    
            int idx = 0;
    
            while (idx < 5)
            {
                if (dLen < 1024)
                    break;
    
                ++idx;
                dLen = dLen / 1024;
            }
    
            dLen = Math.Round(dLen, 2);
    
            return dLen.ToString() + GetLengthName(idx);
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected string GetHref(object o)
        {
            if (o is DirectoryInfo)
                return GetDirHref(o as DirectoryInfo);
    
            return GetFileHref(o as FileInfo);
    
        }
    
     
    
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected string GetDirHref(DirectoryInfo info)
        {
            if (info == null)
                return "&nbsp;";
    
            string fullName = info.FullName;
            string rootName = GetRootDirName();
    
            string subName = fullName.Substring(rootName.Length);
    
            string hrefUrl = "default.aspx?dir=" + Server.UrlEncode(subName);
    
            return "<a href=\"" + StringConvertQuot(hrefUrl) + "\" title=\"" + StringConvertQuot(subName) + "\" >" + info.Name + "</a>";
    
        }
    
    
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected string GetFileHref(FileInfo info)
        {
            if (info == null)
                return "&nbsp;";
    
            string fullName = info.FullName;
            string rootName = Request.PhysicalApplicationPath;
    
            string subName = fullName.Substring(rootName.Length);
    
            string hrefUrl = strPhyPath + "/" + subName.Replace("\\", "/");
    
            return "<a href=\"" + StringConvertQuot(hrefUrl) + "\" title=\"" + StringConvertQuot(subName) + "\" >" + info.Name + "</a>";
    
        }
     
    
  • <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="WebForms_AdmHPlus_Files_DownLoad_Default" %>
    
    
    <!DOCTYPE html>
    <html>
    
    <head>
    
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    
        <title>软件下载</title>
        <meta name="keywords" content="软件下载">
        <meta name="description" content="软件下载">
    
        <link href="<%=HPlusLibPhyPath %>/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
        <link href="<%=HPlusLibPhyPath %>/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
        <link href="<%=HPlusLibPhyPath %>/css/plugins/iCheck/custom.css" rel="stylesheet">
        <link href="<%=HPlusLibPhyPath %>/css/animate.min.css" rel="stylesheet">
        <link href="<%=HPlusLibPhyPath %>/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    
        
        <script type="text/javascript">
            var rootPhyPath = "<%=strPhyPath%>"; 
    
        </script>
    
    </head>
    
    <body class="gray-bg">
        <div class="wrapper wrapper-content">
            <div class="row">
    
                <div class="col-sm-12 animated fadeInRight">
                    <div class="mail-box-header">
                        <h2><a href="default.aspx">软件下载</a>
                        </h2>
                        <div class="mail-tools tooltip-demo m-t-md">
                            <%=NavButton %>
                        </div>
                    </div>
                    <div class="mail-box">
    
                        <table class="table table-hover table-mail">
                            <tbody>
                                <asp:Repeater ID="mainRepeater" runat="server">
                                    <ItemTemplate>
                                        <tr class="<%#GetTrCssClass(Container.DataItem) %>">
                                            <td class="check-mail">
                                                <input type="checkbox" class="i-checks">
                                            </td>
                                            <td class="mail-subject">
                                                <%#GetHref(Container.DataItem) %>
                                            </td>
                                            <td class="text-right"><%#Eval("LastWriteTime") %>
                                            </td>
                                            <td class="text-right"><%#GetFileSize(Container.DataItem) %></td>
                                        </tr>
                                    </ItemTemplate>
                                </asp:Repeater>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <script src="<%=HPlusLibPhyPath %>/js/jquery.min.js?v=2.1.4"></script>
        <script src="<%=HPlusLibPhyPath %>/js/bootstrap.min.js?v=3.3.6"></script>
        <script src="<%=HPlusLibPhyPath %>/js/content.min.js?v=1.0.0"></script>
        <script src="<%=HPlusLibPhyPath %>/js/plugins/iCheck/icheck.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function ()
            { $(".i-checks").iCheck({ checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green", }) });
        </script>
    
    </body>
    
    </html>
    
    

标签:网站下载文件管理的逻辑代码 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)
 
  ┈全部┈  
 
(显示默认分类)