开发者

Displaying desired files only in asp.net

  DirectoryInfo Dir = new DirectoryInfo(Server.MapPath(strheadlinesid));
  FileInfo[] FileList = Dir.GetFiles("*.txt", SearchOption.AllDirectories);

In the Place of *.txt ,I want to mention some more file extensions how can I do that.

I used another type of approach but I have a small problem in it when I use the FI as hyperlink it's giving total path.but I want to print only the file name not fullpath.

   string supportedExtensions = "*.jpg,*.gif,*.png,*.bmp,*.jpe,*.jpeg,*.wmf,*.emf,*.xbm,*.ico,*.eps,*.tif,*.tiff,*.g01,*.开发者_如何学JAVAg02,*.g03,*.g04,*.g05,*.g06,*.g07,*.g08";

   foreach (string FI in Directory.GetFiles(Server.MapPath(strheadlinesid), "*.*", SearchOption.AllDirectories).Where(s => supportedExtensions.Contains(Path.GetExtension(s).ToLower())))
   {

       Response.Write("<td><a href= view5.aspx?file=" + strheadlinesid + "\\" + FI + " target=_self;> " +
           FI + "</a></td>");

   }


Try

string fileFilter = "*.wma,*.jpeg,*.txt";
            string[] fileExt = fileFilter.Split(',');
            FileInfo[] fileInfo = null;
            DirectoryInfo dir = new DirectoryInfo("D:\\Test");
            List<FileInfo[]> listFileInfo = new List<FileInfo[]>();

            foreach (string strVar in fileExt)
            {
                fileInfo = dir.GetFiles(strVar, SearchOption.AllDirectories);
                listFileInfo.Add(fileInfo);
            }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