求指教,怎么在form窗体中可以选择上传图片并且显示为头像 急需要这个功能, 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果是winform用一个Picturebox来显示就可以了,如果是webform用image控件来显示。至于上传,winform是在本地的,不需要上传。webform有fileupload控件可以实现上传。都不难的。 OpenFileDialog OpenFile = new OpenFileDialog(); if (OpenFile.ShowDialog(this) == DialogResult.OK) { if (MessageBox.Show("上传成功!是否设置为头像?", "成功!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) this.BackgroundImage = Image.FromFile(OpenFile.FileName); }不谢 //[HttpPost] //public ActionResult Upload(FormCollection form) //{ // //1.获取文件信息 // HttpPostedFileBase file = Request.Files["file"]; // //2.判断文件大小,扩展名(可以用js实现) // if (file.ContentLength > 1048576) // { // //xxxxxxxxx // } // //2.判断文件类型 // if (file.ContentType != "image/png" || file.ContentType != "image/gif") // { // //xxxxxxxxx // //return View("Index"); // } // if (file.FileName != null) // { // string serverPath = HttpContext.Server.MapPath("/Content/UploadFile"); // //2.判断文件目录是否存在 // if (!Directory.Exists(serverPath)) // { // Directory.CreateDirectory(serverPath); // } // string filePath = Path.Combine(serverPath, Path.GetFileName(file.FileName)); // file.SaveAs(filePath); // return View("Index"); // } // else // { // return View(); // } //} //public ActionResult DownLoad() //{ // //插件名称 // string fileName = "logo.png"; // //文件路径 // string filePath = Server.MapPath("/Content/DownloadFile/logo.png"); // FileStream fs = new FileStream(filePath, FileMode.Open); // byte[] bytes = new byte[(int)fs.Length]; // fs.Read(bytes, 0, bytes.Length); // fs.Close(); // Response.Charset = "UTF-8"; // Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); // Response.ContentType = "application/octet-stream"; // //解决文件名乱码问题 // Response.AddHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(fileName)); // Response.BinaryWrite(bytes); // Response.Flush(); // Response.End(); // return new EmptyResult(); //} tabcontrol中的groupBox中的radiobutton遍历问题 sql 如何替换某个字段里的空格 二维数组的问题~~ 网络编程mfc不用线程为何C#需要线程 datagrid行提针 用Ctrl+C将excel一段内容复制到剪贴板,然后把用Ctrl+V粘贴到datagrid中 如何编辑SQL命令删除数据表中的的这些记录!(急问,谢了) c# .net 2005中实现pop3收取信件 【EXCLE高手请进】C#调用EXCEL组件超慢,是什么原因? 如何获得父表某行关联的子表信息(关键是那些删除的纪录) 关于数据库连接操作方式,求给个建议! 请来个高手帮我把这两个方法转成函数,谢谢拉
if (OpenFile.ShowDialog(this) == DialogResult.OK)
{
if (MessageBox.Show("上传成功!是否设置为头像?", "成功!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
this.BackgroundImage = Image.FromFile(OpenFile.FileName);
}
不谢
//public ActionResult Upload(FormCollection form)
//{
// //1.获取文件信息
// HttpPostedFileBase file = Request.Files["file"]; // //2.判断文件大小,扩展名(可以用js实现)
// if (file.ContentLength > 1048576)
// {
// //xxxxxxxxx
// }
// //2.判断文件类型
// if (file.ContentType != "image/png" || file.ContentType != "image/gif")
// {
// //xxxxxxxxx
// //return View("Index");
// }
// if (file.FileName != null)
// {
// string serverPath = HttpContext.Server.MapPath("/Content/UploadFile");
// //2.判断文件目录是否存在
// if (!Directory.Exists(serverPath))
// {
// Directory.CreateDirectory(serverPath);
// }
// string filePath = Path.Combine(serverPath, Path.GetFileName(file.FileName));
// file.SaveAs(filePath);
// return View("Index");
// }
// else
// {
// return View();
// }
//}
//public ActionResult DownLoad()
//{
// //插件名称
// string fileName = "logo.png";
// //文件路径
// string filePath = Server.MapPath("/Content/DownloadFile/logo.png");
// FileStream fs = new FileStream(filePath, FileMode.Open);
// byte[] bytes = new byte[(int)fs.Length];
// fs.Read(bytes, 0, bytes.Length);
// fs.Close();
// Response.Charset = "UTF-8";
// Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
// Response.ContentType = "application/octet-stream";
// //解决文件名乱码问题
// Response.AddHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(fileName));
// Response.BinaryWrite(bytes);
// Response.Flush();
// Response.End();
// return new EmptyResult();
//}