Why doesnt this work?

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
 
M

mikeb

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.
 
S

Showjumper

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.
 

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

Top