Exemplo n.º 1
0
        /// <summary>
        /// 获取目录下所有文件
        /// </summary>
        /// <param name="folderPath">目录路径</param>
        /// <param name="rootPath">根路径</param>
        /// <returns>List FileInfo</returns>
        public List <HttpFolderInfo> GetDirectories(string folderPath, string rootPath)
        {
            StringBuilder urlFormat = new StringBuilder();
            string        orderBy   = GameRequest.GetQueryString("order");

            List <HttpFolderInfo> httpFolderList = new List <HttpFolderInfo>();
            IList <FolderInfo>    folderList     = FileManager.GetDirectoryFilesListForObject(folderPath, FsoMethod.All);

            if (folderList == null || folderList.Count <= 0)
            {
                //无文件访问权限
                m_access = false;
                return(httpFolderList);
            }

            //文件信息转换
            foreach (FolderInfo folderInfo in folderList)
            {
                //删除 Builder
                urlFormat.Remove(0, urlFormat.Length);

                //目录
                if (folderInfo.FsoType == FsoMethod.Folder)
                {
                    urlFormat
                    .AppendFormat("<a href=\"Web_FilesManager.aspx?path={0}\">", Utility.UrlEncode(rootPath + "/" + folderInfo.Name))
                    .AppendFormat("<img src=\"images/attach/files/folder.gif\" alt=\"文件夹\" align=\"absmiddle\" /> {0} </a>", folderInfo.Name)
                    .AppendFormat(" <a href=\"Web_FilesManager.aspx?act=compress&amp;path={0}&amp;objfolder={1}\" onclick=\"javascript:compressMsg();\">", Utility.UrlEncode(m_folderPath), Utility.UrlEncode(folderInfo.FullName));

                    HttpFolderInfo httpFolder = new HttpFolderInfo(folderInfo.Name, Utility.UrlEncode(folderInfo.FullName), urlFormat.ToString(), "", 0, "folder", folderInfo.LastWriteTime);
                    httpFolderList.Add(httpFolder);

                    m_folderCount++;
                }

                //文件
                if (folderInfo.FsoType == FsoMethod.File)
                {
                    if (TextUtility.InArray(folderInfo.ContentType, "jpg,gif,png,bmp,psd", ",", true))
                    {
                        urlFormat
                        .AppendFormat("<a href=\"javascript:void(0);\" onclick=\"showPopWin('Web_FilesView.aspx?url=file.axd?file={0}',700,433,null);\">", Utility.UrlEncode(rootPath + "/" + folderInfo.Name))
                        .AppendFormat("<img src=\"images/attach/files/{1}.gif\" alt=\"文件\" align=\"absmiddle\" /> {0}</a>", folderInfo.Name, folderInfo.ContentType);
                    }
                    else
                    {
                        urlFormat
                        .AppendFormat("<a href=\"file.axd?file={0}\" target=\"_new\">", Utility.UrlEncode(rootPath + "/" + folderInfo.Name));


                        string logo = "default";
                        switch (folderInfo.ContentType)
                        {
                        case "mp3":
                        case "wav":
                        case "wma":
                        case "wmv":
                            logo = "mp3";
                            break;

                        case "zip":
                        case "7z":
                        case "rar":
                            logo = "zip";
                            break;
                        }

                        if (!TextUtility.EmptyTrimOrNull(folderInfo.ContentType) && TextUtility.InArray(folderInfo.ContentType, "css,dll,doc,docx,swf,txt,xls,xlsx,xml", ",", true))
                        {
                            logo = folderInfo.ContentType;
                        }

                        urlFormat.AppendFormat("<img src=\"images/attach/files/{1}.gif\" alt=\"文件\" align=\"absmiddle\" /> {0}</a>", folderInfo.Name, logo);
                    }

                    HttpFolderInfo httpFolder = new HttpFolderInfo(folderInfo.Name, Utility.UrlEncode(folderInfo.FullName), urlFormat.ToString(), folderInfo.ContentType, folderInfo.Length, "file", folderInfo.LastWriteTime);
                    httpFolderList.Add(httpFolder);

                    m_FileCount++;
                }
            }

            //具有文件访问权限
            m_access = true;

            if (!TextUtility.EmptyTrimOrNull(orderBy))
            {
                httpFolderList.Sort(new FilesComparer(orderBy));
            }

            return(httpFolderList);
        }
