在.net网页上的目录中显示文件 [英] display files in a directory on a .net web page

查看:136
本文介绍了在.net网页上的目录中显示文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您只是想知道在服务器上的目录中显示所有文件的好方法

并让它们可以由客户端机器打开。这些文件

会不时更改,所以不希望在链接和文件中硬编码

名称作为超链接的一部分。也想要推出一个新的页面,所以

将使用Target =" _blank"

-

Paul G

软件工程师。

解决方案

我这样做了,对我们来说效果很好。我在页面加载中创建了一个asp:Table然后

我以编程方式添加了列和行...

解析文件的目录列表。最终的结果是一个很好的

表,包含文件名,修改日期,下载链接等。另外,它是一个好主意将文件存储在外面网站并拥有

app(ASPNET用户)go get当用户点击下载

链接时的文件。我用一个查询字符串和一个单独的(下载)页面做了这个。

这样,用户不能只输入文件名并下载。

在ASP.NET 2.0中,DirectoryInfo类可以帮助您获取

文件的列表:
http://msdn2.microsoft.com/en-us/library/4cyf24ss.aspx

然后TreeView控件可以帮助你显示它们的超链接

下载它们:
http://www.asp.net/QuickStart/aspnet.../treeview.aspx

-

HTH,

Phillip Williams
http://www.societopia.net
http ://www.webswapp.com

&q UOT;保罗"写道:

您只是想知道在服务器上的目录中显示所有文件的好方法,并让它们可以选择由客户端机器打开。这些文件会不时更改,因此不希望在链接和文件名称中硬编码作为超链接的一部分。也想要启动一个新页面,以便
使用Target =" _blank"
-
Paul G
软件工程师。





在页面中添加一个datalist或datagrid,里面有一个超链接


DirectoryInfo dire = new DirectoryInfo(sVirtualFolder) );

FileInfo [] files = dire.GetFiles(" *。*"); //文件标记


DataList.DataSource = files;

DataList.DataBind();


快乐编程

" Paul"写道:

您只是想知道在服务器上的目录中显示所有文件的好方法,并让它们可以选择由客户端机器打开。这些文件会不时更改,因此不希望在链接和文件名称中硬编码作为超链接的一部分。也想要启动一个新页面,以便
使用Target =" _blank"
-
Paul G
软件工程师。



Hi just wondering a good way to display all files in a directory on a server
and have them selectable to be opened by the client machine. These files
change from time to time so would not want to hard code in the link and file
names as part of the hyperlink. Also would want to launch a new page so
would use the Target="_blank"
--
Paul G
Software engineer.

解决方案

I did this, and it worked well for us. I created an asp:Table and then
in the page load I programmatically added columns and rows...after
parsing a directory listing of the files. The end result is a nice
table with the file name, date modified, download link, etc. Also, it
is a good idea to store the files outside of the website and have the
app (ASPNET user) "go get" the file when the user clicks the download
link. I did this with a querystring and a separate (download) page.
That way, users cannot just type the file name and download.


In ASP.NET 2.0 the DirectoryInfo class can help you get a listing of your
files:
http://msdn2.microsoft.com/en-us/library/4cyf24ss.aspx

Then the TreeView control can help you display them with hyperlinks for
downloading them:
http://www.asp.net/QuickStart/aspnet.../treeview.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Paul" wrote:

Hi just wondering a good way to display all files in a directory on a server
and have them selectable to be opened by the client machine. These files
change from time to time so would not want to hard code in the link and file
names as part of the hyperlink. Also would want to launch a new page so
would use the Target="_blank"
--
Paul G
Software engineer.




Add a datalist, or datagrid in the page with a hyperlink inside

DirectoryInfo dire = new DirectoryInfo(sVirtualFolder);
FileInfo[] files = dire.GetFiles("*.*"); // mark of files

DataList.DataSource = files;
DataList.DataBind();

Happy programming
"Paul" wrote:

Hi just wondering a good way to display all files in a directory on a server
and have them selectable to be opened by the client machine. These files
change from time to time so would not want to hard code in the link and file
names as part of the hyperlink. Also would want to launch a new page so
would use the Target="_blank"
--
Paul G
Software engineer.



这篇关于在.net网页上的目录中显示文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