码迷,mamicode.com
首页 > Windows程序 > 详细

.net C# FileUpload控件上传

时间:2015-01-08 20:16:35      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:.net   c#   fileupload控件   上传   

代码

/// <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控件上传

标签:.net   c#   fileupload控件   上传   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!