|
Thanks Mike. I found that
|
|
|
|
|
Hi,
Im trying to get the postdata string in beforenavigate2 event.
The function i:
<br />
void OnBeforeNavigate2(object pDisp, ref object URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancel) {<br />
byte[] myBytes = System.Text.Encoding.ASCII.GetString(PostData);<br />
MessageBox.Show(myBytes.ToString());<br />
<br />
<br />
}<br />
As you can see, im trying several methods to convert the postdata to a string, but im not able to...
MessageBox.Show(PostData.ToString()); shows "System.bytes[]".
I've found this :
http://support.microsoft.com/kb/256195
but the examples are on Visual Basic and C++, and im not able to convert that code to c#
Can anybody help plz?
|
|
|
|
|
byte[] myBytes = (byte[])PostData;
string post = ASCIIEncoding.ASCII.GetString(myBytes);
MessageBox.Show(post);
That was the solution!!!
|
|
|
|
|
hi,
all hcan some one guide me how to print file(excel sheets) using .net application urgent pls!!!
|
|
|
|
|
sailesh_gupta wrote: application urgent pls!!!
Of COURSE it is....
sailesh_gupta wrote: sailesh_gupta
Are you related to Sonia ? She doesn't know how to use google either.
I recommend reading the article I link to below.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi,
I'm currently studying how C# can be used to control MSN messenger. I'm searching here in CodeProject and google. There are couple of examples and none of them work properly for me. I know, I may not be using them properly.
They talk about MessengerAPI. I added reference Add reference -> COM -> Messenger APIs. But, I stillget error as
The type or namespace name 'MessengerPriv' could not be found (are you missing a using directive or an assembly reference?) H:\New Folder\msn\msnsessionchange\MessengerUnlocker.cs.
Please tell me what is the proper way to work on MSN messenger with C# and how to add the proper refrence to MessengerAPI. I also saw MSDN article on Messnger Lock and key API.. All said and done, it doesn't look straight forward to me.
Any help would be appreciated
Thanks
Vikas
|
|
|
|
|
I have a c# dll that is used in c# apps.
How should i handle exceptions in the dll so that it lets the app that is using it know there was a problem and it can report it?
1. Let the exception bubble up
2. Rethrow the exception
3. Have a custom exception, and throw that with the original exception as the inner exception
4. Any other suggestions
The dll does file io, db work and uses collections, so there are a few places that exceptions could occur.
TIA
|
|
|
|
|
|
I will go and have a read, thanks
|
|
|
|
|
If the exception would be useful for the calling code, you can just let it bubble up. If you for example have a method that reads a file, any IO exceptions would make sense to the calling code, as it's directly related to what the method does.
If the exception is not really useful for the calling code, you should just throw a custom exception instead. Whether to include the original exception as an inner exception depends on how useful that information is. If your method for example is parsing values from the text file into integers, and there is a parsing error, you should throw an exception that specifies what the method was expecting to find at that location in the file.
When catching exceptions, you can specify a base class for the exceptions that you want to catch, and let other exceptions bubble up.
Example:
try {
i = int.Parse(stream.ReadLine());
} catch (FormatException ex) {
...
} catch (OverflowException ex) {
...
}
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Is there any kind of serializer in .net that can be used to load and save object graphs w/o barfing if unexpected/old elements exist in the serialized data?
I simply want to ignore field/property names that no longer exist in the serialized classes.
such field should simply be set to their default values.
XmlSerializer won't cut it since it only handles hierarchies and real graphs.
SoapFormatter seems like it always crash if unexpected elements are found.
I do know I can implement ISerializable but Im trying to avoid that, I want it to be easy to plug in new elements in the save file in this use case.
I'm hoping there might be some nifty stuff in WCF for this, or that it might be possible to handle this with the soapformatter.
any ideas?
|
|
|
|
|
I assume you are using the BinaryFormatter.
Wont ISurrogateSelector help?
|
|
|
|
|
|
How about iterating over the items with a foreach loop?
He who makes a beast out of himself gets rid of the pain of being a man
|
|
|
|
|
thanks for early reply.. i will try this suggestion
|
|
|
|
|
LOVE A7X !!!
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Has it taken you that long to notice my sig?
He who makes a beast out of himself gets rid of the pain of being a man
|
|
|
|
|
Yeah, I think so....
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Are you putting the whole stuff inside a loop which is missing from your above code ? If yes put the message box.Show outside the loop
Thanks
Laddie
Kindly rate if the answer was helpful
|
|
|
|
|
thanks..I am still struck with loop, could you please provide me template/sample code..it will be good help
|
|
|
|
|
Bit hard to give you something exact, would need more info about your app/design but this is the basics:
foreach (Control c in myCollection)
{
if (c.someProperty == true)
{
}
else
{
}
}
He who makes a beast out of himself gets rid of the pain of being a man
|
|
|
|
|
Thanks a lot.....I am providing you exact code
DialogResult dlgResult = MessageBox.Show("Removal of this task will also remove following tasks:" + "(" + next_node + ")" + " Do you still want to continue", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (!selectedNode.Checked)
if (dlgResult == DialogResult.Yes)
doCheckSibling(next_node, false);
else if (dlgResult == DialogResult.No)
selectedNode.Checked = true;
This will give you better idea and you can tell me exactly how I can use foreach, I am very close to solution I hope this would be my last query...thanks in advance..
|
|
|
|
|
I have already told you exactly how to use a foreach, I'm not here to do your work for you and if I was to give you complete code you won't learn anything. You've also provided me with the same snippet from your original post. I suggest you look at my last post, consider what issue you're having and then read the following article: How To Use Google[^]
He who makes a beast out of himself gets rid of the pain of being a man
|
|
|
|
|
hi, i have some problems with httpwebrequest
i'm trying to make my adsl router to restart the internet connection using httpwebrequests but it always returning me
the same response/login page
and my cookie container is always empty(count =0)
here is my code:
<br />
<br />
using System;<br />
<br />
using System.IO;<br />
<br />
using System.Net;<br />
<br />
using System.Text;<br />
<br />
namespace HTTPreconnector<br />
<br />
{<br />
<br />
class Program<br />
<br />
{<br />
<br />
static void Main(string[] args)<br />
<br />
{<br />
<br />
Reconnect();<br />
<br />
Console.Read();<br />
<br />
}<br />
<br />
<br />
<br />
public static void Reconnect()<br />
<br />
{<br />
<br />
String url = @"http://10.0.0.138/";<br />
<br />
String strPost = @"var%3Amain=menu1&var%3Astyle=style1&getpage=..%2Fhtml%2Fdefs%2Fstyle1%2Fmenus%2Fmenu1.html&errorpage=..%2Fhtml%2Findex.html&var%3Apagename=home&var%3Aerrorpagename=home&var%3Amenu=quickstart&var%3Amenutitle=Quickstart&var%3Apagetitle=Quick+Start&var%3Apagemaster=home&login%3Acommand%2Fusername=Admin&login%3Acommand%2Fpassword=Admin&var%3Arestore=0";<br />
<br />
StreamWriter myWriter = null;<br />
<br />
CookieContainer myContainer = new CookieContainer();<br />
<br />
<br />
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);<br />
<br />
objRequest.Method = "POST";<br />
<br />
objRequest.ContentLength = strPost.Length;<br />
<br />
objRequest.ContentType = "application/x-www-form-urlencoded";<br />
<br />
objRequest.CookieContainer = new CookieContainer();<br />
<br />
try<br />
<br />
{<br />
<br />
myWriter = new StreamWriter(objRequest.GetRequestStream());<br />
<br />
myWriter.Write(strPost);<br />
<br />
}<br />
<br />
catch (Exception e)<br />
<br />
{<br />
<br />
Console.WriteLine(e.Message);<br />
<br />
}<br />
<br />
finally<br />
<br />
{<br />
<br />
myWriter.Close();<br />
<br />
}<br />
<br />
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();<br />
<br />
<br />
foreach (Cookie cook in objResponse.Cookies)<br />
<br />
{<br />
<br />
myContainer.Add(cook);<br />
<br />
}<br />
<br />
using (StreamReader sr =<br />
<br />
new StreamReader(objResponse.GetResponseStream()))<br />
<br />
{<br />
<br />
String test = sr.ReadToEnd();<br />
<br />
sr.Close();<br />
<br />
Console.WriteLine(test);<br />
<br />
}<br />
<br />
<br />
objRequest = (HttpWebRequest)WebRequest.Create(url);<br />
<br />
strPost = strPost = @"var%3Amain=menu1&var%3Astyle=style1&getpage=..%2Fhtml%2Fdefs%2Fstyle1%2Fmenus%2Fmenu1.html&errorpage=..%2Fhtml%2Fstatus%2Fconnection.html&var%3Apagename=home&var%3Aerrorpagename=home&var%3Amenu=quickstart&var%3Amenutitle=Quickstart&var%3Apagetitle=Quick+Start&var%3Apagemaster=home&var%3AconnectBtnPressed=&var%3Aconid=connection0&connection0%3Apppoe%3Acommand%2Fstop=";<br />
<br />
objRequest = (HttpWebRequest)WebRequest.Create(url);<br />
<br />
objRequest.Method = "POST";<br />
<br />
objRequest.ContentLength = strPost.Length;<br />
<br />
objRequest.ContentType = "application/x-www-form-urlencoded";<br />
<br />
objRequest.CookieContainer = myContainer;<br />
<br />
try<br />
<br />
{<br />
<br />
myWriter = new StreamWriter(objRequest.GetRequestStream());<br />
<br />
myWriter.Write(strPost);<br />
<br />
}<br />
<br />
catch (Exception e)<br />
<br />
{<br />
<br />
Console.WriteLine(e.Message);<br />
<br />
}<br />
<br />
finally<br />
<br />
{<br />
<br />
myWriter.Close();<br />
<br />
}<br />
<br />
objResponse = (HttpWebResponse)objRequest.GetResponse();<br />
<br />
using (StreamReader sr =<br />
<br />
new StreamReader(objResponse.GetResponseStream()))<br />
<br />
{<br />
<br />
String test = sr.ReadToEnd();<br />
<br />
sr.Close();<br />
<br />
Console.WriteLine(test);<br />
<br />
}<br />
<br />
foreach (Cookie cook in objResponse.Cookies)<br />
<br />
{<br />
<br />
myContainer.Add(cook);<br />
<br />
}<br />
<br />
System.Threading.Thread.Sleep(6200);<br />
<br />
<br />
objRequest = (HttpWebRequest)WebRequest.Create(url);<br />
<br />
strPost = strPost = @"var%3Amain=menu1&var%3Astyle=style1&getpage=..%2Fhtml%2Fdefs%2Fstyle1%2Fmenus%2Fmenu1.html&errorpage=..%2Fhtml%2Fstatus%2Fconnection.html&var%3Apagename=home&var%3Aerrorpagename=home&var%3Amenu=quickstart&var%3Amenutitle=Quickstart&var%3Apagetitle=Quick+Start&var%3Apagemaster=home&var%3AconnectBtnPressed=1&var%3Aconid=connection0&connection0%3Apppoe%3Acommand%2Fstart=";<br />
<br />
objRequest = (HttpWebRequest)WebRequest.Create(url);<br />
<br />
objRequest.Method = "POST";<br />
<br />
objRequest.ContentLength = strPost.Length;<br />
<br />
objRequest.ContentType = "application/x-www-form-urlencoded";<br />
<br />
objRequest.CookieContainer = myContainer;<br />
<br />
try<br />
<br />
{<br />
<br />
myWriter = new StreamWriter(objRequest.GetRequestStream());<br />
<br />
myWriter.Write(strPost);<br />
<br />
}<br />
<br />
catch (Exception e)<br />
<br />
{<br />
<br />
Console.WriteLine(e.Message);<br />
<br />
}<br />
<br />
finally<br />
<br />
{<br />
<br />
myWriter.Close();<br />
<br />
}<br />
<br />
objResponse = (HttpWebResponse)objRequest.GetResponse();<br />
<br />
using (StreamReader sr =<br />
<br />
new StreamReader(objResponse.GetResponseStream()))<br />
<br />
{<br />
<br />
String test = sr.ReadToEnd();<br />
<br />
sr.Close();<br />
<br />
Console.WriteLine(test);<br />
<br />
}<br />
<br />
}<br />
<br />
}<br />
<br />
}<br />
<br />
thanks!
|
|
|
|
|
Member 4290786 wrote: and my cookie container is always empty(count =0)
Member 4290786 wrote: CookieContainer myContainer = new CookieContainer();
Member 4290786 wrote: objRequest.CookieContainer = new CookieContainer();
Need I say more?
|
|
|
|