当前位置:编程学习 > C#/ASP.NET >>

求指教,怎么在form窗体中可以选择上传图片并且显示为头像

  。。。急需要这个功能, --------------------编程问答-------------------- 如果是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();
        //}
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,