adding items to an arrayList

D

Darrel

I'm trying to grab the files in a directory and add each one to an array
list. Thist is what I have:

1 Dim filesToUpload() As ArrayList
2 Dim batchFiles As String() =
System.IO.Directory.GetFiles(Server.MapPath("/batchupload/"))
3 Dim arrayCount As Integer = 0
4 For Each fileName As String In batchFiles
5 filesToUpload(arrayCount).Add(fileName)
6 arrayCount = arrayCount + 1
7 Next

But it's giving me an 'Object reference not set to an instance of an
object.' error on line 5. This is code from a tutorial (though modified to
use an arrayList rather than rediming an array) so I'm assuming I goofed up
my syntax somewhere.

-Darrel
 
S

sloan

I think you need

dim files as ArrayList
files = new ArrayList

You should put in

Option Explicit 'On
Option Strict On

at the top of your code. you'll help yourself out a little bit by now
declaring objects correctly in vb.net
 
D

Darrel

I think you need
dim files as ArrayList
files = new ArrayList

THanks, sloan. Yes, I NEED to get in the habit of using the option
explicit/strict feature.

-Darrel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top