ورود

View Full Version : سوال: تغییر نام تصویر و آپلود آن



hadi-z
شنبه 01 بهمن 1390, 23:38 عصر
سلام
چجوری میشه در هنگام دریافت یک تصویر نام اون رو عوض کرد و در یک فولدر از پیش تعیین شده ذخیره اش کرد؟
در ضمن اگر نام رو عوض کردیم و یک تصویر قبلا با همون نام تو اون فولدر وجود داشته باشه به مشکل برمی خوریم یا خودش replace میشه؟
ممنون میشم بهم پاسخ بدید.

TeacherMath
شنبه 01 بهمن 1390, 23:44 عصر
برای اینکه نامها با هم فرق کنند می توانید از
System.Guid استفاده کنید.

hadi-z
شنبه 01 بهمن 1390, 23:46 عصر
شرمنده ولی اصلا متوجه منظورتون نشدم
من میخوام عکسهایی که آپلود میشن رو خودم نام گذاری کنم

fakhravari
شنبه 01 بهمن 1390, 23:47 عصر
public string UpPath;
public string pathImage;
public static string ImageFileName;

public string pathAtach;
public static string AtachFileName;

public void uploadpic()
{

UpPath = Server.MapPath(@"../Img/Img_Topik/");
if (!Directory.Exists(UpPath))
{
Directory.CreateDirectory(Server.MapPath(@"../Img/Img_Topik/"));
}

pathImage = Server.MapPath(@"../Img/Img_Topik/");
String[] validext = { ".jpg", ".jpeg", ".bmp", ".jpe", ".png", ".gif", ".tiff", ".tif", ".bmp" };
string ext = System.IO.Path.GetExtension(FileUpload1.PostedFile .FileName);
if (Array.IndexOf(validext, ext.ToLower()) < 0)
{
return;
}

ImageFileName = System.IO.Path.GetFileName(FileUpload1.FileName);

//FileInfo TheFile = new FileInfo(Server.MapPath(@"../Img/Img_Topik/") + ImageFileName);
//if (TheFile.Exists)
//{
// File.Delete(Server.MapPath(@"../Img/Img_Topik/") + ImageFileName);
//}

while (System.IO.File.Exists(pathImage + ImageFileName))
{
ImageFileName = "1" + ImageFileName;
}


FileUpload1.PostedFile.SaveAs(pathImage + ImageFileName);
}

public void uploadFile()
{

UpPath = Server.MapPath(@"../Img/File_Topik/");
if (!Directory.Exists(UpPath))
{
Directory.CreateDirectory(Server.MapPath(@"../Img/File_Topik/"));
}

pathAtach = Server.MapPath(@"../Img/File_Topik/");
String[] validext = { ".rar", ".zip", ".doc", ".docx", ".ppt", ".pptx" };
string ext = System.IO.Path.GetExtension(FileUpload2.PostedFile .FileName);
if (Array.IndexOf(validext, ext.ToLower()) < 0)
{
return;
}

AtachFileName = System.IO.Path.GetFileName(FileUpload2.FileName);

//FileInfo TheFile = new FileInfo(Server.MapPath(@"../Img/File_Topik/") + AtachFileName);
//if (TheFile.Exists)
//{
// File.Delete(Server.MapPath(@"../Img/File_Topik/") + AtachFileName);
//}
while (System.IO.File.Exists(pathAtach + AtachFileName))
{
AtachFileName = "1" + AtachFileName;
}

FileUpload1.PostedFile.SaveAs(pathAtach + AtachFileName);
}

http://barnamenevis.org/showthread.php?319398