Ejemplo n.º 1
0
    private void UploadAtt()
    {
        HtmlForm FrmCompose     = (HtmlForm)this.Page.FindControl("NewItem");
        Random   TempNameInt    = new Random();
        string   NewMailDirName = TempNameInt.Next(100000000).ToString();

        string SavePath = ConfigHelper.GetConfigString("AttachmentPath");

        if (string.IsNullOrEmpty(SavePath))
        {
            SavePath = "~/Attachment/";
        }
        if (!SavePath.EndsWith("/") && !SavePath.EndsWith("\\"))
        {
            SavePath += "/";
        }

        // 存放附件至提交人目录中,随机生成目录名
        SavePath += "BBS/TMP/" + NewMailDirName + "/" + Session["UserName"].ToString();
        String MapSavePath = "";

        if (SavePath.StartsWith("~"))
        {
            MapSavePath = Server.MapPath(SavePath);
        }
        else
        {
            MapSavePath = SavePath;
        }
        MapSavePath = MapSavePath.Replace("/", "\\");

        Directory.CreateDirectory(MapSavePath);
        ViewState["SavePath"] = MapSavePath;

        ArrayList upattlist = (ArrayList)ViewState["UpattList"];

        if (hif.PostedFile.FileName.Trim() != "")
        {
            string FileName = System.IO.Path.GetFileName(hif.PostedFile.FileName);
            hif.PostedFile.SaveAs(MapSavePath + "/" + FileName);

            string[]            attfile = FileName.Split('.');
            BBS_ForumAttachment att     = new BBS_ForumAttachment();
            att.Reply = 0;                    //不属于某个回复默认设置为0
            att.Name  = attfile[0];
            att.Path  = SavePath + "/" + FileName;
            if (attfile.Length > 1)
            {
                att.ExtName = attfile[attfile.Length - 1];
            }
            att.FileSize   = hif.PostedFile.ContentLength;
            att.UploadTime = DateTime.Now;

            if (upattlist == null)
            {
                upattlist = new ArrayList();
            }
            upattlist.Add(att);
        }
        ViewState["UpattList"] = upattlist;
        BindAttList();
    }
