I am using this Ajax file upload in my project and it’s working fine, my only problem is how can I save the path of the photo the I just uploaded?
basically I tried to copy the path to a TextBox control after a successful upload and surround that text box with an updatepanel and update that panel manually after calling the Ajax’s SaveAs method, but it doesn’t seem to work.
this is the code for the the uploadedComplete event:
protected void AsyncFileUpload1_UploadedComplete (object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
System.Threading.Thread.Sleep(3000);
if (AsyncFileUpload1.HasFile)
{
var relativeFolder = DateTime.Now.Year.ToString(CultureInfo.InvariantCulture) + Path.DirectorySeparatorChar + DateTime.Now.Month +
Path.DirectorySeparatorChar;
relativeFolder = relativeFolder.Replace('\\', '/');
var folder = Utils.RelativeWebRoot + "PostPhotos/" + relativeFolder;
var fileName = Path.GetFileName(e.FileName);
AsyncFileUpload1.SaveAs(Server.MapPath(folder + fileName));
txtPostPhoto.Text = folder + fileName;
PostImage.ImageUrl = txtPostPhoto.Text;
PostPhotoUpdatePanel.Update();
}
}
txtPostPhoto is my text box.
PostImage is where I am trying to display the image preview.
is there another way of doing this?
Try to save photopath in a ViewState
In client side place a script tag,