HTMLimputFile control, can't make browse only.

G

Garry Freemyer

I've been fighting this for three months, I'm in tears! Please help if you
can!

Problem .... Users need to be able to upload multiple files.
Solution: Created a control that dynamically creates html input controls,
and a description text box as well equal to the number of files they want to
upload at a time.

Things work except its flakey ... sometimes it pretends nothing was uploaded
and I got to refresh the page many times to get the files to show.

Showstopper 1: If the user types stuff in the file path instead of using the
browse button, the files will not start uploading if the content is not a
valid path to a file.

Solution tried Set the attribute of the control to readonly. Failed because
it won't browse - click on the browse button and nothing happens.

I tried validation, using a RegularExpressionValidator and it works if I
demand that the value in the text box part of the control be an email and
use one of my regexes for that it works fine, but if I change it to the
regex below, it appears to accept everything!

I'm out of time and I'm out of ideas.

Here is my regex .....

Public Const RegexForFileUpload =
"\b((?#drive)[a-z]):\\((?#folder)[^/:*?""<>|\r\n]*\\)?((?#file)[^\\/:*?""<>|\r\n]*)"


Here is the function that creates the dynamic file upload stuff ...

Private Sub DynamicallyGenerateUpload()

Dim table As System.Web.UI.WebControls.Table =
CType(FindControl("TestTable"), Table)

Dim i As Integer

For i = 1 To PhotoCount

Dim tableRow As TableRow = New TableRow

Dim PreListingCheckBox As New CheckBox

PreListingCheckBox.Text = "This is a PRE-LISTING IMAGE"

Dim htmlFile As HtmlInputFile = New HtmlInputFile

htmlFile.MaxLength = consts.MaxImageUploadSize

htmlFile.Accept = "image/*" ' accept any image type file.

htmlFile.ID = "htmlFile" & i

'htmlFile.Attributes.Add("ReadOnly", "true")

Dim tableCell As New TableCell

tableCell.Controls.Add(htmlFile)

' Add in a regex validator.

Dim rev As RegularExpressionValidator = New RegularExpressionValidator

rev.ControlToValidate = htmlFile.ClientID

rev.Display = ValidatorDisplay.Dynamic

rev.Enabled = True

rev.Text = "Invalid Path"

rev.ErrorMessage = "Invalid Path"

rev.ValidationExpression = consts.RegexForFileUpload

rev.EnableClientScript = True

rev.Visible = True

rev.ID = "rev" & i

tableCell.Controls.Add(rev)

' End of regex validator

' tableCell.Controls.Add(labelWarning)

Dim labelDesc As Label = New Label

labelDesc.Text = "Description:"

labelDesc.BackColor = Color.White

tableCell.Controls.Add(labelDesc)

Dim txtDesc As TextBox = New TextBox

txtDesc.Style.Item("Width") = "300px"

txtDesc.Style.Item("Height") = "30px"

txtDesc.TextMode = TextBoxMode.MultiLine

txtDesc.BackColor = Color.Yellow

txtDesc.ID = "txtDesc" & i

'txtDesc.Attributes.Add("CausesValidation", "true")

tableCell.Controls.Add(txtDesc)

If ShowPreListingCheckBox Then

tableCell.Controls.Add(PreListingCheckBox)

End If

' Row

'Dim radSpell As Telerik.WebControls.RadSpell = New
Telerik.WebControls.RadSpell

'radSpell.ID = "radSpell" & i

'radSpell.IsClientID = False

'radSpell.ControlToCheck = txtDesc.ID

'radSpell.Width = System.Web.UI.WebControls.Unit.Pixel(80)

'tableCell.Controls.Add(radSpell)

tableRow.Controls.Add(tableCell)

table.Controls.Add(tableRow)

Next i

End Sub
 
J

Jesse Houwing

Hello Garry,

The regex you are using contains constructs that are not supported in cliet
side code. But you have set the clientside valdiation option to true. Hence
things won't work.

