Пример #1
0
    /// <summary>
    /// Upload click handler.
    /// </summary>
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (!CheckPermissions("cms.forums", PERMISSION_MODIFY))
        {
            return;
        }

        if ((upload.HasFile) && (PostInfo != null))
        {
            // Check attachment extension
            if (!ForumAttachmentInfoProvider.IsExtensionAllowed(upload.FileName, SiteContext.CurrentSiteName))
            {
                ShowError(GetString("ForumAttachment.AttachmentIsNotAllowed"));
                return;
            }

            ForumInfo fi = ForumInfoProvider.GetForumInfo(PostInfo.PostForumID);
            if (fi != null)
            {
                ForumGroupInfo fgi = ForumGroupInfoProvider.GetForumGroupInfo(fi.ForumGroupID);
                if (fgi != null)
                {
                    ForumAttachmentInfo fai = new ForumAttachmentInfo(upload.PostedFile, 0, 0, fi.ForumImageMaxSideSize);
                    fai.AttachmentPostID = PostInfo.PostId;
                    fai.AttachmentSiteID = fgi.GroupSiteID;
                    ForumAttachmentInfoProvider.SetForumAttachmentInfo(fai);

                    ReloadAttachmentData(PostInfo.PostId);
                    UniGrid.ReloadData();
                }
            }
        }
    }
Пример #2
0
    /// <summary>
    /// Upload click hadler.
    /// </summary>
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (!CheckPermissions("cms.forums", CMSAdminControl.PERMISSION_MODIFY))
        {
            return;
        }

        if ((upload.HasFile) && (this.PostInfo != null))
        {
            // Check attachment extension
            if (!ForumAttachmentInfoProvider.IsExtensionAllowed(upload.FileName, CMSContext.CurrentSiteName))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("ForumAttachment.AttachmentIsNotAllowed");
                return;
            }

            ForumInfo fi = ForumInfoProvider.GetForumInfo(this.PostInfo.PostForumID);
            if (fi != null)
            {
                ForumGroupInfo fgi = ForumGroupInfoProvider.GetForumGroupInfo(fi.ForumGroupID);
                if (fgi != null)
                {
                    ForumAttachmentInfo fai = new ForumAttachmentInfo(upload.PostedFile, 0, 0, 0);
                    fai.AttachmentPostID = this.PostInfo.PostId;
                    fai.AttachmentSiteID = fgi.GroupSiteID;
                    ForumAttachmentInfoProvider.SetForumAttachmentInfo(fai);

                    ReloadAttachmentData(this.PostInfo.PostId);
                    UniGrid.ReloadData();
                }
            }
        }
    }
Пример #3
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;
                }
            }
        }
    }