net服务器控件位置,一个“简单”的ASP.NET的服务器控件

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Drawing;usingSystem.Drawing.Design;usingSystem.IO;usingSystem.Text;usingSystem.Web;usingSystem.Web.Caching;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;

[assembly: TagPrefix("EndWell","EW")]namespaceEndWell

{

[DefaultProperty("Text")]

[ToolboxData("")]

[ToolboxBitmap("HyperlinkFileList.ico")]publicclassHyperlinkFileList : Panel

{

[Bindable(true)]

[Category("Files List")]

[Description("The Title of the list of files")]publicstringFilesTitle {get;set;}

[Bindable(true)]

[Category("Files List")]

[Description("The directory of the files to list:  (~/Files/)")]//these two built in editors were lacking://[EditorAttribute(typeof(System.Web.UI.Design.UrlEditor), typeof(UITypeEditor))]//[EditorAttribute(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(UITypeEditor))][EditorAttribute(typeof(EndWell.DualModeFolderEditor),typeof(UITypeEditor))]publicstringFilesDirectory {get;set; }

[Bindable(true)]

[Category("Files List")]

[Description("The filter for the files to show:  (*.*)")]publicstringFilesFilter {get;set; }

[Bindable(true)]

[Category("Files List")]

[Description("Text to show when there are no files")]publicstringNoFilesText {get;set; }//---- Private vars --------------------------privateString[] m_FilesArray;//cached for performance//---- Default constants-------------------constString DEF_FILES_DIR="~/xml/";constString DEF_FILES_FILT="*.xml";constString DEF_FILES_TITLE="XML Files:";constString DEF_NOFILES_TEXT="";//---- Constructor --------------------------publicHyperlinkFileList()

{//set defaults for our propertiesFilesDirectory=DEF_FILES_DIR;

FilesFilter=DEF_FILES_FILT;

FilesTitle=DEF_FILES_TITLE;

NoFilesText=DEF_NOFILES_TEXT;//Set defaults for panel properties//I don't like the default width to be full screen//And a border looks betterWidth=newUnit("300px");

BorderStyle=BorderStyle.Solid;

BorderWidth=1;

BorderColor=Color.Black;//If height is set, force scroll bars to keep list//from spilling over the panel/div boundaries.if((Height!=null)&&(ScrollBars==ScrollBars.None))

ScrollBars=ScrollBars.Auto;//Allow multiple controls to be placed horizontally//(normally each div get's its own line)Style["display"]="inline-block";//add spacing outside the controlStyle["margin"]="0.5em";//add space inside the controlStyle["padding-left"]="0.5em";

Style["padding-right"]="0.5em";

Style["padding-bottom"]="0.5em";//top space usually comes from the title...if(String.IsNullOrEmpty(FilesTitle)==true)

Style["padding-top"]="0.5em";

}//---- RenderContents ----------------------------Spit out the HTMLprotectedoverridevoidRenderContents(HtmlTextWriter Output)

{//output the title if one was setif(String.IsNullOrEmpty(FilesTitle)==false)

{

Output.Write("

");//cosmetic spacingOutput.Write(FilesTitle);

Output.Write("");

}

GetFilesArray();if(m_FilesArray.Length==0)

{

Output.Write(HttpUtility.HtmlEncode(NoFilesText));

}else{foreach(String OneFileinm_FilesArray)

{

HyperLink Link=newHyperLink();

Link.NavigateUrl=Path.Combine(FilesDirectory, Path.GetFileName(OneFile));

Link.Text=Path.GetFileNameWithoutExtension(OneFile);

Link.RenderControl(Output);

Output.WriteBreak();

}

}

}//---- GetFilesArray -------------------------Fill the m_FilesArray with a list of files//either from disk or the cacheprivatevoidGetFilesArray()

{//see if the file list is in the cache.//use directory and filter as unique keym_FilesArray=Page.Cache[FilesDirectory+FilesFilter]asString[];if(m_FilesArray!=null)return;//if no files filter set, use the default one.if(String.IsNullOrEmpty(FilesFilter))

FilesFilter=DEF_FILES_FILT;//if no files directory set, use the default one.if(String.IsNullOrEmpty(FilesDirectory))

FilesDirectory=DEF_FILES_DIR;//if a virtual path is detected, map to full pathString FullPath;if(FilesDirectory.StartsWith("~"))

FullPath=Context.Server.MapPath(FilesDirectory);elseFullPath=FilesDirectory;//get the filesm_FilesArray=Directory.GetFiles(FullPath, FilesFilter, SearchOption.TopDirectoryOnly);//put the list in the cache so we don't have to read the disk again//use a dependency on the directory being read from for auto refreshingPage.Cache.Insert(FilesDirectory+FilesFilter,//unique keym_FilesArray,//list of files to storenewCacheDependency(FullPath));//dependency on directory}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值