Ejemplo n.º 2
0
    protected void btn_OK_Click(object sender, EventArgs e)
    {
        #region 帖子的回复

        #region 添加帖子的回复
        BBS_ForumReplyBLL replybll = new BBS_ForumReplyBLL();
        replybll.Model.ItemID    = Convert.ToInt32(ViewState["ItemID"]);
        replybll.Model.Title     = Title.Value;
        replybll.Model.Content   = ckedit_content.Text;
        replybll.Model.Replyer   = Session["UserName"].ToString();
        replybll.Model.ReplyTime = DateTime.Now;
        replybll.Model.IPAddress = Request.ServerVariables.Get("REMOTE_ADDR").ToString();
        int replyid = replybll.Add();    // 返回已经回复的帖子的ID

        //修改论坛文章的留言量
        BBS_ForumItemBLL itembll = new BBS_ForumItemBLL(Convert.ToInt32(ViewState["ItemID"]));
        itembll.UpdateAddReplyTimes(Convert.ToInt32(ViewState["ItemID"]));
        #endregion

        #region 添加留言的附件
        ArrayList upattlist = (ArrayList)ViewState["UpattList"];
        if (upattlist != null && upattlist.Count > 0)
        {
            foreach (BBS_ForumAttachment att in upattlist)
            {
                string path = att.Path;
                if (path.StartsWith("~"))
                {
                    path = Server.MapPath(path);
                }
                FileStream stream = new FileStream(path, FileMode.Open);
                byte[]     buff   = new byte[stream.Length];
                stream.Read(buff, 0, buff.Length);
                stream.Close();
                att.Path   = "";
                att.ItemID = (int)ViewState["ItemID"];

                #region 自动压缩上传的图片
                if (ATMT_AttachmentBLL.IsImage(att.ExtName))
                {
                    try
                    {
                        MemoryStream         s             = new MemoryStream(buff);
                        System.Drawing.Image originalImage = System.Drawing.Image.FromStream(s);
                        s.Close();

                        int width = originalImage.Width;

                        if (width > 1024 || att.ExtName == "bmp")
                        {
                            if (width > 1024)
                            {
                                width = 1024;
                            }

                            System.Drawing.Image thumbnailimage = ImageProcess.MakeThumbnail(originalImage, width, 0, "W");

                            MemoryStream thumbnailstream = new MemoryStream();
                            thumbnailimage.Save(thumbnailstream, System.Drawing.Imaging.ImageFormat.Jpeg);
                            thumbnailstream.Position = 0;
                            att.FileSize             = (int)(thumbnailstream.Length / 1024);
                            att.ExtName = "jpg";

                            byte[] b = new byte[thumbnailstream.Length];
                            thumbnailstream.Read(b, 0, b.Length);
                            thumbnailstream.Close();
                            buff = b;
                        }
                    }
                    catch { }
                }
                #endregion

                att.Reply = replyid;
                BBS_ForumAttachmentBLL bll = new BBS_ForumAttachmentBLL();
                bll.Model = att;
                bll.Add(buff);

                BBS_ForumAttachment m = bll.Model;
                string uploadcontent  = "";    //插入主表中

                switch (att.ExtName.ToLower())
                {
                case "jpg":
                case "gif":
                case "bmp":
                case "png":
                    uploadcontent = " [IMG]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/IMG]<br/>";
                    break;

                case "mp3":
                    uploadcontent = " [MP=320,70]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/MP]<br/>";
                    break;

                case "avi":
                    uploadcontent = " [MP=320,240]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/MP]<br/>";
                    break;

                case "swf":
                    uploadcontent = " [FLASH]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/FLASH]<br/>";
                    break;

                default:
                    uploadcontent = "<a href=DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + ">" + att.Name + "." + att.ExtName + "</a><br/>";
                    break;
                }
                ViewState["Content"] += uploadcontent + "<br/>";
            }

            if (ViewState["SavePath"] != null)
            {
                try
                {
                    string path = (string)ViewState["SavePath"];
                    path = path.Substring(0, path.LastIndexOf("\\"));
                    Directory.Delete(path, true);
                    ViewState["SavePath"] = null;
                }
                catch { }
            }

            //将附件的路径添加到回复主表中去
            replybll.Model.Content += "<br/><font color=red><b>附件列表:</b></font><br/>" + ViewState["Content"].ToString();
            replybll.Update();

            //清空附件的列表
            for (int i = upattlist.Count - 1; i >= 0; i--)
            {
                this.lbx_AttList.Items.RemoveAt(i);
                upattlist.RemoveAt(i);
            }
            ViewState["UpattList"] = upattlist;
        }
        #endregion

        #endregion

        Response.Redirect("display.aspx?ID=" + ViewState["ItemID"].ToString() + "&BoardID=" + ViewState["BoardID"].ToString());
    }
