This is a migrated thread and some comments may be shown as answers.

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

5 Answers 766 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Siingh
Top achievements
Rank 2
Siingh asked on 23 Jun 2010, 08:55 AM
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

5 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 28 Jun 2010, 08:56 AM
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
0
Ankit
Top achievements
Rank 1
answered on 31 Oct 2011, 08:22 AM
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.
0
Genady Sergeev
Telerik team
answered on 03 Nov 2011, 08:55 AM
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
0
Gilberto
Top achievements
Rank 1
answered on 12 Dec 2013, 08:43 PM
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
0
Genady Sergeev
Telerik team
answered on 18 Dec 2013, 12:06 PM
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.
Tags
Upload (Obsolete)
Asked by
Siingh
Top achievements
Rank 2
Answers by
Genady Sergeev
Telerik team
Ankit
Top achievements
Rank 1
Gilberto
Top achievements
Rank 1
Share this question
or