上传图片操作! 请问:在windows(C#)程序里上传图片操作怎么写的??呵 我初学 不太懂 有哪位大虾能否给出代码! 谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void btnupload_images_Click(object sender, System.EventArgs e){ if(this.File1.Value.ToString()=="")//如果没有图片上传,则提示出错 { Response.Write("<script>alert('请选择正确的图片文件')</script>"); } else { string imagename=this.File1.Value.Substring(this.File1.Value.IndexOf(".")+1).ToUpper(); if(imagename=="GIF" || imagename=="JPG") { if(this.File1.PostedFile.ContentLength>204800)//大小是否大于200K { Response.Write("<script>alert('你上传的图片文件过大')</script>"); } else { //根据时间生成图片名 string SaveName=DateTime.Now.ToString("yyyyMMddhhmmssfff"); string fn=this.File1.PostedFile.FileName; string strImageName=SaveName+fn.Substring(fn.LastIndexOf("."));//图片名加上图片后缀名 string strpath=Server.MapPath("")+"\\UpImages\\"+strImageName;//得到将要保存图片的路径 this.File1.PostedFile.SaveAs(strpath);//把图片保存在此路径中 this.Image1.ImageUrl="\\Web\\Webblog\\UpImages\\"+strImageName;//图片控件赋值 this.Panel1.Visible=false; } } else { Response.Write("<script>alert('你上传的图片文件格式不对')</script>"); } } } 老大,这个是用于网站后台的上传图片的代码啊,不是C# winFrom代码 private void menuItem5_Click(object sender, System.EventArgs e)//图片加载{OpenFileDialog of=new OpenFileDialog();FileStream fs;of.Filter="Picture Files(*.jpg)|*.jpg|Bmp(*.bmp)|*.bmp|All Files(*.*)|*.*";if(of.ShowDialog()==DialogResult.OK&&of.FileName!=""){fs=new FileStream(of.FileName,FileMode.Open,FileAccess.Read);byte[] btyPic=new byte[(int)fs.Length];fs.Read(btyPic,0,btyPic.Length);try{this.ptbImage.SizeMode=PictureBoxSizeMode.Normal;this.ptbImage.Image=Image.FromFile(of.FileName);}catch(Exception ImageExp){MessageBox.Show(ImageExp.Message);}fs.Close();System.Data.SqlClient.SqlCommand sqlUpdateCommand11=new System.Data.SqlClient.SqlCommand();sqlUpdateCommand11.Connection = this.sqlCon;sqlUpdateCommand11.CommandText = "Update JBDA set zp=@zp where zgbh=@zgbh"; sqlUpdateCommand11.Parameters.Add(new System.Data.SqlClient.SqlParameter("@zgbh", System.Data.SqlDbType.VarChar, 50, "zgbh"));sqlUpdateCommand11.Parameters["@zgbh"].Value=this.txtzgbh.Text;sqlUpdateCommand11.Parameters.Add(new System.Data.SqlClient.SqlParameter("@zp", System.Data.SqlDbType.Image,16, "zp"));sqlUpdateCommand11.Parameters["@zp"].Value=btyPic;try{sqlUpdateCommand11.ExecuteNonQuery();}catch(Exception exp){MessageBox.Show(exp.Message);}this.sqljbda.Update(this.dsResult,"JBDA");this.dsResult.Clear();this.sqljbda.Fill(this.dsResult,"JBDA");//sqlUpdateCommand11.Connection.Close();MessageBox.Show("图片插入成功");}} 如何通过系统获取当前正在拷贝文件的拷贝速度? 求一个PluginInstaller.msi下载地址! 文革浏览器兼容性的问题 asp.net新手提问 给DataGridViewComboBoxCell赋值的问题! 绑定问题????(datagridview) FtpFindFirstFile获取文件名不对 在线等 前辈们给看看,,弄了一天了,,到底哪错了,, 高分求救估价冲估的解决方案!急!!! webserver中为什么我的Session保存不了 请教各位:如何实现拖动窗口大小图像跟着放大缩小,总是整体显示在窗口中? ILMerge是怎么用的?
{
if(this.File1.Value.ToString()=="")//如果没有图片上传,则提示出错
{
Response.Write("<script>alert('请选择正确的图片文件')</script>");
}
else
{
string imagename=this.File1.Value.Substring(this.File1.Value.IndexOf(".")+1).ToUpper();
if(imagename=="GIF" || imagename=="JPG")
{
if(this.File1.PostedFile.ContentLength>204800)//大小是否大于200K
{
Response.Write("<script>alert('你上传的图片文件过大')</script>");
}
else
{
//根据时间生成图片名
string SaveName=DateTime.Now.ToString("yyyyMMddhhmmssfff");
string fn=this.File1.PostedFile.FileName;
string strImageName=SaveName+fn.Substring(fn.LastIndexOf("."));//图片名加上图片后缀名
string strpath=Server.MapPath("")+"\\UpImages\\"+strImageName;//得到将要保存图片的路径
this.File1.PostedFile.SaveAs(strpath);//把图片保存在此路径中
this.Image1.ImageUrl="\\Web\\Webblog\\UpImages\\"+strImageName;//图片控件赋值
this.Panel1.Visible=false;
}
}
else
{
Response.Write("<script>alert('你上传的图片文件格式不对')</script>");
}
}
}
{
OpenFileDialog of=new OpenFileDialog();
FileStream fs;
of.Filter="Picture Files(*.jpg)|*.jpg|Bmp(*.bmp)|*.bmp|All Files(*.*)|*.*";
if(of.ShowDialog()==DialogResult.OK&&of.FileName!="")
{
fs=new FileStream(of.FileName,FileMode.Open,FileAccess.Read);
byte[] btyPic=new byte[(int)fs.Length];
fs.Read(btyPic,0,btyPic.Length);
try
{
this.ptbImage.SizeMode=PictureBoxSizeMode.Normal;
this.ptbImage.Image=Image.FromFile(of.FileName);
}
catch(Exception ImageExp)
{
MessageBox.Show(ImageExp.Message);
}
fs.Close();
System.Data.SqlClient.SqlCommand sqlUpdateCommand11=new System.Data.SqlClient.SqlCommand();
sqlUpdateCommand11.Connection = this.sqlCon;
sqlUpdateCommand11.CommandText = "Update JBDA set zp=@zp where zgbh=@zgbh"; sqlUpdateCommand11.Parameters.Add(new System.Data.SqlClient.SqlParameter("@zgbh", System.Data.SqlDbType.VarChar, 50, "zgbh"));
sqlUpdateCommand11.Parameters["@zgbh"].Value=this.txtzgbh.Text;
sqlUpdateCommand11.Parameters.Add(new System.Data.SqlClient.SqlParameter("@zp", System.Data.SqlDbType.Image,16, "zp"));
sqlUpdateCommand11.Parameters["@zp"].Value=btyPic;
try{sqlUpdateCommand11.ExecuteNonQuery();}
catch(Exception exp)
{MessageBox.Show(exp.Message);}
this.sqljbda.Update(this.dsResult,"JBDA");
this.dsResult.Clear();
this.sqljbda.Fill(this.dsResult,"JBDA");//sqlUpdateCommand11.Connection.Close();
MessageBox.Show("图片插入成功");}
}