Login    
 
 
 
 
Text/HTML
  
You are here :: Blogs Saturday, May 19, 2012

Search
Note: This uses the internal blog search engine. The Google search engine is also available at the top of the page.
  
Disclaimer

Please review the site disclaimer before downloading or using content found on this site

  
Categories
  
DEVSHED Blog
As always, I welcome your comments!
Jan 12

Written by: Steve Gray
1/12/2011 10:42 AM  RssIcon

Recently I needed to populate a grid with the all the files in a folder and link to them. Here is the code to do the work

Code Snippet
  1. Sub binddata()
  2.     Dim strBaseFolder As String = Server.MapPath("\bulletins")
  3.  
  4.     Dim oDT As New DataTable
  5.  
  6.     'create column 1
  7.     Dim fileName As DataColumn = New DataColumn("fileName", System.Type.GetType("System.String"))
  8.     oDT.Columns.Add(fileName)
  9.  
  10.     'create column 2
  11.     Dim fullPath As DataColumn = New DataColumn("fullPath", System.Type.GetType("System.String"))
  12.     oDT.Columns.Add(fullPath)
  13.  
  14.     'create column 3
  15.     Dim relPath As DataColumn = New DataColumn("relPath", System.Type.GetType("System.String"))
  16.     oDT.Columns.Add(relPath)
  17.  
  18.     For Each s As String In Directory.GetFiles(strBaseFolder)
  19.         'create the rows
  20.         Dim oRow As DataRow
  21.         oRow = oDT.NewRow
  22.         oRow("fileName") = Path.GetFileName(s)
  23.         oRow("fullPath") = s
  24.         oRow("relPath") = "~/bulletins/" & Path.GetFileName(s)
  25.         oDT.Rows.Add(oRow)
  26.     Next s
  27.  
  28.     Dim oDV As DataView = oDT.DefaultView
  29.     oDV.Sort = "fileName desc"
  30.  
  31.     Me.Grid1.DataSource = oDV
  32.     Me.Grid1.DataBind()
  33.  
  34. End Sub

Tags:
Categories:
As always, I welcome your comments!
  
 
 
Home | Products | Blogs | Contact Us | Links | God's Plan
Privacy Statement | Terms Of Use
 
Copyright 2011 by Devshed.us