Пример #1
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="file"></param>
        /// <param name="ClassID"></param>
        /// <returns></returns>
        public static Result UpLoadFile(HttpPostedFile file, int ClassID)
        {
            Result     r  = new Result();
            SysSetting ss = BasePage.SystemSetting;

            string FileName = file.FileName.GetFileNameFromPath();    //文件名
            string ExtName  = file.FileName.GetFileExtNameFromPath(); //扩展名
            string NewName  = @string.GetGuid() + ExtName;            //新文件名

            if (!ExtName.Replace(".", "").IsInArray(ss.FileExtNameFilter.Split(',')))
            {
                r.Success = false;
                r.Text    = "不允许上传此类文件";
                return(r);
            }
            if (file.ContentLength > ss.MaxPostFileSize)
            {
                r.Success = false;
                r.Text    = "文件太大";
                return(r);
            }

            string Folder        = ss.FileDir + "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/"; //文件目录
            string FolderShotCut = Folder + "ShortCut/";                                         //缩略图目录

            string FilePath          = Folder + NewName;                                         //文件路径
            string FilePath_ShortCut = FolderShotCut + NewName;                                  //缩略图路径

            file.SaveAs(System.Web.HttpContext.Current.Server.MapPath(FilePath), true);

            Voodoo.Model.File f = new Voodoo.Model.File();

            if (ExtName.ToLower().Replace(".", "").IsInArray("jpg,jpeg,png,gif,bmp".Split(',')))
            {
                ImageHelper.MakeThumbnail(System.Web.HttpContext.Current.Server.MapPath(FilePath), System.Web.HttpContext.Current.Server.MapPath(FilePath_ShortCut), 105, 118, "Cut");
            }
            else
            {
                FilePath_ShortCut = "";
                f.FileType        = 1;
            }
            FileInfo savedFile = new FileInfo(System.Web.HttpContext.Current.Server.MapPath(FilePath));



            f.FileDirectory = ss.FileDir;
            f.FileExtName   = ExtName;
            f.FilePath      = FilePath;
            f.FileSize      = (savedFile.Length / 1024).ToInt32();
            //f.FileType=
            f.SmallPath = FilePath_ShortCut;
            f.UpTime    = DateTime.Now;


            FileView.Insert(f);

            r.Success = true;
            r.Text    = FilePath;
            return(r);
        }
Пример #2
0
        protected void btn_Save_Click(object sender, EventArgs e)
        {
            User      u = UserAction.opuser;
            UserGroup g = UserGroupView.GetModelByID(u.Group.ToS());

            if (FileUpload1.FileName.IsNullOrEmpty())
            {
                Js.AlertAndGoback("为提高您文章的排名,请选择一张标题图片");
                return;
            }

            #region    图片
            SysSetting ss = BasePage.SystemSetting;

            HttpPostedFile file     = Request.Files["FileUpload1"];
            string         FileName = file.FileName.GetFileNameFromPath();    //文件名
            string         ExtName  = file.FileName.GetFileExtNameFromPath(); //扩展名
            string         NewName  = @string.GetGuid() + ExtName;            //新文件名

            if (!ExtName.Replace(".", "").IsInArray(ss.FileExtNameFilter.Split(',')))
            {
                Js.AlertAndGoback("不允许上传此类文件");
                return;
            }
            if (file.ContentLength > ss.MaxPostFileSize)
            {
                Js.AlertAndGoback("文件太大");
                return;
            }

            string Folder        = ss.FileDir + "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/"; //文件目录
            string FolderShotCut = Folder + "ShortCut/";                                         //缩略图目录

            string FilePath          = Folder + NewName;                                         //文件路径
            string FilePath_ShortCut = FolderShotCut + NewName;                                  //缩略图路径

            file.SaveAs(Server.MapPath(FilePath), true);
            ImageHelper.MakeThumbnail(Server.MapPath(FilePath), Server.MapPath(FilePath_ShortCut), 105, 118, "Cut");



            FileInfo savedFile = new FileInfo(Server.MapPath(FilePath));

            Voodoo.Model.File f = new Voodoo.Model.File();

            f.FileDirectory = ss.FileDir;
            f.FileExtName   = ExtName;
            f.FilePath      = FilePath;
            f.FileSize      = (savedFile.Length / 1024).ToInt32();
            //f.FileType=
            f.SmallPath = FilePath_ShortCut;
            f.UpTime    = DateTime.Now;

            FileView.Insert(f);
            #endregion


            News n = new News();
            n.Author      = txt_Author.Text.TrimDbDangerousChar();
            n.AutorID     = UserAction.opuser.ID;
            n.ClassID     = ddl_Class.SelectedValue.ToInt32();
            n.ClickCount  = 0;
            n.Content     = txt_Content.Text.TrimDbDangerousChar();
            n.Description = txt_Description.Text.TrimDbDangerousChar();
            n.DownCount   = 0;
            n.EnableReply = false;
            n.FTitle      = txtFtitle.Text.TrimDbDangerousChar();
            n.KeyWords    = txt_Keyword.Text.TrimDbDangerousChar();
            n.ModelID     = 0;
            n.NavUrl      = "";
            n.NewsTime    = DateTime.Now;
            n.SetTop      = false;
            n.Source      = txt_Source.Text.TrimDbDangerousChar();
            n.Title       = txt_Title.Text.TrimDbDangerousChar();
            n.TitleColor  = "000";
            n.TitleImage  = FilePath;//上传图片
            n.ZtID        = 0;
            n.Audit       = g.PostAotuAudit;
            n.FileForder  = DateTime.Now.ToString("yyyy-MM-dd");

            n.ID = WS.RequestInt("id");

            Result r = NewsAction.UserPost(n, UserAction.opuser);

            if (r.Success)
            {
                Js.AlertAndChangUrl(r.Text, "PostList.aspx");
            }
            else
            {
                Js.AlertAndGoback(r.Text);
            }
        }