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

Uploaded in asp.net 3.5

Can you please share a working sample, for having control of the uploaded files?

I get the next error when I try to compile:

Error    2    Member 'GleamTech.Web.Controls.FileVistaControl.Uploaded' cannot be accessed with an instance reference; qualify it with a type name instead    C:\samples\DotNet35\FileManager\FileVistaExamples\WebForm1.aspx.cs    32    17    FileVistaExamples


This is the code:

namespace GleamTech.FileVistaExamples
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        private static bool areHandlersAdded = false;

        private void FileVistaControl_Uploaded(object sender, GleamTech.Web.Controls.FileVistaUploadedEventArgs e)
        {
            string whichUser = HttpContext.Current.Session["username"].ToString();

            //Get the paths of the uploaded files by walking through UploadedFiles collection
            string filePaths = "";
            foreach (GleamTech.Web.FileTransfer.UploadedFile uploadedFile in e.UploadProgress.UploadedFiles)
                filePaths += uploadedFile.FullPath + ", ";
        }

        protected void Page_Load(object sender, EventArgs e)
        {


            fv.RootFolders[0].Path = Server.MapPath("~/Files");

            if (!areHandlersAdded)
            {
                //fv.Uploaded += new EventHandler<FileVistaUploadedEventArgs>(FileVistaControl_Uploaded);
                fv.Uploaded += FileVistaControl_Uploaded;
                areHandlersAdded = true;
            }
        }   
    }
}
Benito Lopez 11/29/2009 8:51 AM
I need to trap the current upload file, and rename it. If the user uploads some.gif I need to rename it into 54321some.gif, so after the callback in the grid I need to see 54321some.gif instead some.gif.
Benito Lopez 11/29/2009 1:41 PM
The events are static members (FileVistaControl.Uploaded) but you are trying to access them like instance members (fv.Uploaded).
Below is the most recent code for example 2 (distributed with v1.7):


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Configuration;

using GleamTech.Web.Controls;
using GleamTech.Web.FileTransfer; //Only used for UploadedFile class referenced in FileVistaControl_Uploaded method

namespace GleamTech.FileVistaExamples
{
    public partial class example2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            FileVistaControl fileVistaControl = (FileVistaControl)LoadControl("~/FileVistaControl/filevista.ascx");

            fileVistaControl.Style = "width: 800px; height: 600px";
            fileVistaControl.Language = "en";
            fileVistaControl.LicenseKey = "k0r64Bq87NBWuEcj1wWW9QxDXQa2A+lf2R+KGZM=";

            FileVistaRootFolder rootFolder1 = new FileVistaRootFolder("Root Folder 1", "~/App_Data/RootFolder1");
            rootFolder1.Permissions = FileVistaPermissions.Full;
            fileVistaControl.RootFolders.Add(rootFolder1);

            FileVistaRootFolder rootFolder2 = new FileVistaRootFolder("Root Folder 2", "~/App_Data/RootFolder2");
            rootFolder2.Permissions = FileVistaPermissions.Traverse | FileVistaPermissions.List 
                                        | FileVistaPermissions.Download | FileVistaPermissions.Upload;
            rootFolder2.Quota = "2000 KB";
            rootFolder2.AllowedFileTypes = "*.jpg; *.gif";
            fileVistaControl.RootFolders.Add(rootFolder2);

            //Render the control in the placeholder.
            PlaceHolder1.Controls.Add(fileVistaControl);

