|
Here is a function that lets you do that:
Public Function GetWebPageResult(ByVal webPG As String) As String<br />
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(webPG), HttpWebRequest)<br />
<br />
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)<br />
<br />
Dim receiveStream As Stream = myHttpWebResponse.GetResponseStream()<br />
<br />
Dim encode As System.Text.Encoding = System.Text.Encoding.GetEncoding("utf-8")<br />
<br />
Dim readStream As New StreamReader(receiveStream, encode)<br />
GetWebPageResult = readStream.ReadToEnd() ' Use this 'readStream' where ever you want.<br />
<br />
End Function
Just call this function and pass the webpage URL to it. It will grab the html content of the page and return it as a string as the result of the function.
Pete Soheil
DigiOz Multimedia
http://www.digioz.com
|
|
|
|
|
Hi,
IMO you should Close both the WebResponse and the Stream inside your function.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Luc Pattyn wrote: IMO you should Close both the WebResponse and the Stream inside your function.
LOL... oops.... my bad.
Yeah, make sure to close both those.
Pete Soheil
DigiOz Multimedia
http://www.digioz.com
|
|
|
|
|
I'd forgotten about that class, cheers. Been working on winforms too long!
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
Hi Digi, thatnks for the reply.
The function is awesome. it works like charm ^^
BTW, i just find out another solution, to share with you guys here =D
I used webclient class, there is a readopen() method to achieve this.
here is a sample class which i get from msdn.
Public Class Test
Public Shared Sub Main(args() As String)
If args Is Nothing OrElse args.Length = 0 Then
Throw New ApplicationException("Specify the URI of the resource to retrieve.")
End If
Dim client As New WebClient()
' Add a user agent header in case the
' requested URI contains a query.
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)")
Dim data As Stream = client.OpenRead(args(0))
Dim reader As New StreamReader(data)
Dim s As String = reader.ReadToEnd()
Console.WriteLine(s)
data.Close()
reader.Close()
End Sub 'Main
End Class 'Test
|
|
|
|
|
How do I get my app to display a console window?
(As in the little black screen)
_______________________________________________________________________
http://www.readytogiveup.com/[ ^]
"you can't forget something you never knew..." M. Du Toit
|
|
|
|
|
I think there is a function GetConsoleWindow but I'm not 100%.
_____________________________________________
Flea Market! It's just like...it's just like...A MINI-MALL!
|
|
|
|
|
evilnoodle wrote: How do I get my app to display a console window?
Just use:
Process.Start("cmd.exe")
Or if you want to associate it with a named process:
<br />
Dim ps1 As New System.Diagnostics.Process<br />
ps1.StartInfo.WindowStyle = ProcessWindowStyle.Normal<br />
ps1.StartInfo.CreateNoWindow = False<br />
ps1.StartInfo.UseShellExecute = False<br />
ps1.StartInfo.FileName = "cmd.exe"<br />
ps1.Start()<br />
Pete Soheil
DigiOz Multimedia
http://www.digioz.com
|
|
|
|
|
In managed code , i send a message to native application :
Dim s As String = "text that i want to send"<br />
Dim GC As GCHandle = GCHandle.Alloc(s)<br />
SendMessage( hwnd , MsgId , wParam , GC )<br />
GC.Free()
In native code , i want to display a message box with text got from above message :
LRESULT WndProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam )<br />
{<br />
MessageBox(hWnd, (LPTSTR)lParam, L"Caption", MB_OKCANCEL | MB_ICONQUESTION | MB_APPLMODAL);<br />
}
But i can not get text with : (LPTSTR)lParam
Please help me to know why this code doesn't work , and how to do it ?
Thank you
|
|
|
|
|
Hi,
within a single process you need to obtain a GCHandle with GCHandleType.Pinned
so the GC can not move the object anymore; then you get the pointer through
GCHandle.AddrOfPinnedObject, and that will be your lParam.
passing strings to another process does not work that way, since the pointer
only means something to the process that owns the string. More code is needed
to allocate, then write, memory in the other process.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Thank you , i will try to write "more code"
|
|
|
|
|
Hi, you may want to have a look at my TrayIconBuster article; it has an LP_Process
class that deals with this (it is in C#, same things can be done in VB.NET).
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Thank you again
|
|
|
|
|
Hi,
I want to make an encryptation to a string but the result to be places in a textbox.
I tried the cryptostream class but it work only with stream.
thanks
|
|
|
|
|
You should be able to write out the stream to a byte array and then convert the byte array to a string.
Here are some methods I have used, sorry they are in C# They should be easy to re-write in vb.net
public static String MemoryStreamToString(MemoryStream p_ms)
{
return MemoryStreamToString(p_ms, Encoding.Default);
}
public static String MemoryStreamToString(MemoryStream p_ms, Encoding p_encoding)
{
return ByteArrayToString(p_ms.GetBuffer(), p_encoding);
}
public static MemoryStream StringToMemoryStream(String p_string)
{
return StringToMemoryStream(p_string, Encoding.Default);
}
public static MemoryStream StringToMemoryStream(String p_string, Encoding p_encoding)
{
return new MemoryStream(StringToByteArray(p_string, p_encoding));
}
public static Byte[] StringToByteArray(string p_str)
{
return StringToByteArray(p_str, Encoding.Default);
}
public static Byte[] StringToByteArray(string p_str, Encoding p_encoding)
{
return p_encoding.GetBytes(p_str);
}
public static string ByteArrayToString(byte[] p_byteArray)
{
return ByteArrayToString(p_byteArray, Encoding.Default);
}
public static string ByteArrayToString(byte[] p_byteArray, Encoding p_encoding)
{
int numberOfBytes = p_byteArray.Length;
return p_encoding.GetString(p_byteArray, 0, numberOfBytes);
}
Hope that helps.
Ben
|
|
|
|
|
Hello friends.
Please tell me what the job of function (InstrReverse) and function (Instr)with examples.
Thank you so much.
|
|
|
|
|
<code>
if instr("read the help or google it","google") > 0 then
Success = true
else
PutSomeEffortInBeforePostingOnAForum = true
end if
if InStrReverse exists then
LookItUp = true
else
StopWastingOtherPeoplesTime = true
end if
</code>
-- modified at 9:07 Wednesday 15th August, 2007
You always pass failure on the way to success.
|
|
|
|
|
LOVE IT!
_____________________________________________
Flea Market! It's just like...it's just like...A MINI-MALL!
|
|
|
|
|
|
i need to make a scheduling system for a guesthouse. (9 rooms). i need a way to scroll through the database (Sql 2005) and view room bookings relative to dates and rooms.
Calendar function and rooms thanks!
|
|
|
|
|
Basically, you need to write a database, in SQL, and then you need to write a simple program that displays your information, and calls the database methods. Smells like homework to me.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I have a user input form in which user enters some rich text in a rich text box. I store the rtb1.rtf into database. Now all what I need is to concate all input i.e. concate rtf from all rows (in database) but what happens when the output appears the only text from the first row appears. But I need to prepare whole rtf document containing data from all rows. Please help me in this regard and also let me know if the scenario is not clear
Salman Sheikh
|
|
|
|
|
|
Thanx a lot sir but i am using SQL Server 2000 and using text type to store rtf. here comes exactly the same text returned by the Richtextbox control's rtf Property.
Also i couldn't read the complete article you told for i am not registered user of that site.
Salman Sheikh
|
|
|
|
|
hi
have you tried creating an invisible richtextbox and then apppeding the database rows to the richtectbox
sort of
for eachatabase row
RichTextBox1.Rtf = RichTextBox1.rtf + <db rows="" rtf="">
next
then at the end to get the plaintext just do
val = richtextbox1.text
not elegant but will probably work
HTH
Martin
life is a bowl of cherries
go on take a byte
|
|
|
|