teardrop
یک شنبه 25 فروردین 1392, 21:57 عصر
به نام خدا
سلام
برای پروژه ام نیاز به ارسال عکس یا همون آپلود عکس دارم، عکس رو تونستم آپلود و ذخیره کنم. ولی وقتی که می خوام عکس رو از دایرکتوری مربوطه نمایش بدم با مشکل مواجه می شم. یعنی وقتی که عکس تو سایت نمایش داده می شه با دایرکتوری فرق می کنه یعنی اصلا اون عکس وجود نداره. بار اولی که عکس رو آپلود می کنم مشکلی نداره ولی بار دوم که آپلود می کنم و ذخیره میشه تو سایت عکس قبلی رو نشون میده در حالی که اون عکس با عکس جدید در دایرکتوری مربوطه رونویسی شده.
کد ذخیره عکس:
/// <summary>
/// Save image from uploader
/// </summary>
/// <param name="name">name of image</param>
private void SaveImage(string name)
{
try
{
if (Session["fileContentsImgEmployee"] != null)
{
string nameOfImg = name.ToString() + ".jpg";
string savePath = Server.MapPath("~/Images/EmployeeImages/");
byte[] bufferImgEmployee = (byte[])Session["fileContentsImgEmployee"];
// Save to directory of images
System.IO.File.WriteAllBytes(savePath + nameOfImg, bufferImgEmployee);
// Remove session
Session.Remove("fileContentsImgEmployee");
}
}
catch (Exception ex)
{
LabelError.Text = ex.Message;
}
}
کد نمایش عکس :
if (System.IO.File.Exists(Server.MapPath("~/Images/EmployeeImages/") + query.p_ + ".jpg"))
{
employeeImage.Width = 80;
employeeImage.Height = 80;
// It is important when the image is not showed, upper and lower words must checked by explorer(firefox, ie) with generated address asp.net
employeeImage.ImageUrl = "~/images/EmployeeImages/" + query.p_ + ".jpg";
}
else
employeeImage.ImageUrl = "";
102838102839
سلام
برای پروژه ام نیاز به ارسال عکس یا همون آپلود عکس دارم، عکس رو تونستم آپلود و ذخیره کنم. ولی وقتی که می خوام عکس رو از دایرکتوری مربوطه نمایش بدم با مشکل مواجه می شم. یعنی وقتی که عکس تو سایت نمایش داده می شه با دایرکتوری فرق می کنه یعنی اصلا اون عکس وجود نداره. بار اولی که عکس رو آپلود می کنم مشکلی نداره ولی بار دوم که آپلود می کنم و ذخیره میشه تو سایت عکس قبلی رو نشون میده در حالی که اون عکس با عکس جدید در دایرکتوری مربوطه رونویسی شده.
کد ذخیره عکس:
/// <summary>
/// Save image from uploader
/// </summary>
/// <param name="name">name of image</param>
private void SaveImage(string name)
{
try
{
if (Session["fileContentsImgEmployee"] != null)
{
string nameOfImg = name.ToString() + ".jpg";
string savePath = Server.MapPath("~/Images/EmployeeImages/");
byte[] bufferImgEmployee = (byte[])Session["fileContentsImgEmployee"];
// Save to directory of images
System.IO.File.WriteAllBytes(savePath + nameOfImg, bufferImgEmployee);
// Remove session
Session.Remove("fileContentsImgEmployee");
}
}
catch (Exception ex)
{
LabelError.Text = ex.Message;
}
}
کد نمایش عکس :
if (System.IO.File.Exists(Server.MapPath("~/Images/EmployeeImages/") + query.p_ + ".jpg"))
{
employeeImage.Width = 80;
employeeImage.Height = 80;
// It is important when the image is not showed, upper and lower words must checked by explorer(firefox, ie) with generated address asp.net
employeeImage.ImageUrl = "~/images/EmployeeImages/" + query.p_ + ".jpg";
}
else
employeeImage.ImageUrl = "";
102838102839