首页 > Windows开发 > 详细

.net C# FileUpload控件上传

时间:2015-01-08 20:14:46      阅读:170      评论:0      收藏:0      [点我收藏+]

代码

/// <summary>
        ///  保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnPro_Click(object sender, EventArgs e)
        {
            if (Session["User"] != null)
            {
			  try
                {
					string Imgfile = string.Empty;
					if (FileUpload_ProductImg.HasFile)
					{
						string path = Server.MapPath("~/mImages/ProductUploadFile/");
						Imgfile = "mImages/ProductUploadFile/";
						//拼接文件的名称
						//DirectoryInfo dir = new DirectoryInfo(path);
						//文件名由文件夹中文件的数量和后缀组成
						//string name = dir.GetFiles().Length + Path.GetExtension(FileUpload_ProductImg.FileName);
						string name = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + Path.GetExtension(FileUpload_ProductImg.FileName);
						Imgfile = Imgfile + name;
						FileUpload_ProductImg.PostedFile.SaveAs(path + name);
					}else
					{
					 Page.ClientScript.RegisterStartupScript(this.GetType(), "", @"<script>alert('没有选择文件,请先选择文件!');location.href='NewsContentList.aspx';</script>");
                    return;
					}
                }
                catch (Exception)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "", @"<script>alert('上传失败,请联系管理员!');location.href='NewsContentList.aspx';</script>");
                    return;
                }
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", @"<script>alert('登入超时!');location.href='Login.aspx';</script>");
                return;
            }
        }


.net C# FileUpload控件上传

原文:http://blog.csdn.net/chinaplan/article/details/42527845

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!