Browse files in specified directory on server.
I want it see all the files in the specified directory, How can I do that in asp.net.
Following script will display all file in directory. Run sample code<%@ Page Language="C#" %>
<%@ import Namespace="System.IO" %>
<script runat="server">
string vpath = "/Images/Standard";
void Page_Load(Object sender,EventArgs e){
FileRepeater.DataSource = new DirectoryInfo(Server.MapPath(vpath)).GetFiles();
FileRepeater.DataBind();
}
</script>
<html>
<head>
</head>
<body>
<form runat="Server">
<asp:Repeater runat="server" Id="FileRepeater">
<ItemTemplate>
<div>
<a href="<%#vpath + "/" + DataBinder.Eval(Container.DataItem,"Name")%>">
<%# DataBinder.Eval(Container.DataItem,"Name") %>
</a>
</div>
</ItemTemplate>
</asp:Repeater>
</form>
</body>
</html>
|
 My name is Jigar Desai I share my ideas on this site and you can contact me by filling contact form.
|