|
-
May 1st, 2007, 06:25 AM
#1
Thread Starter
Lively Member
[2005] WebClient derived class issues
Hi there,
I am attempting to write a new class called XmlSource that inherits from System.Net.WebClient. Basically, I want to override the OnDownloadFileCompleted function to process the System.Net.DownloadStringCompletedEventArgs.Result passed to the eventhandler for this event. If this sounds confusing, maybe the comments in my code will help.
=vb Code:
Public Class XmlSource
Inherits System.Net.WebClient
Private _name As String
Private _uri As Uri
Private _lasterror As String
Private _xmldocstring As String
Private _xmldoc As System.Xml.XmlDocument
...snip snip...
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Protected Overrides Sub OnDownloadFileCompleted(ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
' Preferable I would like to handle the e.Result presently in wcDownloadStringCompleted()
' so I can create the XmlTextReader and all that stuff.
MyBase.OnDownloadDataCompleted(e)
End Sub
Public Sub fetchXML()
Dim wcWebClient As New System.Net.WebClient 'WebClient
' Setup Event Handlers
AddHandler wcWebClient.DownloadStringCompleted, AddressOf wcDownloadStringCompleted
' AddHandler wcWebClient.DownloadProgressChanged, AddressOf weDownloadProgressChanged
'Fetch HTML page
wcWebClient.DownloadStringAsync(_uri)
End Sub
' This functionality is currently handled by the main form but I would prefer to handle that within
' this Class, before the MyBase.OnDownloadDataCompleted(e) is called.
Private Sub wcDownloadStringCompleted(ByVal sender As Object, ByVal e As System.Net.DownloadStringCompletedEventArgs)
'If the string request went as planned and wasn't cancelled:
If e.Cancelled = False AndAlso e.Error Is Nothing Then
'Use e.Result to get the String
Dim sr As New System.IO.StringReader(CStr(e.Result))
' The XmlTextReader
Dim xr As New System.Xml.XmlTextReader(sr)
' The XmlDocument
_xmldoc = New System.Xml.XmlDocument
_xmldoc.Load(xr)
_lasterror = String.Empty
Else
_lasterror = CStr(e.Error.Message)
End If
End Sub
End Class
Maybe my code somewhat explains it. The idea is that once the download is completed, and the DownloadStringCompleted event has been raised to the application, the xmldocuement is ready for consumption by simply asking for it through a property (to be written, still).
So my question is, how do I access the parameter passed to the eventhandler BEFORE it is passed there so I can fiddle with the DownloadStringCompletedEventArgs.Result.
Thanks,
Mightor
What the world needs is more geniuses with humility, there are so few of us left.
If my post was accidentally useful, please rate it as such, thanks!
Mon aéroglisseur est plein des anguilles.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|