上传文件

 //上传图片
    protected void BtnUpload_Click(object sender, EventArgs e)
    {
        //权限
        //数据获取
        //数据加工,输入、输出
        string filename = "";
        if (HiddenField_pic.Value.Trim() == "")
            filename = DateTime.Now.ToString("yyyyMMddhhmmss");
        else
            filename = HiddenField_pic.Value.Split('_')[0].ToString();
        string strd = DateTime.Now.ToString();
        if (this.FileUpload1.HasFile)
        {
            if (this.FileUpload1.PostedFile.ContentLength > 0)
            {
                //动作记录
                //正常处理
                if (!System.IO.Directory.Exists("D://88gogo//system//uploadpic//news"))
                {
                    System.IO.Directory.CreateDirectory("D://88gogo//system//uploadpic//news");
                }

                this.FileUpload1.PostedFile.SaveAs("D://88gogo//system//uploadpic//news//" + filename);
                HiddenField_pic.Value = filename;
                img.ImageUrl = "D://88gogo//system//uploadpic//news//" + HiddenField_pic.Value;
                img.Visible = true;
            }
        }
    }

你可能感兴趣的:(上传文件)