您目前尚未登陆,请选择【登陆】或【注册
首页->博客论坛->SpaceBuilder v1.1源代码>>BlogControls/Admin/ManageAttachments.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:SpaceBuilder v1.1源代码
当前文件:文件类型 SpaceBuider11/BlogControls/Admin/ManageAttachments.cs打开代码结构图
普通视图
		            
1//------------------------------------------------------------------------------ 2// <copyright company="Tunynet"> 3// Copyright (c) Tunynet Inc. All rights reserved. 4// </copyright> 5//------------------------------------------------------------------------------ 6 7using System; 8using System.Collections.Generic; 9using System.Text; 10using SpaceBuilder.Components; 11using SpaceBuilder.Controls.Utils; 12using System.Web.UI.WebControls; 13using SpaceBuilder.Posts.Components; 14using SpaceBuilder.Blogs.Components; 15using SpaceBuilder.Blogs.Configuration; 16using TunyNet.Utils; 17 18namespace SpaceBuilder.Blogs.Controls 19{ 20 /// <summary> 21 /// 管理博客中的附件 22 /// </summary> 23 public class ManageAttachments : WeblogAdminThemedControl 24 { 25 SBContext wlContext = SBContext.Current; 26 27 protected override void OnInit(EventArgs e) 28 { 29 if (SkinName == null) 30 SkinName = "Skin-ManageAttachments.ascx"; 31 32 wlContext = SBContext.Current; 33 base.OnInit(e); 34 //this.EnableViewState = false; 35 } 36 Child Controls 47 protected override void AttachChildControls() 48 { 49 addBlogAttachments = FindControl("AddBlogAttachments") as ModalLink; 50 postListRepeater = FindControl("PostListRepeater") as Repeater; 51 52 if (postListRepeater != null) 53 { 54 postListRepeater.ItemDataBound += new RepeaterItemEventHandler(postListRepeater_ItemDataBound); 55 postListRepeater.ItemCommand += new RepeaterCommandEventHandler(postListRepeater_ItemCommand); 56 } 57 if (addBlogAttachments != null) 58 { 59 addBlogAttachments.Url = BlogUrls.Instance().UploadBlogAttachment(CurrentWeblog.ApplicationKey); 60 } 61 } 62 63 protected override void OnLoad(EventArgs e) 64 { 65 base.OnLoad(e); 66 EnsureChildControls(); 67 RefreshJavaScript.RegisterRefresh(this.Page); 68 if (!Page.IsPostBack) 69 Bind(); 70 } 71 72 void Bind() 73 { 74 List<PostAttachment> attachments = PostAttachments.GetPostAttachtmentMetaDatasBySectionID(CurrentWeblog.SectionID, ApplicationType.Blog); 75 if (attachments != null && attachments.Count > 0) 76 { 77 postListRepeater.DataSource = attachments; 78 postListRepeater.DataBind(); 79 } 80 } 81 82 void postListRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) 83 { 84 if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 85 { 86 PostAttachment attachment = e.Item.DataItem as PostAttachment; 87 if (attachment != null) 88 { 89 HyperLink title = e.Item.FindControl("Title") as HyperLink; 90 if (title != null) 91 { 92 title.Text = StringUtils.Trim(attachment.FriendlyFileName, 30); 93 title.ToolTip = attachment.FriendlyFileName; 94 title.NavigateUrl = WeblogConfiguration.Instance().AttachmentSettings.DirectPath(attachment); 95 } 96 Literal size = e.Item.FindControl("Size") as Literal; 97 if (size != null) 98 { 99 size.Text = string.Format("{0}K", Math.Round(Convert.ToDouble(attachment.Length) / 1024, 2)); 100 101 } 102 Literal pubDate = e.Item.FindControl("PubDate") as Literal; 103 if (pubDate != null) 104 { 105 pubDate.Text = Convert.ToString(attachment.CreateDate); 106 } 107 ImageButton delete = e.Item.FindControl("Delete") as ImageButton; 108 if (delete != null) 109 { 110 delete.CommandArgument = attachment.AttachmentID.ToString(); 111 delete.Attributes["onclick"] = "if(!confirm('确认要删除此附件吗?')){return false;}"; 112 } 113 Literal blogAttachmentPrefix = e.Item.FindControl("BlogAttachmentPrefix") as Literal; 114 if (blogAttachmentPrefix != null) 115 { 116 //blogAttachmentPrefix.Text = WeblogConfiguration.Instance().AttachmentSettings.GetImageThumbnail(attachment, 15, CurrentWeblog.ApplicationKey); 117 blogAttachmentPrefix.Text = WeblogConfiguration.Instance().AttachmentSettings.PreviewHTML(attachment, CurrentWeblog.ApplicationKey, FileThumbnailSize.Small); 118 } 119 } 120 } 121 } 122 123 void postListRepeater_ItemCommand(object source, RepeaterCommandEventArgs e) 124 { 125 switch (e.CommandName) 126 { 127 case "Delete": 128 int attachmentID = int.Parse((string)e.CommandArgument); 129 PostAttachmentMetaData pa = PostAttachments.GetPostAttachtmentMetaData(attachmentID, ApplicationType.Blog); 130 if (pa != null) 131 { 132 WeblogConfiguration.Instance().AttachmentSettings.DeleteAttachmentFromDisk(pa); 133 PostAttachments.Delete(int.Parse((string)e.CommandArgument), ApplicationType.Blog); 134 Bind(); 135 } 136 break; 137 } 138 } 139 } 140} 141
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:SpaceBuilder v1.1源代码