Esempio n. 1
0
        protected void ArticlesAddBtn_Click(object sender, EventArgs e)
        {
            NewArticleModel model = new NewArticleModel();
            // model.
            CMSService mycms = new CMSService();
            //string _Pic=string.Empty;
            //if (!string.IsNullOrEmpty(ImgName))
            //{
            //    _Pic = ImgName;
            //}
            string body = Request.Form["editorcontent"];

            //if (Utils.Utils.GetHtmlImageUrlList(body).Length > 0)
            //{
            //    string k = Utils.Utils.GetHtmlImageUrlList(body)[0].Replace("/FLYUpload/Images/","");
            //    model.ImgName =k;
            //}
            //else
            //{
            //    model.ImgName = string.Empty;
            //}

            string[] k = FBS.Utils.Utils.GetHtmlImageUrlList(body);

            int    point = 0;
            string url   = "";

            if (k.Length > 0)
            {
                foreach (string y in k)
                {
                    if (!y.Contains("/plugins/emoticons/"))//表情
                    {
                        url = y;
                        break;
                    }
                    point++;
                }
                if (point == k.Length)
                {
                    model.ImgName = string.Empty;
                }
                else
                {
                    if (url.Contains("FLYUpload/Images/"))
                    {
                        model.ImgName = FBS.Utils.Utils.GetHtmlImageUrlList(body)[point];
                    }
                    else
                    {
                        //网络图片
                        try
                        {
                            //String fileExt = Path.GetExtension(url).ToLower();
                            //System.Drawing.Image tempimage = System.Drawing.Bitmap.FromFile(url);
                            //string filename = "/FLYUpload/Images/" + Guid.NewGuid().ToString() + fileExt;
                            //tempimage.Save(filename);
                            //tempimage.Dispose();

                            model.ImgName = url;
                        }
                        catch (Exception ee)
                        {
                            model.ImgName = string.Empty;
                        }
                    }
                }
            }
            else
            {
                model.ImgName = string.Empty;
            }



            model.Title        = ArticleTitle.Text.ToString().Trim();
            model.Body         = body;
            model.CategoryID   = new Guid(ArticleCategory.SelectedItem.Value);
            model.CategoryName = ArticleCategory.SelectedItem.Text.ToString().Replace("┣", "").Replace("-", "");
            model.SourceSite   = ArticleWeb.Text.ToString().Trim();
            model.SourceUrl    = ArticleLink.Text.ToString().Trim();
            model.BriefTitle   = ArticleBriefTitle.Text.ToString().Trim();
            //从cookie获取用户名及用户的ID
            HttpCookie hc = Request.Cookies[FormsAuthentication.FormsCookieName];
            FormsAuthenticationTicket fat = FormsAuthentication.Decrypt(hc.Value);

            model.UserID   = new Guid(fat.Name);
            model.UserName = fat.UserData;
            mycms.CreateArticle(model);
            //Response.Redirect("ArticlesList.aspx?Type='add'");
            Response.Write("<script>alert('添加成功')</script>");
        }