How To Clear Uploaded Files after succesfull upload using Upload / Silverlight RadUpload

Thread is closed for posting
6 posts, 0 answers
  1. Siingh
    Siingh avatar
    32 posts
    Member since:
    Jul 2012

    Posted 23 Jun 2010 Link to this post

    Hi Telerik
    I am using Upload / Silverlight RadUpload , I have problem that everytime I upload files, those files remain in uploadfiles method or array.
    I want to clear those previous files name once they uploded. when ever I upload one file and save file info into database then try to upload another file this time it will loop though old uploaded file also and new one also.

    I want to delete uploaded files from memory only not disk once they uploaded and if I upload new file it should show only new file not previous uploaded files.

    I have Upload / Silverlight RadUpload and one button on form within RadWindow and I am using Radajax

    What I am doing
    Steps
    1. Upload file 1 using Upload / Silverlight RadUpload
    2. Click on Button to retrieve uploaded files info to store in database
    3. Now I want to upload file 2 so i selected file 2
    4. Click on button to retrieve uploaded file 2 but this time it will show me file 1 and file 2 also


    If i repeat thoese steps it will show me all files again while i save thier info.
    only one way I have found to clear it is to refresh page but I am using Radajax and I dont want to refresh


    Also please tell me is thier any way to change thier file name while uploading..


    reply me please asap urgent



    Kind Regards:
    Harinder Singh
    McConnell Dowell SEA
  2. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 28 Jun 2010 Link to this post

    Hi Siingh,

    Indeed such problem exists. Fortunately, it is pretty easy to fix it. Just reset the value of the hidden input field after you are ready. Example:

    protected void Button1_Click(object sender, EventArgs e)
        {
            //All files are serialized as UploadedFileInfo object in JSON format stored in the UploadedFilesJson hidden field
     
            List<UploadedFileInfo> uploadedFiles = new List<UploadedFileInfo>();
     
     
            //Check whether the user uploaded any files.
            if (!string.IsNullOrEmpty(UploadedFilesJson.Value))
            {
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List<UploadedFileInfo>));
                 
                //Deserialize the uploaded files
                uploadedFiles = (List<UploadedFileInfo>)serializer.ReadObject(new MemoryStream(Encoding.UTF8.GetBytes(UploadedFilesJson.Value)));
     
                foreach (UploadedFileInfo file in uploadedFiles)
                {
                    string fullName = Path.Combine(MapPath("~/Files"), file.FileName);
                    //Use the uploaded files for something
                     
                    if (File.Exists(fullName))
                    {
                        string fileContents = File.ReadAllText(fullName);
     
                        //Give some feedback that the file is processed
                        Placeholder1.Controls.Add(new LiteralControl("<div>" + file.FileName + " (" + file.FileSize + " bytes)</div>"));
     
                        //Optionally delete the uploaded file
                        File.Delete(fullName);
                    }
                }
            }
     
            UploadedFilesJson.Value = string.Empty;
        }

    The important line here is the last line. I have attached sample project to this replay that demonstrates the approach.

    Regards,
    Genady Sergeev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ankit
    Ankit avatar
    4 posts
    Member since:
    Oct 2011

    Posted 31 Oct 2011 Link to this post

    hello,
    i am use this example this is work fine but i am use my project. javascript is not working properly so json is not set the value then i am not recieve the uploaded file name please help me.
  5. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 03 Nov 2011 Link to this post

    Hi Ankit,

    We have dropped the support for the sample silverlight upload in favor of RadAsyncUpload. I suggest that you take a look at it.


    Best wishes,
    Genady Sergeev
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  6. Gilberto
    Gilberto avatar
    1 posts
    Member since:
    May 2011

    Posted 12 Dec 2013 Link to this post

    Hi, I've been struggling with the same problem above and I'm using a RadAsyncUpload control but I couldn't figure out on how to use your code towards it. For example, how do I use the following line of your code:

    //Deserialize the uploaded files
    uploadedFiles = (List<UploadedFileInfo>)serializer.ReadObject(
    new MemoryStream(Encoding.UTF8.GetBytes(UploadedFilesJson.Value)));

    My control name's "AsyncUpload1"

    Thank you!
    Gil
  7. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 18 Dec 2013 Link to this post

    Hi Gilberto,

    The Silverlight upload is long time deprecated and we do not recommend using it. I guess that you use RadAsyncUpload and try to use the code provided in this thread but the two controls are not compatible and the code won't work. In order to help you better could you please open a new thread and post your exact issue there or simply update this thread?

    Regards,
    Genady Sergeev
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017