图片上传

图片上传
<asp:FileUpload ID="fuIcon" runat="server" />

protected void Button1_Click(object sender, EventArgs e)
    {
        Dqt.Reporter.Model.school schoolModel = new Dqt.Reporter.Model.school();
        if (fuIcon.HasFile)
        {
            string fileExt = System.IO.Path.GetExtension(fuIcon.FileName).ToLower().ToLower();
            if (fileExt == ".jpg" || fileExt == ".ico" || fileExt == ".png" || fileExt == ".gif")
            {
                string path = "/UploadFile/" + DateTime.Now.ToString("yyyy_MM") + "/";
                string cata = Server.MapPath(path);
                try
                {
                    if (!System.IO.Directory.Exists(cata))
                    {
                        System.IO.Directory.CreateDirectory(cata);
                    }
                    string picName = DateTime.Now.ToString("ddHHmmss_") + MFunction.GetRandomStringHaveNum(4) + "_y" + fileExt;
                    schoolModel.Icon = path + picName;
                    fuIcon.SaveAs(cata + picName);
                    System.Drawing.Image upImg = System.Drawing.Image.FromStream(fuIcon.PostedFile.InputStream);
                    Dqt.Reporter.Common.ThumbImg.MakeThumbnail(cata + picName, Server.MapPath(path + picName.Replace("_y", "_200x130")), 200,130, "HW", fileExt, "");
                }
                catch (Exception ex)
                {
                    jsHint.toUrl("发生错误:" + ex.Message.ToString(), "OfficialWorksAdd.aspx");
                    return;
                }
            }
            else
            {
                jsHint.toUrl("只允许上传JPG,png或GIF或ICO格式的文件!", "OfficialWorksAdd.aspx");
                return;
            }
        }
        else
        {
            schoolModel.Icon = "";
        }
schoolModel.ManageId = int.Parse(this.TxtManageId.Text.Trim());
        schoolModel.ManegeName = this.TxtManegeName.Text.Trim();
        schoolModel.NewNums = int.Parse(this.TxtNewNums.Text.Trim());
        schoolModel.Address = this.TxtAddress.Text.Trim();
        schoolModel.GuideTeacher = this.TxtGuideTeacher.Text.Trim();
        schoolModel.GTid = int.Parse(this.TxtGTid.Text.Trim());
        if (schoolBLL.Add(schoolModel))
        {
            Dqt.Reporter.Common.jsHint.Refresh("记录被成功添加");
            SchoolInstance.Instance.Dispose();
        }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值