您目前尚未登陆,请选择【登陆】或【注册
首页->全站代码->MyWebPages51aspx汉化最终版>>App-Code/Sections/DownloadList.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:MyWebPages51aspx汉化最终版
当前文件:文件类型 MyWebPagesStarterKit/App_Code/Sections/DownloadList.cs打开代码结构图
普通视图
		            
1//=============================================================================================== 2// 3// (c) Copyright Microsoft Corporation. 4// This source is subject to the Microsoft Permissive License. 5// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx. 6// All other rights reserved. 7// 8//=============================================================================================== 9 10using System; 11using System.Data; 12using System.Web; 13using System.Web.Services; 14using System.Web.Services.Protocols; 15using System.IO; 16using System.Collections.Generic; 17 18namespace MyWebPagesStarterKit 19{ 20 /// <summary> 21 /// Download List Section 22 /// This section displays a list of downloadable files 23 /// </summary> 24 public class DownloadList : Section<DownloadList.DownloadListData>, ISidebarObject 25 { 26 public DownloadList() 27 { 28 _data.Entries = new DataSet(); 29 _data.Entries.Tables.Add(new DataTable("DownloadListEntries")); 30 31 DataColumn primaryKeyColumn = new DataColumn("Guid", typeof(Guid)); 32 primaryKeyColumn.Unique = true; 33 34 _data.Entries.Tables["DownloadListEntries"].Columns.Add(primaryKeyColumn); 35 _data.Entries.Tables["DownloadListEntries"].PrimaryKey = new DataColumn[] { primaryKeyColumn }; 36 37 _data.Entries.Tables["DownloadListEntries"].Columns.AddRange( 38 new DataColumn[] 39 { 40 new DataColumn("Title", typeof(string)), 41 new DataColumn("Filename", typeof(string)), 42 new DataColumn("Size", typeof(string)), 43 new DataColumn("Comment", typeof(string)) 44 } 45 ); 46 } 47 48 public DownloadList(string id) : base(id) { } 49 50 public DataView GetDownloadEntries() 51 { 52 return new DataView(DownloadEntries, string.Empty, "Title ASC", DataViewRowState.CurrentRows); 53 } 54 55 public DataTable DownloadEntries 56 { 57 get { return _data.Entries.Tables["DownloadListEntries"]; } 58 } 59 60 public DataRow GetDownloadEntry(string id) 61 { 62 DataRow row = null; 63 DataRow[] foundRows = DownloadEntries.Select(string.Format("Guid = '{0}'", id)); 64 if (foundRows.Length > 0) 65 row = foundRows[0]; 66 return row; 67 } 68 69 /// <summary> 70 /// Directory to which files are uploaded 71 /// </summary> 72 public string UploadDirectory 73 { 74 get 75 { 76 string virtualdirectory = string.Format("~/App_Data/_Downloads/{0}", SectionId); 77 string physicaldirectory = HttpContext.Current.Server.MapPath(virtualdirectory); 78 if(!Directory.Exists(physicaldirectory)) 79 Directory.CreateDirectory(physicaldirectory); 80 return virtualdirectory; 81 } 82 } 83 84 public override bool Delete() 85 { 86 try 87 { 88 Directory.Delete(HttpContext.Current.Server.MapPath(UploadDirectory), true); 89 } 90 catch 91 { 92 return false; 93 } 94 95 return base.Delete(); 96 } 97 98 public override List<SearchResult> Search(string searchString, WebPage page) 99 { 100 //no deep-links, as soon as one matching entry is found, return the link to the WebPage 101 List<SearchResult> foundResults = new List<SearchResult>(); 102 DataRow[] foundRows = _data.Entries.Tables["DownloadListEntries"].Select(string.Format("Title LIKE '%{0}%' OR Filename LIKE '%{0}%' OR Comment LIKE '%{0}%'", searchString.Replace("'", "''")), "Title ASC"); 103 104 if (foundRows.Length > 0) 105 { 106 foundResults.Add( 107 new SearchResult( 108 string.Format("~/Default.aspx?pg={0}#{1}", page.PageId, SectionId), 109 (string)foundRows[0]["Title"], 110 SearchResult.CreateExcerpt(SearchResult.RemoveHtml((string)foundRows[0]["Comment"]), searchString) 111 ) 112 ); 113 } 114 115 return foundResults; 116 } 117 118 public ChannelData GetSidebarRss(string PageId) 119 { 120 ChannelData elements = new ChannelData(); 121 foreach (DataRowView row in GetDownloadEntries()) 122 { 123 Dictionary<string, string> item = new Dictionary<string, string>(); 124 int iPosition = 0; 125 foreach (string rsskey in Enum.GetNames(typeof(RssElements))) 126 { 127 InsertRssKeyValue(rsskey, row, PageId, ref item); 128 iPosition++; 129 } 130 131 elements.ChannelItems.Add(item); 132 } 133 return elements; 134 } 135 136 private void InsertRssKeyValue(string RssKey, DataRowView row, string PageId, ref Dictionary<string, string> elements) 137 { 138 string key = string.Empty; 139 string value = string.Empty; 140 switch (RssKey) 141 { 142 case "title": 143 value = row["Title"] + " (" + row["Size"] + ")"; 144 break; 145 case "link": 146 value = string.Format("~/DownloadHandler.ashx?pg={0}&section={1}&file={2}", PageId , SectionId, HttpUtility.UrlEncode((string)row["filename"])); 147 break; 148 case "description": 149 value = (string)row["Comment"]; 150 break; 151 } 152 153 if (value != string.Empty) 154 elements.Add(RssKey, value); 155 } 156 157 public struct DownloadListData 158 { 159 public DataSet Entries; 160 } 161 } 162} 163
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:MyWebPages51aspx汉化最终版
51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号