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

forcing refresh of uploaded content

2 Answers 166 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 17 Aug 2011, 09:19 PM

I am using the AsyncUpload control to upload an employee picture to a telerik AJAX Manager enabled website.  The <ASP:IMAGE> tag that displays the picture is embedded in a Telerik Rad Ajax Loading Panel.

When I upload the picture (to the temporary folder) and then click the page submit button, the employee picture is correctly saved to the temporary folder and then moved to the target folder.  

As people can potentially upload pictures with the same filename, they can clobber each other's previously uploaded files inside the target folder.  I've added logic in the server side submit button handler to rename each uploaded targetfolder file so that it is always unique to a particular employee.   Each employee will end up retaining this filename as it is based on a formula that uses an employee number, even for future subsequent uploads.  At the end of the submit button handler, I repopulate the screen controls.

If I upload two different pictures for the same screen without leaving it, the first upload renders the picture.  On the second upload, the picture doesn't change even though its content and timestamp HAS changed in the target folder.  The reason it doesn't refresh on the second upload is that the <ASP:IMAGE> tag is using the same filename it had from the first upload.  The ajax mechanism doing the background postback isn't telling something (internet explorer?) to reload the image from the targetfolder.

How do I get the uploaded file to be marked as being dirty so that a refresh on the <ASP:IMAGE> tag is forced?

protected void btnSave_Click(object sender, EventArgs e)
{
    System.String result = "OK";
    System.String strUploadedFileName = "";
    System.String strUploadedFileExtension = "";
    System.String strNewEmployeePhotoName = "";
    System.String strEmployeePicturesPath = "";
      
    try
    {
        System.String strCoordinatorID = lblCoordinatorID.Text.Trim();
        if (strCoordinatorID != "")
        {
            EmployeeInfo coordinator = EmployeeInfo.GetEntity(strCoordinatorID);
            if (upldPicture.UploadedFiles.Count>0)
            {
                strEmployeePicturesPath = getMappedFolderPathTo("EmployeePictures");
                strUploadedFileName = upldPicture.UploadedFiles[0].FileName; //file is located in targetfolder at this point
                strUploadedFileExtension = upldPicture.UploadedFiles[0].GetExtension();
                strNewEmployeePhotoName = "COORDINATOR_" + strCoordinatorID + strUploadedFileExtension;
                  
                //rename the file so that it can't be clobbered by someone else uploading another file with same name
                if (File.Exists(@strEmployeePicturesPath + strNewEmployeePhotoName) == true)
                {
                    File.Delete(@strEmployeePicturesPath + strNewEmployeePhotoName); //delete any leftover picture
                }
                File.Move(@strEmployeePicturesPath + strUploadedFileName, @strEmployeePicturesPath + strNewEmployeePhotoName); //do a move incase the source is still open
                File.Delete(@strEmployeePicturesPath + strUploadedFileName); //delete the original file that was uploaded
            }
              
            if (coordinator != null)
            {   //update existing coordinator
                if (strNewEmployeePhotoName!="")
                {
                    coordinator.employeePhotoFileName = strNewEmployeePhotoName;
                }
                EmployeeInfo.Update(coordinator);
            }
            else
            {
                //its a new coordinator so add it
            }
            result = LoadCoordinator(ref coordinator, userpage.editor); //refresh the page
        }//strCoordinatorID != ""
    }
    catch (Exception ex)
    {
        System.Object oe = (Object)ex;
        result = "btnSave_Click: " + et.rptError(ref oe);
    }//try
    lblMsg.Text = result;
}//EOF btnSave_Click

2 Answers, 1 is accepted

Sort by
0
Andy
Top achievements
Rank 1
answered on 19 Aug 2011, 02:29 PM
Hey Telerik guys, any insights about how to force telerik controls that display uploaded content to re-retrieve that content if its been just uploaded with the telerik rad ajax upload control when the filename is the same and the content was overwritten?

Right now, I'm appending a GUID to the uploaded filename to make it different from its previous version.  But, I'ld really prefer NOT to do that if possible. 
0
Peter Filipov
Telerik team
answered on 22 Aug 2011, 03:21 PM
Hello Andy,

I wasn't able to run your sample code. In order to investigate the issue further, please open a new support ticket and send me a working version of it.

My suggestion is to update asp image control with RadAjaxManager too.

Best wishes,
Peter Filipov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
AsyncUpload
Asked by
Andy
Top achievements
Rank 1
Answers by
Andy
Top achievements
Rank 1
Peter Filipov
Telerik team
Share this question
or