Changing Temp Folder location of RadAsyncUpload Dynamically

4 posts, 0 answers
  1. Anil
    Anil avatar
    8 posts
    Member since:
    Jun 2013

    Posted 04 Dec 2013 Link to this post

    Hi,

    I have a requirement where I will be using asyncupload in a pop up window in gridview. I need to save attachments added for each row in a temp folder with someUniqueID I have. And when user click on Save button outside the grid, I will be moving all these files to permanent location. The issue is with modifying temporary folder location dynamically. I want to change the temp folder location when I bring pop-up window by clicking on a button in a row. I do not want to move those files to permanent location until user clicks on save button that is outside grid. I am using radgrid with soma static columns and some dynamic columns.


    Thanks,
    Anil
  2. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 06 Dec 2013 Link to this post

    Hi Anil,

    The files that are saved into the temporary folder can not get mixed up. Each file in temporary folder has a unique name, which is formed by the original name and the current time stamp. For example:
    if you upload "telerik.png" it will be uploaded to temporary folder with name: "1386335690530telerik.png". This means that you can upload one file from two different uploads and there will be no problem to save it from both uploads.

    Please find the attached sample.

    Regards,
    Hristo Valyavicharski
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Anil
    Anil avatar
    8 posts
    Member since:
    Jun 2013

    Posted 06 Dec 2013 Link to this post


    Well..

    Let me explain again.

    My Grid will have testcases listed in each row with a testcaseid. I will be changing the status of testcases to pass/fail/NA. While changing status, I will also add some files to it. Once I am done with changing status and attaching files for all tests, I will click on save button. Then all these attachments should go to folders with their respective testcaseids. I do not want them to be going to some single folder and get mixed up. I hope you understood my requirement now.

    If I add attachments to testcases with ID 10000, 10001 and click on save button. I am expecting to move files attached to 10000 testcaseID to go into a folder named   attachments/testcases/10000
    and files attached to 10001 to go into folder    attachments/testcases/10001. For this reason only, I need identifier for all the files I am attaching to. and I want to control that identifier. 

    Please let me know if it is possible to know the random number that is attached to file name while saving that file to temp folder.

    The example you attached will be moving all the files to single target folder and I do not want that thing to happen. I want files to be moving to different folders.


    Thanks,
    Anil
  5. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 09 Dec 2013 Link to this post

    Hi Anil,

    You don't need to know the Temporary File name. I would suggest that you handle the OnFileUploaded event and store every file into the appropriate folder: 
    protected void RadAsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
    {
        //Get reference of the RadAsyncUpload
        RadAsyncUpload upload = (RadAsyncUpload)sender;
     
        //Get the DataKeyField
        var id = (upload.Parent.Parent as GridDataItem).GetDataKeyValue("TestID");
     
        //Generate the Target folder according to the Test's ID
        string target = Server.MapPath("~/Tests/" + id.ToString() + "/");
     
        //Check if the generated target folder exists. If it doesn't create it.
        if(!Directory.Exists(target))
        {
            Directory.CreateDirectory(target);
        }
     
        //Get the full file name
        string fullFileName = target + e.File.FileName;
        //Save the file
        e.File.SaveAs(fullFileName);
    }

    Sample is attached. 

    Regards,
    Hristo Valyavicharski
    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