遍历获取目录信息

 public string GetReportList(int type, Guid _advisorid, Guid _accountid)//获取目录 //1 表示Risk 2表示Xray 0默认都显示
        {
            StringBuilder sblist = new StringBuilder();
            string RiskPath = string.Format("../Report/Lists/{0}/{1}/Risk", _advisorid, _accountid);
            string XrayPath = string.Format("../Report/Lists/{0}/{1}/Xray", _advisorid, _accountid);
            DirectoryInfo riskInfo = new DirectoryInfo(Server.MapPath(RiskPath));
            DirectoryInfo XrayInfo = new DirectoryInfo(Server.MapPath(XrayPath));
            try
            {
                foreach (FileInfo finfo in riskInfo.GetFiles())
                {
                    if (finfo.Exists && finfo.Name.Substring(finfo.Name.LastIndexOf('.') + 1) == "pdf" && type != 2)
                    {
                        sblist.Append("1:");
                        sblist.Append(finfo.Name);
                        sblist.Append(";");
                    }
                }
                foreach (FileInfo finfo in XrayInfo.GetFiles())
                {
                    if (finfo.Exists && finfo.Name.Substring(finfo.Name.LastIndexOf('.') + 1) == "pdf" && type != 1)
                    {
                        sblist.Append("2:");
                        sblist.Append(finfo.Name);
                        sblist.Append(";");
                    }
                }
                return sblist.ToString();
            }
            catch
            {
                return "";
            }
        }

你可能感兴趣的:(遍历获取目录信息)