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

conversion

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
Nov 15 '05 #1
4 3548
I don't think you've posted the code that's required to determine the
problem. What exactly is this PostData object that you're trying to cast
into a stream? I think to determine your problem I would have to see
several lines before this one:
Stream s = (Stream)PostData;

Chris LaJoie

"Ching-Lung" <ch*******@alumni.cs.utexas.edu> wrote in message
news:02****************************@phx.gbl...
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

Nov 15 '05 #2
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-----
I don't think you've posted the code that's required to determine theproblem. What exactly is this PostData object that you're trying to castinto a stream? I think to determine your problem I would have to seeseveral lines before this one:
Stream s = (Stream)PostData;

Chris LaJoie

"Ching-Lung" <ch*******@alumni.cs.utexas.edu> wrote in messagenews:02****************************@phx.gbl...
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

.

Nov 15 '05 #3
Cool, thx!

-CL

-----Original Message-----
Sorry about that, I missed that in your first post.

have a look here:
http://msdn.microsoft.com/library/default.asp? url=/workshop/browser/webbrowser/reference/events/beforenav
igate.asp
that url will probably wrap, just piece it together again in your browser.
PostData is variant, so it could potentially be any type of data. I don'tbelieve a Stream can handle that (I must admit I haven't worked with Streamsmuch). Instead of casting it to a Stream, try casting it directly to astring instead, and see what happens. If that doesn't work, can you put awatch on the PostData object and view it in the watches window when you'redebugging? That might be able to tell you what type of data it is.

Hope this helps,
Chris LaJoie


Nov 15 '05 #4

Hi Ching,

Yes, I think you should cast PostData parameter to System.String class then
you can
use the method of string class to process postdata parameter.

Jeffrey Tan
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: "Ching-Lung" <ch*******@alumni.cs.utexas.edu>
| Sender: "Ching-Lung" <ch*******@alumni.cs.utexas.edu>
| References: <02****************************@phx.gbl>
<en**************@tk2msftngp13.phx.gbl>
| Subject: Re: conversion
| Date: Fri, 15 Aug 2003 15:12:57 -0700
| Lines: 123
| Message-ID: <03****************************@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
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcNjemHFBo3nqiaMQfm8vVoeJRVgLg==
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:176797
| NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| 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-----
| >I don't think you've posted the code that's required to
| determine the
| >problem. What exactly is this PostData object that
| you're trying to cast
| >into a stream? I think to determine your problem I would
| have to see
| >several lines before this one:
| >Stream s = (Stream)PostData;
| >
| >Chris LaJoie
| >
| >"Ching-Lung" <ch*******@alumni.cs.utexas.edu> wrote in
| message
| >news:02****************************@phx.gbl...
| >> 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
| >
| >
| >.
| >
|

Nov 15 '05 #5

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

Similar topics

1
by: Stub | last post by:
Docs says that "The compiler does not use an explicit constructor to implement an implied conversion of types. It's purpose is reserved explicitly for construction." I put up code of three cases...
7
by: Michael Lehn | last post by:
Hi, I have a question regarding the conversion of objects. When is the conversion done by the constructor and when by the operator. My feeling tells me that the constructor is preferred. But...
16
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. ...
31
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one...
11
by: Steve Gough | last post by:
Could anyone please help me to understand what is happening here? The commented line produces an error, which is what I expected given that there is no conversion defined from type double to type...
2
by: Alex Sedow | last post by:
Why explicit conversion from SomeType* to IntPtr is not ambiguous (according to standart)? Example: // System.IntPtr class IntPtr { public static explicit System.IntPtr (int); public...
3
by: Steve Richter | last post by:
here is a warning I am getting in a C++ .NET compile: c:\SrNet\jury\JuryTest.cpp(55) : warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied while...
0
by: Lou Evart | last post by:
DOCUMENT CONVERSION SERVICES Softline International (SII) operates one of the industry's largest document and data conversion service bureaus. In the past year, SII converted over a million...
0
by: dataentryoffshore | last post by:
Get a Discount up to 60% on data entry, data capture, dataentry services, large volume data processing and data conversion services through offshore facilities in India. Offshore data entry also...
21
by: REH | last post by:
It it permissible to use the constructor style cast with primitives such as "unsigned long"? One of my compilers accepts this syntax, the other does not. The failing one chokes on the fact that the...
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...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.