Introduction to VB Internet Tools.ppt
《Introduction to VB Internet Tools.ppt》由会员分享,可在线阅读,更多相关《Introduction to VB Internet Tools.ppt(50页珍藏版)》请在麦多课文档分享上搜索。
1、Introduction to VB.Net Internet Tools,Downloading Internet Resources,Download the HTML from a web page and display it in a text box. System.URI A class for expressing a Uniform Resource Identifier. System.Net.WebRequest Makes a request to a Uniform Resource Identifier. WebResponse Provides a respons
2、e from a Uniform Resource Identifier. Demo: MyBrowser/GetWebPage,Imports System.IO Imports System.Net Imports System.Text Private Sub BtnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnGo.ClickDim URI As New Uri(txtURL.Text)Dim request As WebRequest = WebRequest.Creat
3、e(URI)Dim response As WebResponse = request.GetResponseDim stream As Stream = response.GetResponseStreamDim readStream As New StreamReader(stream)Dim webData As String = readStream.ReadToEndstream.Close()readStream.Close()txtData.Text = webData End sub,Change Downloaded Page,For example, use strings
4、 Replace method to change page content. webData = webData.Replace(“Chao“, “You“),Using the WebClient Class,This class wraps the Request and Response classes. Methods: DownloadData: Returns a byte array from an Internet address. DownloadFile: Save a downloaded file. OpenRead: Returns a stream from an
5、 Internet address.,UTFEncoding Class,This class encodes Unicode characters using UCS Transformation Format, 8-bit form (UTF-8). This encoding supports all Unicode character Method: GetString Decodes the specified byte array into a string.,WebClient/Download,Dim wc As New WebClient()Dim utf8 As New U
6、TF8Encoding()Dim webData As StringwebData = utf8.GetString(wc.DownloadData(txtURL.Text)txtData.Text = webData,WebClient/DownloadFile,Dim wc As New WebClient() wc.DownloadFile(txtURL.Text, “c:testDownLoad.txt“),WebClient/OpenRead,Dim wc As New WebClient()Dim stream As Streamstream = wc.OpenRead(txtUR
7、L.Text)Dim readStream As New StreamReader(stream)Dim webData As String = readStream.ReadToEndtxtData.Text = webData,Hosting Internet Explorer in Windows Forms,Internet Explorer COM control Right click Tool Box Windows Form tab and select Customize ToolBox Select COM Component tab, and Scroll down to
8、 select Microsoft Web Browser.,Internet Explorer COM control,Events DownLoadComplete DownLoadBegin Methods: Navigate Dim HomeURL As String = “http:/dchaolaptop“Private Sub MyBrowser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadIE.Navigate(HomeURL)End Sub Goback
9、, GoForward Stop Refresh2 GoHome, GoSearch,Introduction to Web Form,Web Form vs HTML Form,HTML Form: A web page that contains one or more HTML form controls such as textbox, checkbox, dropdown list, and button inside an HTML tag. Web Form: A web page that contains:ASP.NET server controls, and/or HTM
10、L form controls inside a tag. ASP.NET code that produces dynamic content to be displayed within the web form.,ASP.NET Server Controls, ASP:,Intrinsic Controls: These controls correspond to their HTML counterparts. Ex. Textbox, listbox, button, etc. Data-Centric Controls: Controls used for binding an
11、d displaying data from a data source, such as the DataGrid control. Rich Controls: Such as Calendar, AdRotator. Validation Controls: Such as RequiredFieldValidator. Namespace:System.Web.UI.Webcontrols,Web Server,Default directory C:InetPubwwwroot Computer lab: Zip drive dchao Default home page Defau
12、lt.aspx, default.asp, default.htm,Web Project,File/New/ ASP.Net Application Website folder Web form: Webform.aspx Design view and HTML view WebForm.Aspx.VB CodeBehind,Web Data Form,Web Data Form Wizard: Project/Add Web Form/Data Form Wizard Web Form with Server Explorer or Data Tools. Data binding O
13、leDbDataAdapter1.Fill(Ds21) DataGrid1.DataBind(),Use Data Reader to Create a DropDown List,Demo: WebForm/WebForm2 Update rating for selected customer,Introduction to ASP.Net,ASP.NET,ASP.NET is a server-side technology for creating dynamic web pages. ASP.NET allows you to use a selection of full prog
14、ramming languages. The default language is VB .NET. ASP.NET files have a .aspx extension.,ASP.NET in the .NET Framework,1. The client requests a web page. 2. The web server locates the page. 3. If the page is an ASP.NET page, it is sent to the Common Language Runtime for compilation and execution. 4
15、. The HTML produced by the CLR is returned to the browser.,Benefits of Server-Side Technology,Browser compatibility: Every browser reads HTML. Protection of source code. Controls are server-side objects with properties, methods and events. Separating code from content. Embedded code CodeBehind Data
16、entered into form fields is preserved in View State.,Elements of an ASP.Net Page,Directives Code blocks ASP.NET controls HTML tags and text. Server-side include directives,Directives,A directive controls how an ASP.Net page is compiled. Page directives: Specify default language, enable tracing and d
17、ebugging for a page. , Imports name spaces To process Access database, we need to import:,Inserting ASP.NET Code into Web Pages,Place ASP.NET code between and with a RUNAT attribute.Your scriptInline Code Block: ASP code is placed between . The time is now The time is now “=“ is shorthand for respon
18、se.write Server-side comments:CodeBehind,Demo: TineNow.aspx,The time is now The time is now good afternoon“) end if %,ASP.NET Object Model,Client,Server,Request Object,Response Object,Server Object,Session Object,Application Object,ASP.NET Request Object,When a page is requested, much information is
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- INTRODUCTIONTOVBINTERNETTOOLSPPT
