コード例 #1
0
        public void addTeacher()
        {
            try
            {
                Teacher Teacher = new Teacher();
                setValue(Teacher, context);

                HttpPostedFile hpf = context.Request.Files["headImgFile"];
                if (hpf != null)
                {
                    string serverPath = "/uploadFile/headImg/" + System.DateTime.Now.Ticks + "." + hpf.FileName.Split('.')[1];
                    string savePath = context.Server.MapPath(serverPath);//路径,相对于服务器当前的路径
                    hpf.SaveAs(savePath);//保存
                    Teacher.HeadImage = serverPath;
                }

                TeacherService s = new TeacherService();
                s.save(Teacher);

                context.Response.Write("1");
            }
            catch (Exception e)
            {
                context.Response.Write("0");
            }
        }
コード例 #2
0
        public void updateTeacher()
        {
            try
            {
                Teacher Teacher = new Teacher();
                setValue(Teacher, context);

                HttpPostedFile hpf = context.Request.Files["headImgFile"];
                if (hpf != null)
                {
                    string savepath = context.Server.MapPath("/uploadFile/headImg/" + Teacher.Id + "." + hpf.GetType());//路径,相对于服务器当前的路径
                    hpf.SaveAs(savepath);//保存
                    Teacher.HeadImage = savepath;
                }

                TeacherService s = new TeacherService();
                s.save(Teacher);
                context.Response.Write("1");
            }
            catch (Exception e)
            {
                context.Response.Write("0");
            }
        }