上传图片代码一:
private string UploadFile()
{
if (!Directory.Exists(this.VtekPhotoPath))
{
DirectoryInfo dirinfo = Directory.CreateDirectory(this.VtekPhotoPath);
}
string file_name = "";
try
{
this.media = new MyUploader.HttpMedia();
media.ChangePrefixAsTimeStr();
media.SetMaxLength(3000);
ArrayList al = new ArrayList();
al.Add("jpeg");
al.Add("jpg");
al.Add("gif");
al.Add("png");
al.Add("bmp");
media.SetFilter(al);
if (media.Upload(this.VtekPhotoPath))
{
file_name = media.GetFileName();
if (file_name != "")
{
string sql = "select top 1 picture from Goods where SN ='" + this.pk + "'";
string file_name1 = MySqlBase.GetVarFromSql(sql, "img");
this.deleleFile(file_name1);
}
}
else
{
string s = media.ErrorMessages;
}
}
catch (Exception Err)
{
this.tErrors = Err.Message;
}
return file_name;
}
private bool deleleFile(string file_name)
{
try
{
if (File.Exists(this.VtekPhotoPath + "/" + file_name))
{
File.Delete(this.VtekPhotoPath + "/" + file_name);
return true;
}
}
catch (Exception Err)
{
this.tErrors = Err.Message;
}
return false;
}
上传图片代码2:
private string UploadImg(int i)
{
if (!Directory.Exists(this.VtekPhotoPath))
{
DirectoryInfo dirinfo = Directory.CreateDirectory(this.VtekPhotoPath);
}
string photo_name = "";
try
{
this.media = new MyUploader.HttpMedia(i);
media.ChangePrefixAs(DateTime.Now.ToString("yyyyMMddHHmmss") + i.ToString());
media.SetMaxLength(500);
if (media.UploadPhotos(this.VtekPhotoPath))
{
photo_name = media.GetFileName();
}
string a = media.ErrorMessages;
}
catch (Exception err)
{
string tErrors = err.Message;
}
return photo_name;
}
private int SaveDate()
{
int i = -1;
SqlParameter[] p = new SqlParameter[7];
p[0] = new SqlParameter("@headline", this.txtnewtitle.Text.Trim());
p[1] = new SqlParameter("@type", "2");
p[2] = new SqlParameter("@content", this.txtcontent.Text.Trim());
p[3] = new SqlParameter("@isUse", this.rbtstart.SelectedValue);
System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
int file;
string all_photo_name = "";
if (this.ck1.Checked == true)
{
string tch = this.txt1.Text;
all_photo_name += tch.Substring(tch.LastIndexOf("/") + 1) + "|";
}
else
{
string tch11 = this.txt1.Text;
string picname1 = tch11.Substring(tch11.LastIndexOf("/") + 1);
if (picname1 != "")
{
deleleImg(picname1);
}
}
if (this.ck2.Checked == true)
{
string tch2 = this.txt2.Text;
all_photo_name += tch2.Substring(tch2.LastIndexOf("/") + 1) + "|";
}
else
{
string tch12 = this.txt2.Text;
string picname2 = tch12.Substring(tch12.LastIndexOf("/") + 1);
if (picname2 != "")
{
deleleImg(picname2);
}
}
if (this.ck3.Checked == true)
{
string tch3 = this.txt3.Text;
all_photo_name += tch3.Substring(tch3.LastIndexOf("/") + 1) + "|";
}
else
{
string tch13 = this.txt3.Text;
string picname3 = tch13.Substring(tch13.LastIndexOf("/") + 1);
if (picname3 != "")
{
deleleImg(picname3);
}
}
if (this.ck4.Checked == true)
{
string tch4 = this.txt4.Text;
all_photo_name += tch4.Substring(tch4.LastIndexOf("/") + 1) + "|";
}
else
{
string tch14 = this.txt4.Text;
string picname4 = tch14.Substring(tch14.LastIndexOf("/") + 1);
if (picname4 != "")
{
deleleImg(picname4);
}
}
if (this.ck5.Checked == true)
{
string tch5 = this.txt5.Text;
all_photo_name += tch5.Substring(tch5.LastIndexOf("/") + 1) + "|";
}
else
{
string tch15 = this.txt5.Text;
string picname5 = tch15.Substring(tch15.LastIndexOf("/") + 1);
if (picname5 != "")
{
deleleImg(picname5);
}
}
for (file = 0; file < files.Count; file++)
{
string photo_name = this.UploadImg(file);
if (!CoolFuncs.IsNullorEmpty(photo_name))
{
all_photo_name += photo_name + "|";
}
}
if (!CoolFuncs.IsNullorEmpty(all_photo_name))
{
p[4] = new SqlParameter("@photos", all_photo_name);
}
p[5] = new SqlParameter("@Sign_user",this.LoginUser.UID);
p[6] = new SqlParameter("@SN", this.pk);
return i = MySqlBase.ExecuteSql("Event_News_Save", p);
}
private bool deleleImg(string img_name)
{
try
{
if (File.Exists(this.VtekPhotoPath + "/" + img_name))
{
File.Delete(this.VtekPhotoPath + "/" + img_name);
return true;
}
}
catch (Exception err)
{
this.tErrors = err.Message;
}
return false;
}