20
2012
05

asp.net 中显示文件夹下的文件,并有链接地址的例子

using System;
using System.Configuration;
using System.Data.SqlClient;
using System.IO;
using System.Web;

 

   protected void Page_Load(object sender, EventArgs e)
   {
       display_files("/j1", "*.asp"); //"all" 代表全部类型的文件
   }
   public void display_files(string path,string type)
   {
       string fpath = Server.MapPath(path);
       pttt.Text = fpath;
       if (type == "all")
       {
           type = "*.*";
       }
           string[] files = Directory.GetFiles(fpath,type, SearchOption.TopDirectoryOnly);
           foreach (string file in files)
           {
               string fname = Path.GetFileNameWithoutExtension(file);
               //list1.Items.Add(file);
              // string http = Request.ServerVariables("server_name");
               Response.Write ("<a target='_blank' href=http://localhost/"+path+'/'+Path.GetFileName(file)+">"+Path.GetFileName(file)+"</a><br>");
           }
   }

 

 



版权声明:
作者:真爱无限 出处:http://www.pukuimin.top 本文为博主原创文章版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接.
« 上一篇下一篇 »

相关文章:

评论列表:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。