问题描述
我的方法需要刷新以便为用户显示上传的照片。如何避免为用户刷新页面。
protected void fileUploadComplete(object sender,AsyncFileUploadEventArgs e)
{
Thread.Sleep(1000);
尝试
{
string profileimg =,name =,formid =,ext =;
if(Session [DisplayName]!= null && Convert.ToString(Session [DisplayName])!=&& Session [FormId]!= null && Convert.ToString(Session [FormId])!=)
{
name = Convert.ToString(Session) [DisplayName]);
formid = Convert.ToString(Session [FormId]);
profileimg = Convert.ToString(ConfigurationManager.AppSettings [ProfileImg] ])+ name.Split('')[0] +_+ formid;
if(fileUpload1.HasFile)
{
ext = System.IO.Path.GetExtension(fileUpload1.FileName);
位图bmpImg = null;
newfilenameWithExt = profileimg + ext;
if(hdnOldFileName.Value!=)
{
string oldFilePath = Server.MapPath(〜/)+/ storedata /+studentphotos / + hdnOldFileName.Value;
FileInfo oldFile = new FileInfo(oldFilePath);
if(System.IO.File.Exists(oldFilePath))
System.IO.File.Delete(oldFilePath);
}
StudentApplication objStdFileUpload = new StudentApplication();
objStdFileUpload.StudentFormID = 0;
objStdFileUpload.StudentFormID = Convert.ToInt32(Session [FormId]。ToString());
objStdFileUpload.StudentProfileImage = newfilenameWithExt;
if(objStdFileUpload.StudentFormID!= 0)
{
objStdFileUpload。 UpdateFileNameUploadByFormID();
//在上传到Storedata之前调整图像大小
bmpImg = Resize_Image(fileUpload1.PostedFile.InputStream,350,262) ;
bmpImg.Save(Server.MapPath(〜/)+/ storedata /+studentphotos /+ newfilenameWithExt,ImageFormat.Jpeg);
hdnFileNmWithoutExt .Value = Convert.ToString(ConfigurationManager.AppSettings [Home])+storedata / studentphotos /+ newfilenameWithExt;
imgStudentImage.ImageUrl = Server.MapPath(〜/ storedata / studentphotos / )+ newfilenameWithExt;
}
}
}
}
catch(exception ex)
{
MessageControl1.ErrorMessage(Error: - + ex.ToString());
}
}
My Method requires refresh in order to show uploaded photo for user.How to avoid refreshing of page for user.
protected void fileUploadComplete(object sender, AsyncFileUploadEventArgs e)
{
Thread.Sleep(1000);
try
{
string profileimg = "", name = "", formid = "", ext = "";
if (Session["DisplayName"] != null && Convert.ToString(Session["DisplayName"]) != "" && Session["FormId"] != null && Convert.ToString(Session["FormId"]) != "")
{
name = Convert.ToString(Session["DisplayName"]);
formid = Convert.ToString(Session["FormId"]);
profileimg = Convert.ToString(ConfigurationManager.AppSettings["ProfileImg"]) + name.Split(' ')[0] + "_" + formid;
if (fileUpload1.HasFile)
{
ext = System.IO.Path.GetExtension(fileUpload1.FileName);
Bitmap bmpImg = null;
newfilenameWithExt = profileimg + ext;
if (hdnOldFileName.Value != "")
{
string oldFilePath = Server.MapPath("~/") + "/storedata/" + "studentphotos/" + hdnOldFileName.Value;
FileInfo oldFile = new FileInfo(oldFilePath);
if (System.IO.File.Exists(oldFilePath))
System.IO.File.Delete(oldFilePath);
}
StudentApplication objStdFileUpload = new StudentApplication();
objStdFileUpload.StudentFormID = 0;
objStdFileUpload.StudentFormID = Convert.ToInt32(Session["FormId"].ToString());
objStdFileUpload.StudentProfileImage = newfilenameWithExt;
if (objStdFileUpload.StudentFormID != 0)
{
objStdFileUpload.UpdateFileNameUploadByFormID();
// Resize Image Before Uploading to Storedata
bmpImg = Resize_Image(fileUpload1.PostedFile.InputStream, 350, 262);
bmpImg.Save(Server.MapPath("~/") + "/storedata/" + "studentphotos/" + newfilenameWithExt, ImageFormat.Jpeg);
hdnFileNmWithoutExt.Value = Convert.ToString(ConfigurationManager.AppSettings["Home"]) + "storedata/studentphotos/" + newfilenameWithExt;
imgStudentImage.ImageUrl = Server.MapPath("~/storedata/studentphotos/") + newfilenameWithExt;
}
}
}
}
catch (Exception ex)
{
MessageControl1.ErrorMessage("Error:- " + ex.ToString());
}
}
推荐答案
这篇关于如何在没有刷新页面的情况下第一次显示上传的照片。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!