WebPage--上传下载


                //数据检查 begin
                string schType = string.Empty;//学校类型
                string gradeName = string.Empty;// 年级名称
                string subjectName = string.Empty;//科目名称  
                string videoName = this.txtName.Text.Trim();//视频名称
                string imgTrueName = string.Empty;
                schType = this.ddlSchool.SelectedValue.ToString().Trim();
                gradeName=this.ddlGrade.SelectedValue.ToString().Trim();
                subjectName = this.txtSubject.Text.Trim();
                videoName = this.txtName.Text.Trim();

                if (schType == "请选择" || gradeName == "请选择")
                {
                    Response.Write("<script>alert('请选择学校类型和年级!');</script>");
                    return;
                }
                if (subjectName=="")
                {
                    Response.Write("<script>alert('请输入视频对应的科目!');</script>");
                    return;
                }
                if (videoName == "")
                {
                    Response.Write("<script>alert('请输入视频的名称!');</script>");
                    return;
                }
                if ((this.fudFile.PostedFile.FileName == null) || (this.fudFile.PostedFile.FileName == ""))
                {
                    Response.Write("<script>alert('请选择需上传的视频文件!');</script>");
                    return;
                }
                if ((this.fudImg.PostedFile.FileName == null) || (this.fudImg.PostedFile.FileName == ""))
                {
                    Response.Write("<script>alert('请选择需上传的图片文件!');</script>");
                    return;
                }
                FileInfo fileTag = new FileInfo(this.fudFile.PostedFile.FileName);
                string fileType = fileTag.Extension;
                string fileName=fileTag.Name;// 文件物理名称
                if (fileType.ToLower() != ".flv")
                {
                    Response.Write("<script>alert('请确保您选择的是flv文件!');</script>");
                    return;
                }
                FileInfo imgFileTag = new FileInfo(this.fudImg.PostedFile.FileName);
                string imgFileType = imgFileTag.Extension;
                if (imgFileType.ToLower() != ".jpg" && imgFileType.ToLower() != ".bmp" && imgFileType.ToLower() != ".jpeg" && imgFileType.ToLower() != ".gif" && imgFileType.ToLower() != ".png")
                {
                    Response.Write("<script>alert('请确保您选择的是图片文件!');</script>");
                    return;
                }
                //数据检查 end

                //string physicalPath = this.Page.MapPath(@"./UploadFileFolder");
                string physicalPath = Server.MapPath("\\images\\UploadExperimentVideos").ToString();
                string imgPhysicalPath = Server.MapPath("\\images\\VideoImages").ToString();
                DateTime uploadTime = DateTime.Now;
                string year = DateTime.Now.Year.ToString();
                string month = DateTime.Now.Month.ToString();
                string date = DateTime.Now.Day.ToString();
                string hour = DateTime.Now.Hour.ToString();
                string minute = DateTime.Now.Minute.ToString();
                string second = DateTime.Now.Second.ToString();
                string fileTrueName ="video"+ year + month + date + hour + minute + second + fileType;//文件绝对名称
                string imgFileTrueName = "img" + year + month + date + hour + minute + second + imgFileType;//图片绝对名称
                string path_fileName = physicalPath + "/" + fileTrueName;
                string path_imgFileName = imgPhysicalPath + "/" + imgFileTrueName;

                if (File.Exists(path_fileName))
                {
                    File.Delete(path_fileName);
                }
                SqlParameter[] spl ={
                                        new SqlParameter("@schType",SqlDbType.VarChar,50), 
                                        new SqlParameter("@gradeName",SqlDbType.VarChar,50), 
                                        new SqlParameter("@subjectName",SqlDbType.VarChar,250),
                                        new SqlParameter("@videoTrueName",SqlDbType.VarChar,250),
                                        new SqlParameter("@videoName",SqlDbType.VarChar,250),
                                        new SqlParameter("@imgTrueName",SqlDbType.VarChar,250),
                                        new SqlParameter("@ret",SqlDbType.Int,4)
                                    };
                spl[0].Value = schType;
                spl[1].Value = gradeName;
                spl[2].Value = subjectName;
                spl[3].Value = fileTrueName;
                spl[4].Value = videoName;
                spl[5].Value = imgFileTrueName;
                spl[6].Direction = ParameterDirection.Output;
                Dbhelper.SQLHelper.GetDataTable("SQLCont", CommandType.StoredProcedure, spl);
                int ret=Convert.ToInt32(spl[6].Value.ToString());
                if (ret == 1)
                {
                    fudFile.PostedFile.SaveAs(path_fileName);
                    fudImg.PostedFile.SaveAs(path_imgFileName);
                    BindData();
                    Response.Write("<script>alert('视频上传成功!');</script>");
                    return;
                }
                if (ret == 3)
                {
                    Response.Write("<script>alert('视频上传重复!');</script>");
                    return;
                }
                else
                {
                    Response.Write("<script>alert('视频上传失败!');</script>");
                    return;
                }
\\按你的需求做适当修改

posted on 2012-03-08 11:52 青蛙學堂 阅读(166) 评论(0)  编辑 收藏 引用 所属分类: 軟件布袋

只有注册用户登录后才能发表评论。
<2012年3月>
26272829123
45678910
11121314151617
18192021222324
25262728293031
1234567

导航

统计

常用链接

留言簿(8)

随笔分类

随笔档案

收藏夹

青蛙学堂

最新评论

阅读排行榜

评论排行榜