using System; using System.Data; using System.Collections; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using CMS.Forums; using CMS.GlobalHelper; public partial class CMSModules_Forums_Controls_AttachmentDisplayer : ForumViewer { private int mPostID = 0; private int mPostAttachmentCount = 0; protected string mAttachmentSeparator = " "; #region "Public variables" /// /// Gets or sets ID of forum posts. /// public int PostID { get { return ValidationHelper.GetInteger(ViewState["AttachmentDisplayer_PostID"], mPostID); } set { if (value > 0) { ViewState["AttachmentDisplayer_PostID"] = value; mPostID = value; } } } /// /// Gets or sets attachments count. /// public int PostAttachmentCount { get { return ValidationHelper.GetInteger(ViewState["AttachmentDisplayer_PostAttachmentCount"], mPostAttachmentCount); } set { if (value > 0) { ViewState["AttachmentDisplayer_PostAttachmentCount"] = value; mPostAttachmentCount = value; } } } /// /// Gets or sets the attachment separator. /// public string AttachmentSeparator { get { return mAttachmentSeparator; } set { mAttachmentSeparator = value; } } #endregion /// /// OnPreRender reload data. /// protected override void OnPreRender(EventArgs e) { ReloadData(); } /// /// Returns HTML code with link to attachment. /// /// Attachment file name /// Attachment GUID protected string GetAttachmentLink(object data) { // try retype data as datarow view DataRowView drv = data as DataRowView; if (drv != null) { string guid = ValidationHelper.GetString(drv.Row["AttachmentGUID"], ""); string name = HTMLHelper.HTMLEncode(ValidationHelper.GetString(drv.Row["AttachmentFileName"], "")); string mime = ValidationHelper.GetString(drv.Row["AttachmentMimeType"], ""); string url = ResolveUrl("~/CMSModules/Forums/CMSPages/GetForumAttachment.aspx?fileguid=" + guid); if (DisplayAttachmentImage && ImageHelper.IsMimeImage(mime)) { return "" + "\"""; } else { return "" + name + ""; } } return ""; } public override void ReloadData() { // Try to copy forum viewer properties from parent CopyValuesFromParent(this); // Retrieve from DB only if post has some attachments if ((PostAttachmentCount > 0) && ((PostID > 0))) { ltlHeader.Text = GetString("forums.postattachments"); DataSet ds = ForumAttachmentInfoProvider.GetForumAttachments(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(); } /// /// Clear viewestate data. /// public void ClearData() { ViewState["AttachmentDisplayer_PostID"] = null; ViewState["AttachmentDisplayer_PostAttachmentCount"] = null; } }