473,382 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

loading a url using mshtml.createDocumentFromUrl

Hello,
I am having certain problems in trying to use the function
createDocumentFromUrl in VB.NET but get this error.."Object reference not set
to an instance of object".
Here is the code that I am using

Imports mshtml

Public DocumentFactory As HTMLDocument
Public Function GetWebPage(ByVal strURL As String) As HTMLDocument
Try
GetWebPage = DocumentFactory.createDocumentFromUrl(strURL, vbNullString)
StatusBar1.Panels(1).Text = strURL
Do Until GetWebPage.readyState = "complete"
Application.DoEvents()
Loop
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function

I was reading through the similar situation but the gentleman posting the
reply has submiited a attachment which is not be found anymore. I would
greatly apprecitate if the code is posted again.

Thanking you in advance,

Vibhu Bansal.
Nov 21 '05 #1
14 7439
Further to my post, I need to use IPersistStreamInit. I was reading this in
this forum itself. But unfortunately, the solution file posted as an
attachment is missing. I would request anybody who has a clue to it to get
asap.
Vibhu Bansal.
Nov 21 '05 #2
Further to my post, I need to use IPersistStreamInit. I was reading this in
this forum itself. But unfortunately, the solution file posted as an
attachment is missing. I would request anybody who has a clue to it to get
asap.
Vibhu Bansal.
Nov 21 '05 #3
Hi Charles,
It seems that the attachment is not getting posted. Please email the
attachment to me at vi****@hotmail.com if you can.
BTW, the gentleman is you itself and I was reading the post sometime of late
last year within this forum.
Vibhu.

"Charles Law" wrote:
Hi Vibhu
I was reading through the similar situation but the gentleman posting the
reply has submiited a attachment which is not be found anymore. I would
greatly apprecitate if the code is posted again.


Do you know the Gentleman's name, and when it was posted?
GetWebPage = DocumentFactory.createDocumentFromUrl(strURL,
vbNullString)


The problem is here because DocumentFactory has not been created yet.

Try the attached.

HTH

Charles
"Vibhu Bansal" <Vibhu Ba****@discussions.microsoft.com> wrote in message
news:50**********************************@microsof t.com...
Hello,
I am having certain problems in trying to use the function
createDocumentFromUrl in VB.NET but get this error.."Object reference not
set
to an instance of object".
Here is the code that I am using

Imports mshtml

Public DocumentFactory As HTMLDocument
Public Function GetWebPage(ByVal strURL As String) As HTMLDocument
Try
GetWebPage = DocumentFactory.createDocumentFromUrl(strURL,
vbNullString)
StatusBar1.Panels(1).Text = strURL
Do Until GetWebPage.readyState = "complete"
Application.DoEvents()
Loop
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function

I was reading through the similar situation but the gentleman posting the
reply has submiited a attachment which is not be found anymore. I would
greatly apprecitate if the code is posted again.

Thanking you in advance,

Vibhu Bansal.


Nov 21 '05 #4
Hi Charles,
It seems that the attachment is not getting posted. Please email the
attachment to me at vi****@hotmail.com if you can.
BTW, the gentleman is you itself and I was reading the post sometime of late
last year within this forum.
Vibhu.

"Charles Law" wrote:
Hi Vibhu
I was reading through the similar situation but the gentleman posting the
reply has submiited a attachment which is not be found anymore. I would
greatly apprecitate if the code is posted again.


Do you know the Gentleman's name, and when it was posted?
GetWebPage = DocumentFactory.createDocumentFromUrl(strURL,
vbNullString)


The problem is here because DocumentFactory has not been created yet.

Try the attached.

HTH

Charles
"Vibhu Bansal" <Vibhu Ba****@discussions.microsoft.com> wrote in message
news:50**********************************@microsof t.com...
Hello,
I am having certain problems in trying to use the function
createDocumentFromUrl in VB.NET but get this error.."Object reference not
set
to an instance of object".
Here is the code that I am using

Imports mshtml

