S
Sean Carey
I converted a C# Upload app to VB.NET and am down to one error and was
hoping someone could help me with te error. I would greatly appreciate
help from anyone.
Here is the error:
c:\inetpub\wwwroot\admin\filemanager.aspx.vb(76): Expression is of
type 'System.Web.UI.HtmlControls.HtmlInputFile', which is not a
collection type.
Here is the code:
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Xml
Namespace webchange
Public Class attachme
Inherits System.Web.UI.Page
Protected ListBox1 As System.Web.UI.WebControls.ListBox
Protected AddFile As System.Web.UI.WebControls.Button
Protected RemvFile As System.Web.UI.WebControls.Button
Protected FindFile As System.Web.UI.HtmlControls.HtmlInputFile
Protected Upload As System.Web.UI.HtmlControls.HtmlInputButton
Protected Label1 As System.Web.UI.WebControls.Label
Public files As ArrayList = New ArrayList
Public Shared hif As ArrayList = New ArrayList
Protected Image1 As System.Web.UI.WebControls.Image
Public filesUploaded As Integer = 0
Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
End Sub
Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
InitializeComponent()
MyBase.OnInit(e)
End Sub
Private Sub InitializeComponent()
AddHandler Me.AddFile.Click, AddressOf Me.AddFile_Click
AddHandler Me.RemvFile.Click, AddressOf Me.RemvFile_Click
AddHandler Me.Upload.ServerClick, AddressOf
Me.Upload_ServerClick
AddHandler Me.Load, AddressOf Me.Page_Load
End Sub
Private Sub AddFile_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
If Page.IsPostBack = True Then
hif.Add(FindFile)
ListBox1.Items.Add(FindFile.PostedFile.FileName)
Else
End If
End Sub
Private Sub RemvFile_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
If Not (ListBox1.Items.Count = 0) Then
hif.RemoveAt(ListBox1.SelectedIndex)
ListBox1.Items.Remove(ListBox1.SelectedItem.Text)
End If
End Sub
Public Sub Upload_ServerClick(ByVal sender As Object, ByVal e
As System.EventArgs)
Dim id As String = Request.QueryString("id")
Dim ad As String = Request.QueryString("ad")
Dim folder As String = Request.QueryString("Folder")
Dim baseLocation As String = ""
Dim status As String = ""
If folder = "prod" Then
baseLocation = "C:\" + ad + "_" + id + "\" + ad + "_"
+ id + "\"
End If
If folder = "pim" Then
baseLocation = "C:\" + ad + "_" + id + "\" + ad + "_"
+ id + "_pimfiles\"
End If
If folder = "source" Then
baseLocation = "C:\" + ad + "_" + id + "\" + ad + "_"
+ id + "_source\"
End If
If (ListBox1.Items.Count = 0) AndAlso (filesUploaded = 0)
Then
Label1.Text = "Error - a file name must be specified."
Return
Else
For Each HIF As
System.Web.UI.HtmlControls.HtmlInputFile In HIF
Try
Dim fn As String =
System.IO.Path.GetFileName(HIF.PostedFile.FileName)
HIF.PostedFile.SaveAs(baseLocation + fn)
filesUploaded += 1
status += fn + "<br>"
Catch err As Exception
Label1.Text = "Error saving file " +
baseLocation + "<br>" + err.ToString()
End Try
Next
If filesUploaded = HIF.Count Then
Label1.Text = "These " + filesUploaded + " file(s)
were uploaded:<br>" + status
End If
HIF.Clear()
ListBox1.Items.Clear()
End If
End Sub
End Class
End Namespace
hoping someone could help me with te error. I would greatly appreciate
help from anyone.
Here is the error:
c:\inetpub\wwwroot\admin\filemanager.aspx.vb(76): Expression is of
type 'System.Web.UI.HtmlControls.HtmlInputFile', which is not a
collection type.
Here is the code:
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Xml
Namespace webchange
Public Class attachme
Inherits System.Web.UI.Page
Protected ListBox1 As System.Web.UI.WebControls.ListBox
Protected AddFile As System.Web.UI.WebControls.Button
Protected RemvFile As System.Web.UI.WebControls.Button
Protected FindFile As System.Web.UI.HtmlControls.HtmlInputFile
Protected Upload As System.Web.UI.HtmlControls.HtmlInputButton
Protected Label1 As System.Web.UI.WebControls.Label
Public files As ArrayList = New ArrayList
Public Shared hif As ArrayList = New ArrayList
Protected Image1 As System.Web.UI.WebControls.Image
Public filesUploaded As Integer = 0
Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
End Sub
Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
InitializeComponent()
MyBase.OnInit(e)
End Sub
Private Sub InitializeComponent()
AddHandler Me.AddFile.Click, AddressOf Me.AddFile_Click
AddHandler Me.RemvFile.Click, AddressOf Me.RemvFile_Click
AddHandler Me.Upload.ServerClick, AddressOf
Me.Upload_ServerClick
AddHandler Me.Load, AddressOf Me.Page_Load
End Sub
Private Sub AddFile_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
If Page.IsPostBack = True Then
hif.Add(FindFile)
ListBox1.Items.Add(FindFile.PostedFile.FileName)
Else
End If
End Sub
Private Sub RemvFile_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
If Not (ListBox1.Items.Count = 0) Then
hif.RemoveAt(ListBox1.SelectedIndex)
ListBox1.Items.Remove(ListBox1.SelectedItem.Text)
End If
End Sub
Public Sub Upload_ServerClick(ByVal sender As Object, ByVal e
As System.EventArgs)
Dim id As String = Request.QueryString("id")
Dim ad As String = Request.QueryString("ad")
Dim folder As String = Request.QueryString("Folder")
Dim baseLocation As String = ""
Dim status As String = ""
If folder = "prod" Then
baseLocation = "C:\" + ad + "_" + id + "\" + ad + "_"
+ id + "\"
End If
If folder = "pim" Then
baseLocation = "C:\" + ad + "_" + id + "\" + ad + "_"
+ id + "_pimfiles\"
End If
If folder = "source" Then
baseLocation = "C:\" + ad + "_" + id + "\" + ad + "_"
+ id + "_source\"
End If
If (ListBox1.Items.Count = 0) AndAlso (filesUploaded = 0)
Then
Label1.Text = "Error - a file name must be specified."
Return
Else
For Each HIF As
System.Web.UI.HtmlControls.HtmlInputFile In HIF
Try
Dim fn As String =
System.IO.Path.GetFileName(HIF.PostedFile.FileName)
HIF.PostedFile.SaveAs(baseLocation + fn)
filesUploaded += 1
status += fn + "<br>"
Catch err As Exception
Label1.Text = "Error saving file " +
baseLocation + "<br>" + err.ToString()
End Try
Next
If filesUploaded = HIF.Count Then
Label1.Text = "These " + filesUploaded + " file(s)
were uploaded:<br>" + status
End If
HIF.Clear()
ListBox1.Items.Clear()
End If
End Sub
End Class
End Namespace