For example the (?#...) construction is unsupported.

I'd try to solve this using a serverside validator. Just check if the filesize
is 0, if so display an error message for those files that failed. Just process
the files that did work.

Jesse

I've been fighting this for three months, I'm in tears! Please help if
you can!

Problem .... Users need to be able to upload multiple files.
Solution: Created a control that dynamically creates html input
controls,
and a description text box as well equal to the number of files they
want to
upload at a time.
Things work except its flakey ... sometimes it pretends nothing was
uploaded and I got to refresh the page many times to get the files to
show.

Showstopper 1: If the user types stuff in the file path instead of
using the browse button, the files will not start uploading if the
content is not a valid path to a file.

Solution tried Set the attribute of the control to readonly. Failed
because it won't browse - click on the browse button and nothing
happens.

I tried validation, using a RegularExpressionValidator and it works if
I demand that the value in the text box part of the control be an
email and use one of my regexes for that it works fine, but if I
change it to the regex below, it appears to accept everything!

I'm out of time and I'm out of ideas.

Here is my regex .....

Public Const RegexForFileUpload =
"\b((?#drive)[a-z]):\\((?#folder)[^/:*?""<>|\r\n]*\\)?((?#file)[^\\/:*
?""<>|\r\n]*)"

Here is the function that creates the dynamic file upload stuff ...

Private Sub DynamicallyGenerateUpload()

Dim table As System.Web.UI.WebControls.Table =
CType(FindControl("TestTable"), Table)

Dim i As Integer

For i = 1 To PhotoCount

Dim tableRow As TableRow = New TableRow

Dim PreListingCheckBox As New CheckBox

PreListingCheckBox.Text = "This is a PRE-LISTING IMAGE"

Dim htmlFile As HtmlInputFile = New HtmlInputFile

htmlFile.MaxLength = consts.MaxImageUploadSize

htmlFile.Accept = "image/*" ' accept any image type file.

htmlFile.ID = "htmlFile" & i

'htmlFile.Attributes.Add("ReadOnly", "true")

Dim tableCell As New TableCell

tableCell.Controls.Add(htmlFile)

' Add in a regex validator.

Dim rev As RegularExpressionValidator = New RegularExpressionValidator

rev.ControlToValidate = htmlFile.ClientID

rev.Display = ValidatorDisplay.Dynamic

rev.Enabled = True

rev.Text = "Invalid Path"

rev.ErrorMessage = "Invalid Path"

rev.ValidationExpression = consts.RegexForFileUpload

rev.EnableClientScript = True

rev.Visible = True

rev.ID = "rev" & i

tableCell.Controls.Add(rev)

' End of regex validator

' tableCell.Controls.Add(labelWarning)

Dim labelDesc As Label = New Label

labelDesc.Text = "Description:"

labelDesc.BackColor = Color.White

tableCell.Controls.Add(labelDesc)

Dim txtDesc As TextBox = New TextBox

txtDesc.Style.Item("Width") = "300px"

txtDesc.Style.Item("Height") = "30px"

txtDesc.TextMode = TextBoxMode.MultiLine

txtDesc.BackColor = Color.Yellow

txtDesc.ID = "txtDesc" & i

'txtDesc.Attributes.Add("CausesValidation", "true")

tableCell.Controls.Add(txtDesc)

If ShowPreListingCheckBox Then

tableCell.Controls.Add(PreListingCheckBox)

End If

' Row

'Dim radSpell As Telerik.WebControls.RadSpell = New
Telerik.WebControls.RadSpell

'radSpell.ID = "radSpell" & i

'radSpell.IsClientID = False

'radSpell.ControlToCheck = txtDesc.ID

'radSpell.Width = System.Web.UI.WebControls.Unit.Pixel(80)

'tableCell.Controls.Add(radSpell)

tableRow.Controls.Add(tableCell)

table.Controls.Add(tableRow)

Next i

End Sub
 

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

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top