Public DocumentFactory As HTMLDocument
Public Function GetWebPage(ByVal strURL As String) As HTMLDocument
Try
GetWebPage = DocumentFactory.createDocumentFromUrl(strURL,
vbNullString)
StatusBar1.Panels(1).Text = strURL
Do Until GetWebPage.readyState = "complete"
Application.DoEvents()
Loop
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function

I was reading through the similar situation but the gentleman posting the
reply has submiited a attachment which is not be found anymore. I would
greatly apprecitate if the code is posted again.

Thanking you in advance,

Vibhu Bansal.


Nov 21 '05 #5
Vibhu,

It is in the newsgroup, what you can try is to attach this newsgroup direct
on the microsoft.newsserver
news://news.microsoft.com/microsoft....t.languages.vb

As well to inform Charles from that.

Cor
Nov 21 '05 #6
Vibhu,

It is in the newsgroup, what you can try is to attach this newsgroup direct
on the microsoft.newsserver
news://news.microsoft.com/microsoft....t.languages.vb

As well to inform Charles from that.

Cor
Nov 21 '05 #7
I have just sent it so you should receive it shortly.

I am able to see the attachment on the newsgroup using MS Outlook Express as
my newsreader, so perhaps it is something at your end that is preventing you
from seeing it.

Charles
"Vibhu Bansal" <Vi*********@discussions.microsoft.com> wrote in message
news:72**********************************@microsof t.com...
Hi Charles,
It seems that the attachment is not getting posted. Please email the
attachment to me at vi****@hotmail.com if you can.
BTW, the gentleman is you itself and I was reading the post sometime of
late
last year within this forum.
Vibhu.

"Charles Law" wrote:
Hi Vibhu
> I was reading through the similar situation but the gentleman posting
> the
> reply has submiited a attachment which is not be found anymore. I would
> greatly apprecitate if the code is posted again.


Do you know the Gentleman's name, and when it was posted?
> GetWebPage = DocumentFactory.createDocumentFromUrl(strURL,
> vbNullString)


The problem is here because DocumentFactory has not been created yet.

Try the attached.

HTH

Charles
"Vibhu Bansal" <Vibhu Ba****@discussions.microsoft.com> wrote in message
news:50**********************************@microsof t.com...
> Hello,
> I am having certain problems in trying to use the function
> createDocumentFromUrl in VB.NET but get this error.."Object reference
> not
> set
> to an instance of object".
> Here is the code that I am using
>
> Imports mshtml
>
> Public DocumentFactory As HTMLDocument
> Public Function GetWebPage(ByVal strURL As String) As HTMLDocument
> Try
> GetWebPage = DocumentFactory.createDocumentFromUrl(strURL,
> vbNullString)
> StatusBar1.Panels(1).Text = strURL
> Do Until GetWebPage.readyState = "complete"
> Application.DoEvents()
> Loop
> Catch ex As Exception
> MsgBox(ex.Message)
> End Try
> End Function
>
> I was reading through the similar situation but the gentleman posting
> the
> reply has submiited a attachment which is not be found anymore. I would
> greatly apprecitate if the code is posted again.
>
> Thanking you in advance,
>
> Vibhu Bansal.
>
>


Nov 21 '05 #8
I have just sent it so you should receive it shortly.

I am able to see the attachment on the newsgroup using MS Outlook Express as
my newsreader, so perhaps it is something at your end that is preventing you
from seeing it.

Charles
"Vibhu Bansal" <Vi*********@discussions.microsoft.com> wrote in message
news:72**********************************@microsof t.com...
Hi Charles,
It seems that the attachment is not getting posted. Please email the
attachment to me at vi****@hotmail.com if you can.
BTW, the gentleman is you itself and I was reading the post sometime of
late
last year within this forum.
Vibhu.

"Charles Law" wrote:
Hi Vibhu
> I was reading through the similar situation but the gentleman posting
> the
> reply has submiited a attachment which is not be found anymore. I would
> greatly apprecitate if the code is posted again.


