예제 #1
0
    public override void ReloadData()
    {
        // Try to copy forum viewer properties from parent
        CopyValuesFromParent(this);

        // Retrieve from DB only if post has some attachments
        if ((this.PostAttachmentCount > 0) && ((this.PostID > 0)))
        {
            ltlHeader.Text = GetString("forums.postattachments");

            DataSet ds = ForumAttachmentInfoProvider.GetForumAttachments(this.PostID, false);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                rptAttachments.DataSource = ds;
                rptAttachments.DataBind();
                plcPostAttachments.Visible = true;
            }
        }
        // Hide if there is no attachment
        else
        {
            plcPostAttachments.Visible = false;
        }

        base.ReloadData();
    }
예제 #2
0
    /// <summary>
    /// Handles file upload.
    /// </summary>
    protected void btnUpload_OnClick(object sender, EventArgs e)
    {
        if (ForumContext.CurrentForum == null)
        {
            return;
        }

        // Check permissions
        if (!this.IsAvailable(ForumContext.CurrentForum, ForumActionType.Attachment))
        {
            lblError.Visible = true;
            lblError.Text    = GetString("ForumNewPost.PermissionDenied");
            return;
        }

        if (fileUpload.HasFile)
        {
            // Check max attachment size
            if ((ForumContext.CurrentForum.ForumAttachmentMaxFileSize > 0) && ((fileUpload.PostedFile.InputStream.Length / 1024) >= ForumContext.CurrentForum.ForumAttachmentMaxFileSize))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("ForumAttachment.AttachmentIsTooLarge");
                return;
            }

            // Check attachment extension
            if (!ForumAttachmentInfoProvider.IsExtensionAllowed(fileUpload.FileName, this.SiteName))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("ForumAttachment.AttachmentIsNotAllowed");
                return;
            }

            ForumAttachmentInfo attachmentInfo = new ForumAttachmentInfo(fileUpload.PostedFile, 0, 0, ForumContext.CurrentForum.ForumImageMaxSideSize);
            attachmentInfo.AttachmentPostID = ForumContext.CurrentPost.PostId;
            ForumGroupInfo fgi = ForumGroupInfoProvider.GetForumGroupInfo(ForumContext.CurrentForum.ForumGroupID);
            if (fgi != null)
            {
                attachmentInfo.AttachmentSiteID = fgi.GroupSiteID;

                //Save to DB
                ForumAttachmentInfoProvider.SetForumAttachmentInfo(attachmentInfo);
                DataSet ds = ForumAttachmentInfoProvider.GetForumAttachments(ForumContext.CurrentPost.PostId, false);
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    listAttachment.DataSource = ds;
                    listAttachment.DataBind();
                    plcListHeader.Visible = true;
                }
            }
        }
    }
예제 #3
0
    /// <summary>
    /// Page load.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "DeleteConfirmation", ScriptHelper.GetScript(
                                                   "function DeleteConfirm() { return confirm(" + ScriptHelper.GetString(GetString("forums.attachment.deleteconfirmation")) + "); } "));

        if ((ForumContext.CurrentPost != null) && (ForumContext.CurrentPost.PostId > 0))
        {
            btnUpload.Text = GetString("general.upload");
            btnBack.Text   = GetString("general.back");

            if (ForumContext.CurrentForum != null)
            {
                if (ForumContext.CurrentForum.ForumAttachmentMaxFileSize > 0)
                {
                    lblInfo.Text    = GetString("ForumAttachment.MaxFileSizeInfo").Replace("##SIZE##", ForumContext.CurrentForum.ForumAttachmentMaxFileSize.ToString());
                    lblInfo.Visible = true;
                }
            }

            if (ControlsHelper.IsInUpdatePanel(this))
            {
                ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(this.btnUpload);
            }

            if (!RequestHelper.IsPostBack())
            {
                // Get post attachments
                DataSet attachments = ForumAttachmentInfoProvider.GetForumAttachments(ForumContext.CurrentPost.PostId, false);
                if (!DataHelper.DataSourceIsEmpty(attachments))
                {
                    listAttachment.DataSource = attachments;
                    listAttachment.DataBind();
                }
                else
                {
                    plcListHeader.Visible = false;
                }
            }
        }
    }