These forums are read-only and considered to be an archive. Please use the new Community for future interaction and posts.

Using VB

Hi,

I'm trying to use the construct 

FileVistaControl.Uploaded += new EventHandler<FileVistaUploadedEventArgs>(FileVistaControl_Uploaded);

in Visua Basic.

I used FileVistaControl.Uploaded += EventHandler(Of FileVistaUploadedEventArgs)(FileVistaControl_Uploaded)

I get the compile error message "'Public Shared Event Uploaded(sender As Object, e As GleamTech.Web.Controls.FileVistaUploadedEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event."

Am I using the wrong syntax or am I missing something else?

Thanks
Rey Dipasquale 1/12/2009 12:23 PM
I guess you are missing the New operator in that line, please see below for an example code:

Private Shared areHandlersAdded As Boolean = False

Protected Sub Page_Load(sender As Object, e As EventArgs)
    'Add your events within this if block 
    If Not areHandlersAdded Then
        FileVistaControl.Uploaded += New EventHandler(Of FileVistaUploadedEventArgs)(FileVistaControl_Uploaded)

        areHandlersAdded = True
    End If
End Sub

Private Sub FileVistaControl_Uploaded(sender As Object, e As FileVistaUploadedEventArgs)
    'You can use e.RootFolder.MapPath(e.RelativePath) to 
    'get the physical path of only the folder that the files are uploaded to 

    'Get the paths of the uploaded files by walking through UploadedFiles collection 
    Dim filePaths As String

    For Each uploadedFile As GleamTech.Web.FileTransfer.UploadedFile In e.UploadProgress.UploadedFiles
        filePaths += uploadedFile.FullPath + ", "
    Next
End Sub
Cem Alacayir 1/13/2009 6:43 PM
Hi,

I checked the statement "new" and I already had it in place (I neglected it when I entered the post).  Here's the entire code segment.
I noticed that in the statement "FileVistaControl.Uploaded" the "Uploaded" does not show as a method in Visual Studio.  Looks like it is not a programming issue but something else is missing.  Can you tell?


<%@ Import Namespace="GleamTech.Web.Controls" %>
<%@ Page Language="VB" Debug="true" AutoEventWireup="false"  %>

Private areHandlersAdded As Boolean = False

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

            
    If Not areHandlersAdded Then
       FileVistaControl.Uploaded += New EventHandler(Of FileVistaUploadedEventArgs)(FileVistaControl_Uploaded)
       areHandlersAdded = True
    End If
          
    Dim MyFileVistaControl As FileVistaControl = CType(LoadControl("~/FileVistaControl/filevista.ascx"), FileVistaControl)
            
    MyFileVistaControl.Style = "width: 800px; height: 600px"
    MyFileVistaControl.LicenseKey = "HUjDwSdIPUAQ+JPk2yMrEU1IUHgT2EDvUusdYUxKZaaZTuPwTLlr2A=="

    Dim RootFolder As FileVistaRootFolder
            
    RootFolder = New FileVistaRootFolder("Shared Folder", GetConfigString("SharedRootFolder"))
    RootFolder.Permissions = FileVistaPermissions.Traverse And FileVistaPermissions.List And FileVistaPermissions.Download
    MyFileVistaControl.RootFolders.Add(RootFolder)

            
    Dim RootFolders(1) As FileVistaRootFolder
    RootFolders(1) = New FileVistaRootFolder("Shared Folder", GetConfigString("SharedRootFolder"))
    FileVistaControl.SessionRootFolders = RootFolders
            
    PlaceHolder1.Controls.Add(MyFileVistaControl)
          
    FileVistaControl.Uploaded += New EventHandler(Of FileVistaUploadedEventArgs)(FileVistaControl_Uploaded)

End Sub            
    

Function FileVistaControl_Uploaded(ByVal sender As Object, ByVal e As FileVistaUploadedEventArgs)
    'Get the paths of the uploaded files by walking through UploadedFiles collection 
    'You can use e.RootFolder.MapPath(e.RelativePath) to 
    'get the physical path of only the folder that the files are uploaded to 

    'Get the paths of the uploaded files by walking through UploadedFiles collection 
    Dim filePaths As String

    For Each uploadedFile As GleamTech.Web.FileTransfer.UploadedFile In e.UploadProgress.UploadedFiles
        filePaths += uploadedFile.FullPath + ", "
    Next
        
End Function
 
Rey Dipasquale 1/14/2009 1:04 PM
Hi, I fond the answer.  It is a VB programming error.  The C# statement

FileVistaControl.Uploaded += New EventHandler(Of FileVistaUploadedEventArgs)(FileVistaControl_Uploaded) 

Translates to VB as

AddHandler FileVistaControl.Uploaded, AddressOf FileVistaControl_Uploaded

Rey Dipasquale 1/15/2009 7:23 AM
Hello Rey,

I have seen you have used VB. Would you mind in sharing the VB code to insert FileVistaControl on a page? I have converted the C# code used on Example2.aspx (see below) but I get the following error: "Variable 'PlaceHolderX' is used before it has been assigned a value. A null reference exception could result at runtime."

My code is:

Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Web.Configuration

Imports GleamTech.Web.Controls

Namespace filemanager

    Partial Public Class filemanager

        Inherits System.Web.UI.Page
        'Protected testPath1 As String = WebConfigurationManager.AppSettings("TestPath1")
        'Protected testPath2 As String = WebConfigurationManager.AppSettings("TestPath2")

        Private Shared areHandlersAdded As Boolean = False

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            If Not areHandlersAdded Then
                AddHandler FileVistaControl.Uploaded, AddressOf FileVistaControl_Uploaded
                areHandlersAdded = True
            End If

            Dim ctlGerenciaArquivos As FileVistaControl = DirectCast(LoadControl("~/FileVistaControl/filevista.ascx"), FileVistaControl)
            Dim PlaceHolderX As PlaceHolder

            ctlGerenciaArquivos.Style = "width: 800px; height: 600px"
            'Set license key to some arbitrary string value till you purchase a valid key. 
            ctlGerenciaArquivos.LicenseKey = "k0r64Bq87NBWuEcj1wWW9QxDXQa2A+lf2R+KGZM="

            Dim rootFolder As FileVistaRootFolder

            rootFolder = New FileVistaRootFolder("Test Root Folder", "D:\Downloads")
            rootFolder.Permissions = FileVistaPermissions.Full
            ctlGerenciaArquivos.RootFolders.Add(rootFolder)

            Dim rootFolders As FileVistaRootFolder() = New FileVistaRootFolder(0) {}
            rootFolders(0) = New FileVistaRootFolder("Test Root Folder", "D:\Downloads")
            FileVistaControl.SessionRootFolders = rootFolders

            PlaceHolderX.Controls.Add(ctlGerenciaArquivos)

            AddHandler FileVistaControl.Uploaded, AddressOf FileVistaControl_Uploaded

        End Sub

        Private Sub FileVistaControl_Uploaded(ByVal sender As Object, ByVal e As FileVistaUploadedEventArgs)

        End Sub
    End Class
End Namespace

Your help is appreciated.
Mauro 1/20/2009 4:02 AM