-----Original Message-----
Hi Ching-Lung,
According to the MSDN, the type of the parameter PostData in event
BeforeNavigate2 is an SafeArray, which can be marshaled to System.Array
class. But as far as I know, there isn't a built-in type converter which
can convert an Array type to the Stream class, so the runtime throw that
exception. You may convert the Array type to Byte[] directly.
If you still have problems on this issue, please let me know.
Kind regards,
Ying-Shen Yu [MSFT]
Microsoft Support Engineer
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2001 Microsoft Corporation. All rights
reserved.
--------------------
| Content-Class: urn:content-classes:message
| From: "Ching-Lung" <
[email protected]>
| Sender: "Ching-Lung" <
[email protected]>
| References: <
[email protected]>
| Subject: conversion
| Date: Fri, 15 Aug 2003 15:15:05 -0700
| Lines: 107
| Message-ID: <
[email protected]>
| 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: AcNjeq5U3mRGIOBLTuKke//mqfkhaA==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:50377
| NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| Let me rephrase my question.
|
| PostData is one of the parameters of BeforeNavigate()
| event that contains the form's data of the submitted HTM
| page via "post" method.
|
| This is the HTM page looks like:
| ***********************************************
| <html>
| <body>
| <form name="myForm" action="form1.htm" method="post">
| <input type="text" name="myText" /><br/>
| <input type="submit" value="Submit" />
| </form>
| </body>
| </html>
| ***********************************************
|
| It basically contains a simple form with one input text
| area and a button. After clicking submit, web browser
| control raises the event BeforeNavigate() that one of its
| parameters, named "PostData", contains the actual data of
| the form.
|
|
| This is my original implementation of BeforeNavigate()
| event:
| ***********************************************
| public void BeforeNavigate(string URL, int Flags, string
| TargetFrameName, ref object PostData, string Headers, ref
| bool Cancel)
| {
| if(PostData != null)
| {
| try
| {
| Stream s = (Stream)PostData;
| Byte[] read = new Byte[32];
| int bytes = s.Read(read, 0, read.Length);
|
| while(bytes > 0)
| {
| String str = Encoding.ASCII.GetString(read);
| MessageBox.Show(str);
| bytes = s.Read(read, 0, read.Length);
| }
| }
| catch(Exception ex)
| {
| MessageBox.Show(ex.Message);
| }
| }
| }
| ***********************************************
|
| Every time I run this code, it will complain on
| line: "Stream s = (Stream)PostData;", throwing
| exception: "Specified cast is not valid."
|
| I tried to put a break point on that line and when it
| breaks, I see that "PostData" parameter is {System.Array}
| that contains 25 elements with type "byte".
|
| So, go back to my original question, how do I convert
| this "PostData" parameter to a readable string?
|
| Thanks.
| -CL
|
|
|
| >-----Original Message-----
| >Hi,
| >
| >I have web browser control in my windows form and am
| >implementing the following event:
| >
| >*****************************************
| >public void BeforeNavigate(string URL, int Flags, string
| >TargetFrameName, ref object PostData, string Headers, ref
| >bool Cancel)
| >*****************************************
| >
| >When I navigate on an htm file and submit the data (form
| >with post method), what I see on PostData var is the
| >bytes in System.Array.
| >
| >I tried the following code:
| >
| >*****************************************
| >Stream s = (Stream)PostData;
| >Byte[] read = new Byte[32];
| >int bytes = s.Read(read, 0, read.Length);
| >string str = Encoding.ASCII.GetString(b);
| >MessageBox.Show(str);
| >*****************************************
| >
| >But it complains that improper casting from object to
| >stream.
| >
| >So, how do I convert this PostData to string in order to
| >see the actual data?
| >
| >Please help. Thanks!
| >-CL
| >.
| >
|
.