473,326 Members | 2,148 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,326 software developers and data experts.

HTML file handling/modification in Visual Basic .NET application

Hi,

We're implementing a Windows application using Visual
Basic .NET.

One of the key features we need to implement is that we
should be able to get the accurate byte offset of user
selected text in the file.

We've been trying to use the RichTextBox control to load
a file, and get the offset when the user selects some
text in the file. It's been working ok with regular text
files, but we can't use the RichTextBox control to handle
an HTML file.

We're looking for a control that loads a HTML file,
displays it correctly like web-browser, and

1. can get(return) actual position or byte offset of user
selected text

OR

2. has a feature to allow us to modify HTML source, and
put some tags into the specific location, which user
selected
We want to keep the original HTML source as much as
possible if we need to put our own tags into the file to
remember the selected location.

We've tried some third-party controls that can load HTML
file in VB form, but none of them have the features that
we need, and some of them have some issues like modifying
(converting) original HTML source which we don't want.

Please let us know how to implement this.

Thanks.
Nov 20 '05 #1
9 2920
Hi Jay,
1. can get(return) actual position or byte offset of user
selected text

I think it is hard to be done.
e.g. you can use javascript (document.write ) to generate some html text
then how to located the text in html file.

OR

2. has a feature to allow us to modify HTML source, and
put some tags into the specific location, which user
selected
I think you may try to use the MSHTML.

Here I write a simple sample.
Private Sub Command1_Click()
Dim doc As MSHTML.HTMLDocument
Set doc = WebBrowser1.Document
Dim nd As MSHTML.HTMLDivElement
Set nd = doc.getElementById("mntl")
nd.contentEditable = True
nd.innerText = "hello"
End Sub
Private Sub Form_Load()
WebBrowser1.Navigate "http://www.yahoo.com/"
End Sub

Introduction to MSHTML Editing
http://msdn.microsoft.com/library/de...shop/entry.asp

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------Content-Class: urn:content-classes:message
From: "Jay Kim" <eq*****@equilar.com>
Sender: "Jay Kim" <eq*****@equilar.com>
Subject: HTML file handling/modification in Visual Basic .NET application
Date: Wed, 12 Nov 2003 15:54:12 -0800
Lines: 42
Message-ID: <07****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Thread-Index: AcOpeEVypV1Ej9qATRyzTbRVjZtcxQ==
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Newsgroups: microsoft.public.dotnet.languages.vb
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:156310
NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Hi,

We're implementing a Windows application using Visual
Basic .NET.

One of the key features we need to implement is that we
should be able to get the accurate byte offset of user
selected text in the file.

We've been trying to use the RichTextBox control to load
a file, and get the offset when the user selects some
text in the file. It's been working ok with regular text
files, but we can't use the RichTextBox control to handle
an HTML file.

We're looking for a control that loads a HTML file,
displays it correctly like web-browser, and

1. can get(return) actual position or byte offset of user
selected text

OR

2. has a feature to allow us to modify HTML source, and
put some tags into the specific location, which user
selected
We want to keep the original HTML source as much as
possible if we need to put our own tags into the file to
remember the selected location.

We've tried some third-party controls that can load HTML
file in VB form, but none of them have the features that
we need, and some of them have some issues like modifying
(converting) original HTML source which we don't want.

Please let us know how to implement this.

Thanks.


Nov 20 '05 #2
Hi Peter,
Thanks for your response.
I'm trying to test with MSHTML as you suggested.
I was reading through the page in the link that you gave
me, but I'm not sure how to use MSHTML in VB .NET.
Could you tell me more about MSHTML in detail?
Thanks.

Jay

-----Original Message-----
Hi Jay,
1. can get(return) actual position or byte offset of userselected text

I think it is hard to be done.
e.g. you can use javascript (document.write ) to

generate some html textthen how to located the text in html file.

OR

2. has a feature to allow us to modify HTML source, and
put some tags into the specific location, which user
selected
I think you may try to use the MSHTML.

Here I write a simple sample.
Private Sub Command1_Click()
Dim doc As MSHTML.HTMLDocument
Set doc = WebBrowser1.Document
Dim nd As MSHTML.HTMLDivElement
Set nd = doc.getElementById("mntl")
nd.contentEditable = True
nd.innerText = "hello"
End Sub
Private Sub Form_Load()
WebBrowser1.Navigate "http://www.yahoo.com/"
End Sub

Introduction to MSHTML Editing
http://msdn.microsoft.com/library/default.asp?

url=/workshop/entry.asp
Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.--------------------
Content-Class: urn:content-classes:message
From: "Jay Kim" <eq*****@equilar.com>
Sender: "Jay Kim" <eq*****@equilar.com>
Subject: HTML file handling/modification in Visual Basic .NET applicationDate: Wed, 12 Nov 2003 15:54:12 -0800
Lines: 42
Message-ID: <07****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Thread-Index: AcOpeEVypV1Ej9qATRyzTbRVjZtcxQ==
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Newsgroups: microsoft.public.dotnet.languages.vb
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:156310NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Hi,