Do you know the Gentleman's name, and when it was posted?
> GetWebPage = DocumentFactory.createDocumentFromUrl(strURL,
> vbNullString)


The problem is here because DocumentFactory has not been created yet.

Try the attached.

HTH

Charles
"Vibhu Bansal" <Vibhu Ba****@discussions.microsoft.com> wrote in message
news:50**********************************@microsof t.com...
> Hello,
> I am having certain problems in trying to use the function
> createDocumentFromUrl in VB.NET but get this error.."Object reference
> not
> set
> to an instance of object".
> Here is the code that I am using
>
> Imports mshtml
>
> Public DocumentFactory As HTMLDocument
> Public Function GetWebPage(ByVal strURL As String) As HTMLDocument
> Try
> GetWebPage = DocumentFactory.createDocumentFromUrl(strURL,
> vbNullString)
> StatusBar1.Panels(1).Text = strURL
> Do Until GetWebPage.readyState = "complete"
> Application.DoEvents()
> Loop
> Catch ex As Exception
> MsgBox(ex.Message)
> End Try
> End Function
>
> I was reading through the similar situation but the gentleman posting
> the
> reply has submiited a attachment which is not be found anymore. I would
> greatly apprecitate if the code is posted again.
>
> Thanking you in advance,
>
> Vibhu Bansal.
>
>


Nov 21 '05 #9
Hi Charles,
Thanks for the info. Now I am getting stuck up in the next part i.e. using
this fuction, I need to get all elements by their tag names. So in VB6, I was
using the function getElementsbyTagname. But now as the page is being
retrieved in IHTMLDocument2 object, it does not support this function. Can
you provide me hints as to how I can use this functionality. I need to use
this function to look for images and store them on the local folder in the
harddisk.
Any help or references would be greatly beneficial.
Thanking You,
Vibhu.
Nov 21 '05 #10
Hi Charles,
Thanks for the info. Now I am getting stuck up in the next part i.e. using
this fuction, I need to get all elements by their tag names. So in VB6, I was
using the function getElementsbyTagname. But now as the page is being
retrieved in IHTMLDocument2 object, it does not support this function. Can
you provide me hints as to how I can use this functionality. I need to use
this function to look for images and store them on the local folder in the
harddisk.
Any help or references would be greatly beneficial.
Thanking You,
Vibhu.
Nov 21 '05 #11
Vibhu

getElementsByTagName is defined on the IHTMLDocument3 interface. Use
DirectCast to get this interface from the document object and you will then
be able to call the method as before.

HTH

Charles
"Vibhu Bansal" <Vi*********@discussions.microsoft.com> wrote in message
news:33**********************************@microsof t.com...
Hi Charles,
Thanks for the info. Now I am getting stuck up in the next part i.e. using
this fuction, I need to get all elements by their tag names. So in VB6, I
was
using the function getElementsbyTagname. But now as the page is being
retrieved in IHTMLDocument2 object, it does not support this function. Can
you provide me hints as to how I can use this functionality. I need to use
this function to look for images and store them on the local folder in the
harddisk.
Any help or references would be greatly beneficial.
Thanking You,
Vibhu.

Nov 21 '05 #12
Vibhu

getElementsByTagName is defined on the IHTMLDocument3 interface. Use
DirectCast to get this interface from the document object and you will then
be able to call the method as before.

HTH

Charles
"Vibhu Bansal" <Vi*********@discussions.microsoft.com> wrote in message
news:33**********************************@microsof t.com...
Hi Charles,
Thanks for the info. Now I am getting stuck up in the next part i.e. using
this fuction, I need to get all elements by their tag names. So in VB6, I
was
using the function getElementsbyTagname. But now as the page is being
retrieved in IHTMLDocument2 object, it does not support this function. Can
you provide me hints as to how I can use this functionality. I need to use
this function to look for images and store them on the local folder in the
harddisk.
Any help or references would be greatly beneficial.
Thanking You,
Vibhu.

Nov 21 '05 #13
Hi,
Instead of using getElementsbytagname, within IHTMDocument2 I stumbled on a
function of anchors. This is what the code looks like now...

