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

save single file to mutiple target folder

1 Answer 161 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Tapas
Top achievements
Rank 1
Tapas asked on 07 Mar 2012, 03:24 PM
Hi, I want to upload a file in two target folder. Problem is file is uploaded successfully in first target folder but when it is saved for 2nd target folder I get file not found error. What I learn that RadAsyncUpload keeps files temporarily in App_Data folder and when file is saved then it is deleted from that folder. Any different approach so that I can save file for different target folder in single upload.

1 Answer, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 08 Mar 2012, 10:25 AM
Hello Tapas,

This behavior is caused by the fact that the SaveAs method of the uploaded file internally deletes the file from the temporary folder after it has copied it in the target folder, because it no longer needs it.

To save the file to two (or more) locations, you can simply use the File.Copy method to copy the file to the second location. Here's a small example:
protected void Button1_Click(object sender, EventArgs e)
{
    foreach (UploadedFile file in RadAsyncUpload1.UploadedFiles)
    {
        string path = Server.MapPath("Files");
        string fullPath = Path.Combine(path, file.FileName);
 
        string copiesPath = Server.MapPath("Copies");
        string copiesFullPath = Path.Combine(copiesPath, file.FileName);
 
        file.SaveAs(fullPath);
        File.Copy(fullPath, copiesFullPath);
    }
}


All the best,
Bozhidar
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.
Tags
AsyncUpload
Asked by
Tapas
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Share this question
or