I am using ajaxfileupload control on my asp.net page. After image is uploaded, I call uploadcomplete method to save the image on disk and show in image control using following javascript:
string fileName = Guid.NewGuid() + Path.GetExtension(PhotoAFU.FileName.Trim()); // encrypt filename
string filePath = Path.Combine(storagePath, fileName);
string fileVirtPath = GetImageUrl(fileName);
int rnd = new Random((int)DateTime.Now.Ticks).Next(1, 1000);
ScriptManager.RegisterClientScriptBlock(PhotoAFU, PhotoAFU.GetType(), "img",
String.Format(
@"top.document.getElementById('{0}').src='{1}?x={2}';
top.document.getElementById('{3}').value = '{4}'",
EditPhotoImage.ClientID,
fileVirtPath,
rnd,
UploadedImageFileNameHF.ClientID,
fileName),
true
);
Now I click on a save button and try to get the image using following code:
Path.GetFileName(EditPhotoImage.ImageUrl) // shows old image
or
Path.GetFileName(PhotoAFU.FileName) // it shows actual image name not encrypted one
but they both show old image not the current image or actual image name not encrypted name. How can I get the filename from above method in this method ? I tried using viewstate but it is not working properly.