Private Sub SearchUrl(ByVal strURL As String)
Dim objMSHTML As New mshtml.HTMLDocument
Dim objDocument As mshtml.IHTMLDocument2
Dim ips As IPersistStreamInit
Dim item As mshtml.IHTMLElement
ips = DirectCast(objMSHTML, IPersistStreamInit)
ips.InitNew()
objDocument = objMSHTML.createDocumentFromUrl(strURL, vbNullString)
Do Until objDocument.readyState = "complete"
Application.DoEvents()
Loop
For Each item In objDocument.anchors
Dim strUrl1 As mshtml.IHTMLAnchorElement
strUrl1 = item
MsgBox(strUrl1.href)
Next
End Sub
Now when this function is called, it does loop through objDocument.anchors
but shows a message box without any details. This is happening because it
seems that
objDocument's state is still not complete. I reached this inference because
the text in the text box is displayed after the message box has clicked on.

Any clues on why this is happening.

Vibhu.
Nov 21 '05 #14
Hi,
I finally got the problem working. Here is the solution...

We do need use IHTMLDocument3 in order to get the links with a page that has
been loaded.

Thanks Charles for the help you provided.

Private Sub SearchUrl(ByVal strURL As String)
Dim objMSHTML As New mshtml.HTMLDocument
Dim objDocument As mshtml.IHTMLDocument2
Dim ips As IPersistStreamInit
Dim HTMLTagCollection As mshtml.IHTMLElementCollection
Dim item As mshtml.IHTMLAnchorElement
ips = DirectCast(objMSHTML, IPersistStreamInit)
ips.InitNew()
objDocument = objMSHTML.createDocumentFromUrl(strURL, vbNullString)
Do Until objDocument.readyState = "complete"
Application.DoEvents()
Loop
TextBox1.Text = objDocument.body.innerHTML()
Dim ObjDocument3 As mshtml.IHTMLDocument3
ObjDocument3 = DirectCast(objDocument, mshtml.IHTMLDocument3)
HTMLTagCollection = ObjDocument3.getElementsByTagName("A")
For Each item In HTMLTagCollection
MsgBox(item.href)
Next
End Sub
Nov 21 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: BKM | last post by:
I've been using the following 2 ways to make sure my WebBrowser is finished loading a page before continuing with the next code. do:doevents:loop while WebBrowser.Busy do:doevents:loop until...
0
by: travisGatesMcGee | last post by:
For days and days, I have been trying to see a URL's parsing in a DOM tree (links collection, images and other DHTML elements) in Visual Basic......... Total Disaster!!!!!!!!!! Way too many...
3
by: Thomas Seidel | last post by:
Hi NG, I would like to write a specific library that gets it data from a specific webpage. Because not all web sites are XHTML I guess I have to use the old com library MSHTML. Beacause it...
2
by: DotNetShadow | last post by:
Hi Guys, I have been reading heaps of information in regards to MSHTML object being used in .NET applications, windows and UI-less. I have read the walkall samples and tried various techniques...
3
by: DotNetShadow | last post by:
Hi Guys, I have been reading heaps of information in regards to MSHTML object being used in .NET applications, windows and UI-less. I have read the walkall samples and tried various techniques...
3
by: ddd | last post by:
I am trying to use MSHTML without the webbrowser and I am having a few problems. Right now all I am trying to do is load an URL(html page) and access its innerhtml. What I have is: Dim doc As...
11
by: Bob Hollness | last post by:
Hi all (me again. I do try to answer the posts I can instead of just asking!!!) Any ideas how I could load a webpage into a control that was about the size of a stamp? I tried a few things but...
0
by: Vibhu Bansal | last post by:
Hello, I am having certain problems in trying to use the function createDocumentFromUrl in VB.NET but get this error.."Object reference not set to an instance of object". Here is the code that I...
0
by: Atara | last post by:
Our application was build with VS 2003. I have tried to run it on a computer with .Net 2.0 (but without .Net 1.1 , as it should be used) and I got the following error - ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.