lorena Posted April 10, 2006 Posted April 10, 2006 I have several pages that are supposed to list all the files that are .pdf files in a certain directory. For some reason, the page displays one less file than is actually in the directory. What am I doing wrong? Here is my code: Sub BindGrid() Dim dirInfo As New System.IO.DirectoryInfo(Server.MapPath("/p1/Docs/JobOrders/6500 - 6599")) Dim arrFileInfo As Array Dim filesInfo As System.IO.FileInfo Dim filesTable As New DataTable() Dim drFiles As DataRow Dim dvFiles As DataView Dim ofn, ext As String Dim charCt, fileCt As Integer filesTable.Columns.Add("Name", Type.GetType("System.String")) filesTable.Columns.Add("LastWriteTime", Type.GetType("System.DateTime")) arrFileInfo = dirInfo.GetFiles("*.pdf") fileCt = 0 For Each filesInfo In arrFileInfo drFiles = filesTable.NewRow() ofn = filesInfo.Name ext = Right(ofn, 4) charCt = InStr(ofn, ".") - 1 ofn = Mid(ofn, 1, charCt) drFiles("Name") = ofn drFiles("LastWriteTime") = filesInfo.LastWriteTime filesTable.Rows.Add(drFiles) fileCt += 1 Next filesInfo dvFiles = filesTable.DefaultView If SortAscending then dvFiles.Sort = SortExpression & " ASC" Else dvFiles.Sort = SortExpression & " DESC" End If dgFiles.DataSource = dvFiles dgFiles.DataBind() If fileCt < 51 Then GridPagerVisibility(False) Else GridPagerVisibility(True) End If lblyourmom.text = fileCt End Sub Quote
lorena Posted April 11, 2006 Author Posted April 11, 2006 Never mind - page works fine. One of the folks entering the files into the directory was putting periods in the filenames. Quote
Cags Posted April 11, 2006 Posted April 11, 2006 Using LastIndexOf to get the charCt should solve that problem. Or alternatively you could use the System.IO.Path.GetFileNameWithoutExtension() method. Quote Anybody looking for a graduate programmer (Midlands, England)?
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.