We're implementing a Windows application using Visual
Basic .NET.

One of the key features we need to implement is that we
should be able to get the accurate byte offset of user
selected text in the file.

We've been trying to use the RichTextBox control to loada file, and get the offset when the user selects some
text in the file. It's been working ok with regular textfiles, but we can't use the RichTextBox control to handlean HTML file.

We're looking for a control that loads a HTML file,
displays it correctly like web-browser, and

1. can get(return) actual position or byte offset of userselected text

OR

2. has a feature to allow us to modify HTML source, and
put some tags into the specific location, which user
selected
We want to keep the original HTML source as much as
possible if we need to put our own tags into the file toremember the selected location.

We've tried some third-party controls that can load HTMLfile in VB form, but none of them have the features thatwe need, and some of them have some issues like modifying(converting) original HTML source which we don't want.

Please let us know how to implement this.

Thanks.


.

Nov 20 '05 #3
Hi,

MSHTML is a class library used to manipulate the HTML Document Object Model.
To use it in .NET, you may need to add reference to Microsoft.mshtml first.
You may achieve by right click on the reference/Add reference/.NET and
select the Microsoft.mshtml

Here is a helpful link, you may take a look.

document Object
http://msdn.microsoft.com/library/de...thor/dhtml/ref
erence/objects/obj_document.asp
Here is some code I write in VB.NET.

Imports mshtml

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim doc As mshtml.HTMLDocument
doc = AxWebBrowser1.Document
Dim nd As mshtml.HTMLDivElement
nd = doc.getElementById("mntl")
nd.contentEditable = True
nd.innerText = "hello"
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load
AxWebBrowser1.Navigate("http://www.yahoo.com")
End Sub

If you have any concern on this issue, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #4
Hi Peter,
Thank you very much for your help.
I'm trying to test as you suggested.
I'll let you know if it works.
Thanks again.

Jay
-----Original Message-----
Hi,

MSHTML is a class library used to manipulate the HTML Document Object Model.To use it in .NET, you may need to add reference to Microsoft.mshtml first.You may achieve by right click on the reference/Add reference/.NET andselect the Microsoft.mshtml

Here is a helpful link, you may take a look.

document Object
http://msdn.microsoft.com/library/default.asp? url=/workshop/author/dhtml/reference/objects/obj_document.asp
Here is some code I write in VB.NET.

Imports mshtml

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.Click
Dim doc As mshtml.HTMLDocument
doc = AxWebBrowser1.Document
Dim nd As mshtml.HTMLDivElement
nd = doc.getElementById("mntl")
nd.contentEditable = True
nd.innerText = "hello"
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)Handles MyBase.Load
AxWebBrowser1.Navigate("http://www.yahoo.com")
End Sub

If you have any concern on this issue, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
.

Nov 20 '05 #5
Hi Jay,

I look forward to hearing from you.
If you have any concern on this problem, please feel free to post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #6

Try HTML Editor from http://www.itwriting.com/htmleditor/index.php

Atara.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #7

Thanks for your info.
I took a quick look at it. It was not what I can use in
my project, but it was helpful to get some more ideas.
Thanks.

Jay
-----Original Message-----

Try HTML Editor from http://www.itwriting.com/htmleditor/index.php
Atara.

*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!
.

Nov 20 '05 #8
Hi Peter,
I really appreciate your help on this.
I think it is what I wanted. I'm almost positive that we
can implement all the features that we need with these,
but I'm having difficulties to figure them out.
I was able to open up an HTML file using WebBrowser
control, and manipulate it using MSHTML.
But, I still have some issues to solve.
First of all, how do I save the document after modifying
it without asking for the users - which means, we don't
want to show "Save as" popup to users. We want to save it
programmatically.
And, what I want to implement is that when I select some
text in the browser control, and click a button, it
inserts a HTML tag, such as <a name.> tag or <font> tag,
around the text.
For example,
Text in HTML : 1234567
if you have selected "345"
the original source would be : 12<a name="tag_1">345</a>67

I could make it somehow, but it doesn't always work, for
example,
Original source : 12<a name="tag_1">345</a>67
If you have selected "56"
The source HTML would be : 12<a
name="tag_1">34</a><a name="tag_2"> <a
name="tag_1">5</a>6</a>7

So, it's screwed up the previous HTML tags sometimes.
Please take a look at my code sample below, and advise me
if you have better solution for my case.
Thanks very much again for your help.

################################################
# Sample VB Code
################################################
Public Class frmTest
Inherits System.Windows.Forms.Form

Private doc As mshtml.HTMLDocument
Private idx As Long

Private Sub frmTest_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load

AxWebBrowser1.Navigate2("C:\test.html")
doc = AxWebBrowser1.Document
idx = 0

