您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 销售管理 > ASP.NET 例程完全代码版
ASP.NET例程完全代码版(1)——AdRotator因为需要,已经终止一段时间的.NET学习进程,但是,因为个人偏好,故以此方式继续.NET之路,以温故,而知新。原来使用VS.NET2003,后来装了2005以后就没怎么用了,结果,设置pageLayout就让我大费力气,最终只好用htmlTable布局了,无语!第一个例子是关于使用AdRotator控件的,可以随机地显示广告栏目,别不多说,代码为例:第一步:创建一个WebSite(File--New--WebSite),这里起名为Example1。第二步:界面简单布局,拖入控件设置属性,其中,只要设置了AdRotator控件的AdvertisementFile就可以了,当然,这里要先定义好一个xml文档。注意这个xml文档是有着严格的格式控制的,区分大小写!下面是我的xml文档:?xmlversion=1.0encoding=utf-8?AdvertisementsAdImageUrlImage/a.gif/ImageUrlTargetUrl这里,我在解决方案下建立了Image文件夹,并放入了三个.gif图象文件。当应用程序运行,会随机显示其中的一个广告条,每次刷新或者重新访问这个页面,都如此。基础篇的例子过于简单,高手们路过即可~~~~~~~~~~ASP.NET例程完全代码版(2)——DirectoryInfo类2006-04-0111:54:00似乎能在.NETFramework1.1下跑的程序,到了.NET2.0出了问题,在baidu搜了搜,也有人问同样的问题——Directory是静态类,当然不能实例化,可是资料上有些程序却是这么写的Directorydir=newDirectory(strDir);如此在VS2005中编译是通不过的!有些书籍确是垃圾,作者只是为了赚钱而写书,对技术一点不付责任哦,书上代码都跑不过,更不用说是附带的光盘里的了。下面这个例子实现了“我的电脑”的功能,呵呵,其实,就是由驱动器到目录到文件的查看和文件预览,代码不是很规范,不过可以对Directory&DirectoryInfo有个大概的理解。工程建立,在VS2005中建立website,共三个页面ListDrives.aspx,ListDir.aspx,ShowFile.aspx。下面是三个页面的代码:第一个ListDrives.aspx:只写了个Page_Load事件,页面加载的时候得到所有驱动器的列表。protectedvoidPage_Load(objectsender,EventArgse){string[]achDrives=Directory.GetLogicalDrives();Response.Write(ul);for(inti=0;iachDrives.Length;i++){Response.Write(liahref=\listdir.aspx?dir=);Response.Write(Server.UrlEncode(achDrives));Response.Write(\+achDrives);Response.Write(/abr);}Response.Write(/ul);}第2个页面,同样也是写了一个Page_Load(事件,通过得到传递的驱动器名称得到相应的目录文件protectedvoidPage_Load(objectsender,EventArgse){stringdir=Request.QueryString.Get(dir);try{DirectoryInfodirectory=newDirectoryInfo(dir);Response.Write(pCreation:+directory.CreationTime.ToString()+/p);Response.Write(ul);DirectoryInfo[]subDirectory=directory.GetDirectories();//所有子目录for(inti=0;isubDirectory.Length;i++){Response.Write(liahref=\ListDir.aspx?dir=);//继续进入子目录……Response.Write(Server.UrlEncode(subDirectory.FullName));Response.Write(\+subDirectory.Name);Response.Write(/abr);}Response.Write(/ul);FileInfo[]theFiles=directory.GetFiles();//所有非目录文件for(inti=0;itheFiles.Length;i++){Response.Write(liahref=\ShowFile.aspx?file=);Response.Write(Server.UrlEncode(theFiles.FullName));Response.Write(\+theFiles.Name);Response.Write(/abr);}Response.Write(/ul);}catch(Exceptionex){Response.Write(Accessnotpossible,error:i);Response.Write(ex.ToString()+/i);Response.End();}}第3个文件ShowFile.aspx,这个页面中布局一个HtmlTable,用来显示相应的文件信息。下面是在它的HTML代码,读者可以通过它看到Table的结构,非常简单。%@PageLanguage=C#AutoEventWireup=trueCodeFile=ShowFile.aspx.csInherits=ShowFile%%@ImportNamespace=System.IO%!DOCTYPEhtmlPUBLIC-//W3C//DTDXHTML1.0Transitional//EN==servertitleUntitledPage/title/headbody%stringfile2Show=Request.QueryString.Get(file);FileInfothisOne=newFileInfo(file2Show);%divtablestyle=width:731px;height:293pxtrtdstyle=width:191pxname/tdtd%=thisOne.Name%/tdtdstyle=width:237pxcreatedate/tdtd/td/trtrtdstyle=width:191pxpath/tdtd%=thisOne.FullName%/tdtdstyle=width:237pxsize/tdtd%=thisOne.Length.ToString()%/td/trtrtdstyle=width:191pxdirectory/tdtd%=thisOne.DirectoryName%/tdtdstyle=width:237pxlastaccess/tdtd%=thisOne.LastAccessTime.ToString()%/td/trtrtdstyle=width:191px;height:71px;lastmodified/tdtdstyle=height:71px%=thisOne.LastWriteTime.ToString()%/tdtdstyle=width:237px;height:71px;/tdtdstyle=height:71px/td/tr/table/div%StreamReaderreader=thisOne.OpenText();char[]buffer=newchar[1000];intnRead=reader.ReadBlock(buffer,0,255);Response.Write(pre);Response.Write(newstring(buffer,0,nRead));Response.Write(/pre);%/body/htmlASP.NET例程完全代码版(3)——随意创建图形信息2006-04-0311:26:00随意创建图形信息功能:可以选择输出图象的文本;可以选择文本的颜色;可以选择背景的颜色;可以选择字体;可以选择字号;用途:比如显示自己的一个计数器,或者验证码等等。第一个aspx——Start.aspx:这是一个简单的用来设定图象属性的页面,如文本,颜色,大小等等,放置了3个HtmlTextBox,后来发现在codebehind中不能识别控件名称,呵呵,失误,只好加了runat=Server;然后是两个服务器端的DropDownList,来设置字体颜色和背景色。%@PageLanguage=C#%scriptrunat=serverprotectedvoidButton1_Click(objectsender,EventArgse){stringurl=PageCounter.aspx?HitCount=+HitCount.Value+&HitFontName=+HitFontName.Value+&HitFontSize=+HitFontSize.Value+&HitBackgroundColor=+HitBackgroundColor.SelectedValue+&HitFontColor=+HitFontColor.SelectedValue;Response.Redirect(url);}/scripthtmlxmlns==servertitleUntitledPage/title/headbodyformid=form1runat=serverdivtablestyle=width:657px;height:427pxtrtdstyle=width:287pxHitCounter/td
本文标题:ASP.NET 例程完全代码版
链接地址:https://www.777doc.com/doc-6296531 .html