Why doesnt this work?

  • Thread starter Thread starter Showjumper
  • Start date Start date
S

Showjumper

I am trying to add allowed file extensions to an arraylist, as follows. I
really want it so that the values of files will be a comma serparted string
that i set in the property window. This is an upload server control and i
then check the _Allowedfiles arraylist to see if it has the extension and
then upload or not. Right now only the first extnesion gets added - in this
case .jpg, while.gif isnt added. What am i doung wrong?

Thanks...
Ashok
Dim files As String = ".jpg, .gif "

Dim fileArray() As String = files.Split(",")

Dim k As String

For Each k In fileArray

_AllowedFiles.Add(fileArray(i))

Next
 
Showjumper said:
I am trying to add allowed file extensions to an arraylist, as follows. I
really want it so that the values of files will be a comma serparted string
that i set in the property window. This is an upload server control and i
then check the _Allowedfiles arraylist to see if it has the extension and
then upload or not. Right now only the first extnesion gets added - in this
case .jpg, while.gif isnt added. What am i doung wrong?

Thanks...
Ashok
Dim files As String = ".jpg, .gif "

Dim fileArray() As String = files.Split(",")

Dim k As String

For Each k In fileArray

_AllowedFiles.Add(fileArray(i))

Next

You're iterating through fileArray using "For Each" but then you call
_Allowedfiles.Add() using an index that has nothing to do with the loop.

change:

_AllowedFiles.Add(fileArray(i))

To:

_AllowedFiles.Add( k.Trim())

Note that I added a call to Trim() becuase the Split() will leave the
file extentions having leading and/or trailing space characters.
 
Thanks Mike. That was it.
mikeb said:
You're iterating through fileArray using "For Each" but then you call
_Allowedfiles.Add() using an index that has nothing to do with the loop.

change:

_AllowedFiles.Add(fileArray(i))

To:

_AllowedFiles.Add( k.Trim())

Note that I added a call to Trim() becuase the Split() will leave the
file extentions having leading and/or trailing space characters.
 
Back
Top