End Sub
Private Sub Button1_Click_1(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click

Dim rg As mshtml.IHTMLTxtRange
Dim sID As String

idx = idx + 1
sID = "myID_" & idx

If doc.selection.type = "Text" Then
'(1.1)
doc.execCommand("CreateBookmark", False, sID)

rg = doc.selection.createRange
If Not rg Is Nothing Then
'(2.1)
rg.pasteHTML("<a name=""" & sID
& """></a><span class=""my_class"">" & rg.htmlText
& "</span>")
'(2.2)
rg.pasteHTML("<a name=""" & sID
& """></a><span class=""my_class"">" & rg.text
& "</span>")

'(3.1)
rg.pasteHTML("<a name=""" & sID
& """><span class=""my_class"">" & rg.htmlText
& "</span></a>")
'(3.2)
rg.pasteHTML("<a name=""" & sID
& """><span class=""my_class"">" & rg.text
& "</span></a>")

'(4.1)
rg.pasteHTML("<span id=""" & sID & """
class=""my_class"">" & rg.htmlText & "</span>")
'(4.2)
rg.pasteHTML("<span id=""" & sID & """
class=""my_class"">" & rg.text & "</span>")
Else
MsgBox("Invalid selection")
End If
End If

End Sub

End Class
################################################
# Sample HTML - test.html
################################################
<html>
<head>
<title>Test</title>
<style type="text/css">
.my_class {
color: rgb(255,0,0);
}
</style>
</head>
<body>
<h1>Test HTML page

<p>12<font color="#ff0000">34</font>567890
ABCDEF<font
color="#ffff00">GHIJKL</font>MNOPQRSTUVWXYZ</p>

<p>123<a name="myID_100">456</a>7890 ABCD<span
class="my_class">EFG</span>HIJKLMNOPQRSTUVWXYZ</p>
</body>
</html>
-----Original Message-----
Hi Jay,

I look forward to hearing from you.
If you have any concern on this problem, please feel free to post here.
Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
.

Nov 20 '05 #9
Hi Jay,

#1
If you will want to Save file without prompting the user. Sorry, that is
not possible using by simply using WebBrowser control. You can probably
improve that using SendKeys etc. But if you really need to download a file
to hard disk without user prompting, the best bet would be use URL
Monikers. In specific you probably want to use URLDownloadToFile API. You
can find more documentation regarding URL Monikers at
<http://msdn.microsoft.com/workshop/n...w/overview.asp

and URLDownloadToFile at
<http://msdn.microsoft.com/workshop/n...ce/functions/U
RLDDownloadToFile.asp>. Alternatively you can also consider using WinInet
APIs directly
(<http://msdn.microsoft.com/workshop/n...ew/overview.as
p>)
#2
Since MSHTML is used to manipulate the html node, I think you may need to
do the parse work yourself.

=============================================
Text in HTML : 1234567
if you have selected "345"
the original source would be : 12<a name="tag_1">345</a>67
=============================================
In such case, all is ok, because what you are select are in the same node.

=================================================
I could make it somehow, but it doesn't always work, for
example,
Original source : 12<a name="tag_1">345</a>67
If you have selected "56"
The source HTML would be : 12<a
name="tag_1">34</a><a name="tag_2"> <a
name="tag_1">5</a>6</a>7
================================================
If this case, I think you may try to judge if the if the 5 and 6 is in the
same node.
If no, then if 6 and 5 will be format as the same format.
if yes,
<a name="tag_1">345</a>6 to <a name="tag_1">3456</a>
You may get the node "tag_1" and change its text, in the mean
time, delete the 6 from its original node
That is to say, all operation should based on the node.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #10

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

Similar topics

5
by: Jay Kim | last post by:
Hi, We're implementing a Windows application using Visual Basic .NET. One of the key features we need to implement is that we should be able to get the accurate byte offset of user selected text...
4
by: mustafa | last post by:
Dear sir , I have built my application in visual basic 6.0 and crystal Report8.5 , Now i migrated my application to VB.net using the upgrade wizard.My visual basic form is upgraded to vb.net...
6
by: Danny Lesandrini | last post by:
I'm using an Access database to drive a web site and the colors of various table backgrounds are stored in Access. I want users of the Access database to be able to select colors for the site, but...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
4
by: Kenneth Keeley | last post by:
Hi, I have a page that uploads files to my server and I wish to display a "Please wait while uploading" page to the user while the file is uploading. I have been able to redirect the user once the...
17
by: Lloyd Sheen | last post by:
This IDE is driving me nuts. I needed another button so I copied an existing one, changed the Text and the id and position by drag and drop. Well then I run and get the following: Control...
17
by: marks542004 | last post by:
Hi all , I am an old programmer now hobbyist who has used cobol, basic, and RPG . I am new to c++ but have Microsoft Visual Studio 6.0. I have a program in Basic that reads a file , looks for...
1
by: =?Utf-8?B?TWF1cmljZQ==?= | last post by:
Greeings: Looking for guidance in adding a feature. I would like for authorized users to be able to log into a frontpage 2002 website that I created/published and add laboratory results to data...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.