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

events

hello,
i am getting an error on the first line of the IF statement.
if (FileVistaControl.Uploaded == null)
                    FileVistaControl.Uploaded += new EventHandler<FileVistaUploadedEventArgs>(FileVistaControl_Uploaded); 

i am getting "The event 'GleamTech.Web.Controls.FileVistaControl.Uploaded' can only appear on the left hand side of += or -="

please help...
Dima 7/7/2008 7:05 AM
Another problem appears when two users are uploading files in the same time. what happens then is that the object e.UploadProgress.UploadedFiles has the files from both user intstead of each user having his own event and files. how can i prevent this from happening and get the file name that has benn uploaded for each user?
Dima 7/7/2008 7:37 AM
Hi Dima,
The code you posted appears to be correct and should compile, please make sure you use == and not = in the if statement.

Regarding associating the events to the users, this will be very easy by using the session object. For example you can set a session variable to the logged in user’s name in Page_Load event:

Session["UserName"] = "dima";

Then in the events, you can determine the user which caused the event like this:

private void FileVistaControl_Uploaded(object sender, FileVistaUploaded EventArgs e)
{
string whichUser = HttpContext.Current.Session["UserName"]

}
Cem Alacayir 7/7/2008 1:29 PM
thank you for your answer.
the code i posted is correct. i am sure i using == in the if statement, and still getting the same error.

regarding your suggestion to use the session variable i still cant see how it helps me knowing which file in the object "e.UploadProgress.UploadedFiles" was uploaded by each user in the event.
The object e.UploadProgress.UploadedFiles contains all the files that were uploaded.

thanks again.
Dima 7/7/2008 11:08 PM
Dima,
Please use the following code instead to get rid of the error:

        private static bool areHandlersAdded = false;

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!areHandlersAdded)
            {
                FileVistaControl.Uploaded += new EventHandler<FileVistaUploadedEventArgs>(FileVistaControl_Uploaded);

                areHandlersAdded = true;
            }

        }

Note that as the control events are static, we use a static bool field in our page class to make sure the event handlers are only added once and not each time Page_Load is called.

Regarding associating the events to the users, separate upload events are already raised for each upload action so e.UploadProgress.UploadedFiles can not contain files from different users, it can only contain the files from one user at a time. So you just use the session variable to simply find out which user is this.
Cem Alacayir 7/16/2008 7:17 PM
I have tried all of the suggestions to get the "Uploaded" event to register.

I have the trial 1.5.9.  

It doesn't show up in intellisense - so where is it?

Here's the code I used:

    private static bool areHandlersAdded = false; 
    //-----------------------------------
    protected void Page_Load(object sender, EventArgs e)
    {
        FileVistaControl.RootFolders[0].Path = Server.MapPath("~/Files");

        if (!areHandlersAdded)
        { 
            FileVistaControl.Uploaded += new EventHandler<FileVistaUploadedEventArgs>(FileVistaControl_Uploaded);
            areHandlersAdded = true;
        }
    }
Ben Hall 7/22/2008 12:17 PM
Are you sure you are referencing to GleamTech.Web.FileVistaControl.dll in your project and accessing the static class as FileVistaControl.Uploaded ?
Cem Alacayir 7/29/2008 12:44 PM
How do I do that?

Register in web.config?

I've got this:

<add tagPrefix="GleamTech" tagName="FileVistaControl" src="~/FileVistaControl/filevista.ascx" />
<add tagPrefix="GleamTech" assembly="GleamTech.Web.Controls.FileVistaControl" namespace="GleamTech.Web.Controls.FileVistaControl" />

Am I missing something?
Ben Hall 7/30/2008 3:53 PM
No, that reference is for adding the control via markup (tagPrefix), when adding the control programmatically, you need to add reference to FileVistaControl\bin\GleamTech.Web.Controls.FileVistaControl.dll in your project's References section.
Cem Alacayir 8/8/2008 9:07 AM