Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

Is it possible to display the files in gridview from the folder?Not from the database.If yes,kindly tell me how?

Thanks,
Posted

Hi,

yeah you can display file names in data control

Here I'm providing some code for reading list of files in directory

ASP.NET
<asp:DataList ID="DataList1" runat="server" onitemcommand="DataList1_ItemCommand" Width ="60%"
       >
     <HeaderTemplate >
       <table width="100%" align="center">
         <tr>
           <td>List of Items</td>
         </tr>

     </HeaderTemplate>
     <itemtemplate>
          <tr>
           <td>

               <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl ="~/Default13.aspx"  > <%#Container.DataItem %>

           </td>
         </tr>
     </itemtemplate>
     <footertemplate>
         </footertemplate></table>


And code behind file contains following code

C#
            DirectoryInfo dinfo = new DirectoryInfo(Server.MapPath ("~/Scripts"));
            FileInfo[] finfo = dinfo.GetFiles();
            List<string> str = new List<string>();
            foreach (var g in finfo)
            {
                str.Add(g.FullName);
            }
          
          
           

            DataList1.DataSource = str;
            DataList1.DataBind();

</string></string>


In the above code it displays all the files existing in scripts folder

I hope you understood what I said

All the Best
 
Share this answer
 
v2
Comments
sreenathpktr 28-Sep-11 9:24am    
Thank you sir...This is very useful..
Muralikrishna8811 28-Sep-11 9:25am    
u r welcome
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900