FileSystem.GetFiles
FileSystem.GetFiles
FileSystem.GetFiles
FileSystem.GetFiles
FileSystem.GetFiles
FileSystem.GetFiles FileSystem.GetFiles FileSystem.GetFiles FileSystem.GetFiles FileSystem.GetFiles FileSystem.GetFiles FileSystem.GetFiles FileSystem.GetFiles
FileSystem.GetFiles FileSystem.GetFiles
FileSystem.GetFiles
Go Back  Xtreme Visual Basic Talk > > > FileSystem.GetFiles


Reply
 
Thread Tools Display Modes
  #1  
Old 11-18-2006, 06:50 AM
ADO DOT NET ADO DOT NET is offline
Junior Contributor
 
Join Date: May 2006
Posts: 209
Default FileSystem.GetFiles


i am going to read all .txt files and them to my datagrid on form load:
Code:
For Each FoundFile As String In My.Computer.FileSystem.GetFiles((My.Application.Info.DirectoryPath & "\MyDir"), SearchOption.TopDirectoryOnly, "*.txt") DataGridView.Rows.Add(FoundFile) Next
but it gives me an error:
A first chance exception of type 'System.NullReferenceException' occurred in MyApp.exe
Why?
Am I somewhere wrong?
thanks all.
Reply With Quote
  #2  
Old 11-18-2006, 12:00 PM
MikeJ's Avatar
MikeJFileSystem.GetFiles MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,747
Default

Sounds like the GetFiles call is not returning anything. This seems quite kludgy to me in the first place, wouldn't it be better to get all the files, and then loop through that list? (That way, you can use a Try..Finally error trapping block...)
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
  #3  
Old 11-18-2006, 01:39 PM
ADO DOT NET ADO DOT NET is offline
Junior Contributor
 
Join Date: May 2006
Posts: 209
Default

thanks
but how to "get all the files"? "and then loop through that list"???!!!
Reply With Quote
  #4  
Old 11-18-2006, 01:52 PM
MikeJ's Avatar
MikeJFileSystem.GetFiles MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,747
Default

Actually, silly me. I didn't even notice that you were using VS2005. The method you are
using is fine; you just should include error handling to make sure that there are files in the
collection that you are searching.
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
  #5  
Old 11-18-2006, 02:08 PM
ADO DOT NET ADO DOT NET is offline
Junior Contributor
 
Join Date: May 2006
Posts: 209
Default

thanks a lot
I have attached my code! see it yourself! very strange! not wroking!!!
Attached Files
File Type: zip test.zip (15.4 KB, 4 views)
Reply With Quote
  #6  
Old 11-18-2006, 03:58 PM
MikeJ's Avatar
MikeJFileSystem.GetFiles MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,747
Default

I don't have VS2005. Are you sure that the directory you are searching has text files in
it? The error you are getting makes it sound like the collection being returned has no files
in it.
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
  #7  
Old 11-19-2006, 04:24 AM
ADO DOT NET ADO DOT NET is offline
Junior Contributor
 
Join Date: May 2006
Posts: 209
Default

Yes I am sure
That's why I attached my code.
Thank you for your help.
Reply With Quote
  #8  
Old 11-19-2006, 04:30 AM
ADO DOT NET ADO DOT NET is offline
Junior Contributor
 
Join Date: May 2006
Posts: 209
Default

so what other ways I have to do this trick?
Reply With Quote
  #9  
Old 11-20-2006, 08:17 PM
IUnknown's Avatar
IUnknown IUnknown is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Oct 2004
Location: Montréal
Posts: 1,135
Default

You should be using FileIO.SearchOption.SearchTopLevelOnly instead of SearchOption.TopDirectoryOnly.

Hope this helps!
__________________
win7 : vs 2008 : .Net 3.5
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
FileSystem.GetFiles
FileSystem.GetFiles
FileSystem.GetFiles FileSystem.GetFiles
FileSystem.GetFiles
FileSystem.GetFiles
FileSystem.GetFiles FileSystem.GetFiles FileSystem.GetFiles FileSystem.GetFiles FileSystem.GetFiles FileSystem.GetFiles FileSystem.GetFiles
FileSystem.GetFiles
FileSystem.GetFiles
 
FileSystem.GetFiles
FileSystem.GetFiles
 
-->