save single file to mutiple target folder

2 posts, 0 answers
  1. Tapas
    Tapas avatar
    1 posts
    Member since:
    Mar 2012

    Posted 07 Mar 2012 Link to this post

    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.
  2. Bozhidar
    Admin
    Bozhidar avatar
    1188 posts

    Posted 08 Mar 2012 Link to this post

    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.
Back to Top