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