            //Attach your event handlers within this if-block
            //Note that the control events are static so we are checking against an Application variable 
            //to avoid attaching the same events everytime the host page is refreshed.
            if (Application["areEventHandlersAttached"] == null)
            {
                FileVistaControl.Browsed += new EventHandler<FileVistaBrowsedEventArgs>(FileVistaControl_Browsed);
                FileVistaControl.Uploaded += new EventHandler<FileVistaUploadedEventArgs>(FileVistaControl_Uploaded);
                FileVistaControl.Failed += new EventHandler<FileVistaFailedEventArgs>(FileVistaControl_Failed);
                FileVistaControl.Created += new EventHandler<FileVistaCreatedEventArgs>(FileVistaControl_Created);
                FileVistaControl.Deleted += new EventHandler<FileVistaDeletedEventArgs>(FileVistaControl_Deleted);
                FileVistaControl.Renamed += new EventHandler<FileVistaRenamedEventArgs>(FileVistaControl_Renamed);
                FileVistaControl.Copied += new EventHandler<FileVistaCopiedEventArgs>(FileVistaControl_Copied);
                FileVistaControl.Moved += new EventHandler<FileVistaMovedEventArgs>(FileVistaControl_Moved);
                FileVistaControl.Compressed += new EventHandler<FileVistaCompressedEventArgs>(FileVistaControl_Compressed);
                FileVistaControl.Extracted += new EventHandler<FileVistaExtractedEventArgs>(FileVistaControl_Extracted);
                FileVistaControl.Downloaded += new EventHandler<FileVistaDownloadedEventArgs>(FileVistaControl_Downloaded);

                Application["areEventHandlersAttached"] = true;
            } 
        }

        private static void FileVistaControl_Browsed(object sender, FileVistaBrowsedEventArgs e)
        {
            //e.RootFolder
            //e.RelativePath

            //You can use e.RootFolder.MapPath(e.RelativePath) to 
            //get the physical path of the folder that the event occured in.
            System.Diagnostics.Trace.WriteLine(e.RootFolder.MapPath(e.RelativePath), "FileVistaControl_Browsed");

            //Note that the control events will be executed out of the page context as they are static.
            //You can access the executing page context with HttpContext.Current
        }

        private static void FileVistaControl_Uploaded(object sender, FileVistaUploadedEventArgs e)
        {
            //e.RootFolder
            //e.RelativePath
            //e.UploadProgress

            System.Diagnostics.Trace.WriteLine(e.RootFolder.MapPath(e.RelativePath), "FileVistaControl_Uploaded");
            System.Diagnostics.Trace.Indent();

            //You can get information of the uploaded files by walking through UploadedFiles collection 
            foreach (UploadedFile uploadedFile in e.UploadProgress.UploadedFiles)
            {
                System.Diagnostics.Trace.WriteLine(uploadedFile.FullPath);
            }

            System.Diagnostics.Trace.Unindent();
        }

        private static void FileVistaControl_Failed(object sender, FileVistaFailedEventArgs e)
        {
            //e.RootFolder
            //e.RelativePath
            //e.Message
            //e.SourceAction
            //e.SourceActionData

            System.Diagnostics.Trace.WriteLine("FileVistaControl_Failed");
        }

        private static void FileVistaControl_Created(object sender, FileVistaCreatedEventArgs e)
        {
            //e.RootFolder
            //e.RelativePath
            //e.ItemName

            System.Diagnostics.Trace.WriteLine("FileVistaControl_Created");
        }

        private static void FileVistaControl_Deleted(object sender, FileVistaDeletedEventArgs e)
        {
            //e.RootFolder
            //e.RelativePath
            //e.ItemNames

            System.Diagnostics.Trace.WriteLine("FileVistaControl_Deleted");
        }

        private static void FileVistaControl_Renamed(object sender, FileVistaRenamedEventArgs e)
        {
            //e.RootFolder
            //e.RelativePath
            //e.OldItemName
            //e.ItemName

            System.Diagnostics.Trace.WriteLine("FileVistaControl_Renamed");
        }

        private static void FileVistaControl_Copied(object sender, FileVistaCopiedEventArgs e)
        {
            //e.RootFolder
            //e.RelativePath
            //e.FromRootFolder
            //e.FromRelativePath
            //e.ItemNames

            System.Diagnostics.Trace.WriteLine("FileVistaControl_Copied");
        }

        private static void FileVistaControl_Moved(object sender, FileVistaMovedEventArgs e)
        {
            //e.RootFolder
            //e.RelativePath
            //e.FromRootFolder
            //e.FromRelativePath
            //e.ItemNames

            System.Diagnostics.Trace.WriteLine("FileVistaControl_Moved");
        }

        private static void FileVistaControl_Compressed(object sender, FileVistaCompressedEventArgs e)
        {
            //e.RootFolder
            //e.RelativePath
            //e.ZipFileName
            //e.ItemNames

            System.Diagnostics.Trace.WriteLine("FileVistaControl_Compressed");
        }

        private static void FileVistaControl_Extracted(object sender, FileVistaExtractedEventArgs e)
        {
            //e.RootFolder
            //e.RelativePath
            //e.ZipFileName
            //e.ToSubfolder

            System.Diagnostics.Trace.WriteLine("FileVistaControl_Extracted");
        }

        private static void FileVistaControl_Downloaded(object sender, FileVistaDownloadedEventArgs e)
        {
            //e.RootFolder
            //e.RelativePath
            //e.DownloadFileName
            //e.ItemNames

            System.Diagnostics.Trace.WriteLine("FileVistaControl_Downloaded");
        }

    }
}
Cem Alacayir 1/15/2010 3:50 PM