Exemplo n.º 2
0
        public List <HttpFolderInfo> GetDirectories(string folderPath, string rootPath)
        {
            StringBuilder         stringBuilder = new StringBuilder();
            string                queryString   = GameRequest.GetQueryString("order");
            List <HttpFolderInfo> list          = new List <HttpFolderInfo>();
            IList <FolderInfo>    directoryFilesListForObject = FileManager.GetDirectoryFilesListForObject(folderPath, FsoMethod.All);

            if (directoryFilesListForObject == null || directoryFilesListForObject.Count <= 0)
            {
                m_access = false;
                return(list);
            }
            foreach (FolderInfo item3 in directoryFilesListForObject)
            {
                stringBuilder.Remove(0, stringBuilder.Length);
                if (item3.FsoType == FsoMethod.Folder)
                {
                    stringBuilder.AppendFormat("<a href=\"Web_FilesManager.aspx?path={0}\">", Utility.UrlEncode(rootPath + "/" + item3.Name)).AppendFormat("<img src=\"images/attach/files/folder.gif\" alt=\"文件夹\" align=\"absmiddle\" /> {0} </a>", item3.Name).AppendFormat(" <a href=\"Web_FilesManager.aspx?act=compress&amp;path={0}&amp;objfolder={1}\" onclick=\"javascript:compressMsg();\">", Utility.UrlEncode(m_folderPath), Utility.UrlEncode(item3.FullName));
                    HttpFolderInfo item = new HttpFolderInfo(item3.Name, Utility.UrlEncode(item3.FullName), stringBuilder.ToString(), "", 0L, "folder", item3.LastWriteTime);
                    list.Add(item);
                    m_folderCount++;
                }
                if (item3.FsoType == FsoMethod.File)
                {
                    if (TextUtility.InArray(item3.ContentType, "jpg,gif,png,bmp,psd", ",", true))
                    {
                        stringBuilder.AppendFormat("<a href=\"javascript:void(0);\" onclick=\"showPopWin('Web_FilesView.aspx?url=file.axd?file={0}',700,433,null);\">", Utility.UrlEncode(rootPath + "/" + item3.Name)).AppendFormat("<img src=\"images/attach/files/{1}.gif\" alt=\"文件\" align=\"absmiddle\" /> {0}</a>", item3.Name, item3.ContentType);
                    }
                    else
                    {
                        stringBuilder.AppendFormat("<a href=\"file.axd?file={0}\" target=\"_new\">", Utility.UrlEncode(rootPath + "/" + item3.Name));
                        string arg = "default";
                        switch (item3.ContentType)
                        {
                        case "mp3":
                        case "wav":
                        case "wma":
                        case "wmv":
                            arg = "mp3";
                            break;

                        case "zip":
                        case "7z":
                        case "rar":
                            arg = "zip";
                            break;
                        }
                        if (!TextUtility.EmptyTrimOrNull(item3.ContentType) && TextUtility.InArray(item3.ContentType, "css,dll,doc,docx,swf,txt,xls,xlsx,xml", ",", true))
                        {
                            arg = item3.ContentType;
                        }
                        stringBuilder.AppendFormat("<img src=\"images/attach/files/{1}.gif\" alt=\"文件\" align=\"absmiddle\" /> {0}</a>", item3.Name, arg);
                    }
                    HttpFolderInfo item2 = new HttpFolderInfo(item3.Name, Utility.UrlEncode(item3.FullName), stringBuilder.ToString(), item3.ContentType, item3.Length, "file", item3.LastWriteTime);
                    list.Add(item2);
                    m_FileCount++;
                }
            }
            m_access = true;
            if (!TextUtility.EmptyTrimOrNull(queryString))
            {
                list.Sort(new FilesComparer(queryString));
            }
            return(list);
        }