Ejemplo n.º 3
0
    protected void cmdOK_ServerClick(object sender, System.EventArgs e)
    {
        #region 添加论文的主题内容
        BBS_ForumItemBLL itembll = new BBS_ForumItemBLL();
        itembll.Model.Board         = Convert.ToInt32(ViewState["BoardID"]);
        itembll.Model.Title         = Title.Value;
        itembll.Model.Content       = ckedit_content.Text;
        itembll.Model.Sender        = Session["UserName"].ToString();
        itembll.Model.SendTime      = DateTime.Now;
        itembll.Model.HitTimes      = 0;                                   //点击次数默认的设置为0
        itembll.Model.ReplyTimes    = 0;                                   //回复次数默认的设置为0
        itembll.Model.LastReplyer   = Session["UserName"].ToString();      //默认的设置为本人
        itembll.Model.LastReplyTime = DateTime.Now;
        itembll.Model.IPAddr        = Request.ServerVariables.Get("REMOTE_ADDR").ToString();

        itembll.Model["IsTop"]  = "N"; //是否置顶
        itembll.Model["IsPith"] = "N"; //是否是精贴

        int itemid = itembll.Add();    // 返回已经发布的论文的ID
        #endregion

        #region 添加论文的附件
        ArrayList upattlist = (ArrayList)ViewState["UpattList"];
        if (upattlist != null && upattlist.Count > 0)
        {
            string _content = "<br/><font color=red><b>附件列表:</b></font><br/>";

            foreach (BBS_ForumAttachment att in upattlist)
            {
                string path = att.Path;
                if (path.StartsWith("~"))
                {
                    path = Server.MapPath(path);
                }
                FileStream stream = new FileStream(path, FileMode.Open);
                byte[]     buff   = new byte[stream.Length];
                stream.Read(buff, 0, buff.Length);
                stream.Close();
                att.Path   = "";
                att.ItemID = itemid;

                #region 自动压缩上传的图片
                if (ATMT_AttachmentBLL.IsImage(att.ExtName))
                {
                    try
                    {
                        MemoryStream         s             = new MemoryStream(buff);
                        System.Drawing.Image originalImage = System.Drawing.Image.FromStream(s);
                        s.Close();

                        int width = originalImage.Width;

                        if (width > 1024 || att.ExtName == "bmp")
                        {
                            if (width > 1024)
                            {
                                width = 1024;
                            }

                            System.Drawing.Image thumbnailimage = ImageProcess.MakeThumbnail(originalImage, width, 0, "W");

                            MemoryStream thumbnailstream = new MemoryStream();
                            thumbnailimage.Save(thumbnailstream, System.Drawing.Imaging.ImageFormat.Jpeg);
                            thumbnailstream.Position = 0;
                            att.FileSize             = (int)(thumbnailstream.Length / 1024);
                            att.ExtName = "jpg";

                            byte[] b = new byte[thumbnailstream.Length];
                            thumbnailstream.Read(b, 0, b.Length);
                            thumbnailstream.Close();
                            buff = b;
                        }
                    }
                    catch { }
                }
                #endregion

                BBS_ForumAttachmentBLL bll = new BBS_ForumAttachmentBLL();
                bll.Model = att;
                bll.Add(buff);

                BBS_ForumAttachment m = bll.Model;
                string _uploadcontent = "";     //插入主表中

                switch (att.ExtName.ToLower())
                {
                case "jpg":
                case "gif":
                case "bmp":
                case "png":
                    _uploadcontent = " [IMG]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/IMG]<br/>";
                    break;

                case "mp3":
                    _uploadcontent = " [MP=320,70]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/MP]<br/>";
                    break;

                case "avi":
                    _uploadcontent = " [MP=320,240]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/MP]<br/>";
                    break;

                case "swf":
                    _uploadcontent = " [FLASH]DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + "[/FLASH]<br/>";
                    break;

                default:
                    _uploadcontent = "<a href=DownloadAttachfile.aspx?GUID=" + m.GUID.ToString() + ">" + att.Name + "." + att.ExtName + "</a><br/>";
                    break;
                }
                _content += _uploadcontent + "<br/>";
            }

            if (ViewState["SavePath"] != null)
            {
                try
                {
                    string path = (string)ViewState["SavePath"];
                    path = path.Substring(0, path.LastIndexOf("\\"));
                    Directory.Delete(path, true);
                    ViewState["SavePath"] = null;
                }
                catch { }
            }

            //将附件的路径添加到发帖主表中去
            itembll.Model.Content += _content;
            itembll.Update();

            //清空附件的列表
            for (int i = upattlist.Count - 1; i >= 0; i--)
            {
                upattlist.RemoveAt(i);
            }
            ViewState["UpattList"] = upattlist;
        }
        #endregion

        Server.Transfer("listview.aspx?Board=" + ViewState["BoardID"].ToString());
    }