|
Ok, I couldn't figure out how to get the IP address from a HttpWebResponse object, so instead I'm using
IPHostEntry hostentry = Dns.Resolve(uri);
IPAddress = hostentry.AddressList[0];
The problem with the above is that it will not resolve a DNS entry for something like "http://www.google.com", but it will resolve an entry for "google.com" or "www.google.com". However, if you try to create a HttpWebRequest object with either of the latter two uri's, they are invalid - only the first one is valid. I only have one "address bar" in my program, so this is a bit of a problem. So, I need to find a way to get the IP, and create a HttpWebRequest given only one uri - any ideas/suggestions?
Thanks,
Justin
|
|
|
|
|
A quick work around will be a way to format the input from the user, in your case, the address, into an appropriate Uri format so your class can be created. I have written up a simple formatting method that will allow you to accept different formats as you stated above (i.e., www.google.com and google.com) and create the appropriate Uri class from it. Try the following:
private Uri FormatUri(string url)
{
Uri uri = null;
if(!url.ToLower().StartsWith("http://"))
{
uri = new Uri("http://" + url);
}
else
uri = new Uri(url);
return uri;
}
So you can use this as follows:
private void button1_Click(object sender, System.EventArgs e)
{
Uri uri = FormatUri(this.textBox1.Text);
MessageBox.Show(uri.AbsoluteUri);
}
HTH
- Nick Parker My Blog | My Articles
|
|
|
|
|
While I find it odd that you don't know what server responded to you when you, in fact, made the request (a la HttpWebRequest ), you must have some valid reason.
This is possible. Pass HttpWebResponse.Server to Dns.Resolve or similar (like Dns.GetHostByName ) and you can get the IP address. If all you wanted was the name, the Server property would return that for you, as it is clearly documented.
The Dns class would not - and should not - return the protocol scheme "http". DNS - or Domain Name Service - only deals with IP<->hostname mapping. A protocol scheme merely indicates to clients what protocol to use to communicate with the server and, more often than note, the default port (HTTP's default port is 80; SMTP's default port is 25; etc.).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi...
Can anyone tell me if it is possible to run/create a C# application on Linux?
I want to know if it can run on MandrakeLinux...!
Thanks...!
QzRz
|
|
|
|
|
Yes. Take a look at Mono[^]
This posting is provided "AS IS" with no warranties, and confers no rights.
Alex Korchemniy
|
|
|
|
|
Thanks...!
You just saved me for a lot of translation from C# to c++
Thanks again..!
QzRz
|
|
|
|
|
Hello,
I am having trouble updating to a database using a dataset. My code is listed below with the error description. I hope you can help me.
cnnTeacher.Open();<br />
<br />
dsTeacher.Clear();
DataRow drUpdateTeacher;<br />
<br />
daTeacher = new OleDbDataAdapter("SELECT * FROM Teacher",cnnTeacher);<br />
OleDbCommandBuilder cbTeacher = new OleDbCommandBuilder(daTeacher);<br />
daTeacher.FillSchema(dsTeacher, SchemaType.Source, "Teacher");<br />
<br />
drUpdateTeacher = dsTeacher.Tables["Teacher"].Rows.Find(txtTeacherID.Text);
drUpdateTeacher["TeacherID"] = txtTeacherID.Text;
drUpdateTeacher["FirstName"] = txtFirstName.Text;<br />
drUpdateTeacher["LastName"] = txtLastName.Text;<br />
drUpdateTeacher["Email"] = txtEmail.Text;<br />
<br />
daTeacher.Update(dsTeacher,"Teacher");
Error description - SystemNullReferenceException: Object reference not set to a instance of an object
Many thanks in advance,
Steve
|
|
|
|
|
Hello,
I think it is because you don't initialize your drUpdateTeacher object.
Try to do :
daTeacher.FillSchema(dsTeacher, SchemaType.Source, "Teacher");
//Code to add
drUpdateTeacher = dsTeacher.Tables["Teacher"].NewRow();
drUpdateTeacher = dsTeacher.Tables["Teacher"].Rows.Find(txtTeacherID.Text);//Find the row to update
This would be my first guess.
Anyways, most of the time, this error message indicates that you did not initialize an object before you used it.
Hope this helps
|
|
|
|
|
Hello,
Thanks for yourr reply.
But won't the NewRow() add a new record to the table. I was trying to update an existing row not add a new one to the table.
Many thanks in advance,
Steve
|
|
|
|
|
Hello,
No, the NewRow() function does not add a line to the existing table, it creates a line from the row without adding it to the table (it creates the column as they are in the table)
The function DataTable.ImportRow(DataRow row) is the one that adds the line.
You have to create the row with the NewRow function because otherwise, the compiler won't be able to know how many columns there is in the table, what are the columns name/index, etc.
When you create your DataRow object, it has a null value until you write the
row = DataTable.NewRow() statement.
Hope this helps!
Hugo Migneron
|
|
|
|
|
Hello,
I want to add a Splash Screen to my Smart Device Application. The situation is as follows:
The Form1.cs is my Login Page, the Splash.cs is my Form which should displayed about 3 seconds and then should automatically go on to the MainMenu Form.
To reach that I made the following:
In the Form1.cs exists a button which forwards to the MainMenu with these two lines:
MainMenu mainMenu = new MainMenu();
mainMenu.Show();
In the Constructor of the MainMenu Form I wrote after the InitializeComponent() the following lines:
Splash splash = new Splash();
splash.Show();
And in the Splash.cs I import the following method:
[DllImport("coredll.dll", CharSet=CharSet.Unicode)]
public static extern void Sleep (int dwMilliseconds);
public const int IDC_WAIT = 32514;
public const int IDC_ARROW = 32512;
public const int IDC_IBEAM = 32513;
public const int IDC_CROSS = 32515;
public const int IDC_UPARROW = 32516;
public const int IDC_NO = 32648;
public const int IDC_HELP = 32651;
private System.Windows.Forms.Label label1;
public const int IDC_HAND = 32649;
and in the Splash_Load method I wrote the following:
Sleep(3000);
this.Close();
Unfortunately this does not work correctly. Does anybody know what went wrong??
Best Regards
mat
|
|
|
|
|
Instead of pInvoking Sleep, why not use the Sleep method build into .NET
See MSDN's library reference for Thread.Sleep[^] for details
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
On top of what Colin said, the Sleep should not go into the Splash screen. Instead, the code should go into your Main form, using something like:
splash.Show();
Sleep(3000);
splash.Close()
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
I've currently got a program that emulates the command prompt in C#. So my application hooks into cmd.exe and then via a pair of text boxes in my application, I can stream the command prompt input and output back and forth. This works fine on my local machine.
I'm looking to set this up so that there will be 2 applications. On machine A, the application will connect to cmd.exe on machine B. Then from the application on machine A, I can send console commands to machine B's cmd.exe and receive output back.
Does anyone have any recommendations as to how I should go about this?
Any help is much appreciated
|
|
|
|
|
|
could anyone helpme out....i want to make a windows application that has phone, fax, answering machine facilites...this can be acheived through TAPI provided u have a TAPI compliant modem....how do i get strated on this...all the hlp on MSDN is in C/C++ and i cant make head or tails of it....and....i misgt be a little slow in replying as i am unable to access the internet everyday...
|
|
|
|
|
|
Do yourself a big favour. TAPI and C# are a bad combination, especially if you've never written any TAPI applications in C++ before.
My strategy when writing TAPI applications in C# was to use COM Interop with my own TAPI COM wrapper. I also built an XML service in C++ that fired the TAPI events via TCP as XML.
Until Microsoft come out with a better approach to managed TAPI, you are better off writing your TAPI code in C++.
Michael
CP Blog [^]
|
|
|
|
|
Hi~
The wparam and lparam is the pointer of the variable. I would like to pass string to the other window using sendMessage method in C# by P/Invoke. Then, as wparam and lparam is pointer and C# no support pointer. Then how to send the message with string in C# using sendMessage?
|
|
|
|
|
http://pinvoke.net/[^]
I'd give you a reference directly to the page you need, as there is an example of what you want, but the site doesn't allow you to directly go to a page. You have to search or browse for the API you are looking for.
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
Colin Angus Mackay wrote:
I'd give you a reference directly to the page you need, as there is an example of what you want, but the site doesn't allow you to directly go to a page. You have to search or browse for the API you are looking for.
Not entirely true, here is the link: SendMessage[^].
- Nick Parker My Blog | My Articles
|
|
|
|
|
For the pocket pc,
why, sometime when the program try to show a form by calling the .Show() method, the form was not shown. However, the form title appear in the task list(memory)?
|
|
|
|
|
Hi,
I am using the System.Web.Mail in a C# program to send email and i want to make sure my program will be usable. I would like to know if everyone who has dotnet installed (dotnetfx.exe for example) will be able to use the program.
I think there is an issue with the CDO/CDONT but i am not quite sure what it is. My application must support WinME, Win2000 and WinXP with dotnet installed. If anyone knows more about the System.Web.Mail compatibility, it would be really appreciated
Thanks
HM
|
|
|
|
|
The documentation for System.Web.Mail.SmtpMail states that only the following platforms are supported: Windows 2000, Windows XP Professional, Windows Server 2003 family.
Indicative code for getting the OS and CLR version numbers is as folows:
using System;<br />
Console.WriteLine("OSVersion: {0}", Environment.OSVersion.ToString());<br />
Console.WriteLine("CLRVersion: {0}", Environment.Version.ToString());
Please see my article
here[^] for more details:
Salil Khedkar [^]
|
|
|
|
|
There is an issue, and you should not use System.Web.Mail . It requires a CDO server to be installed. Current CDO servers include Microsoft Exchange Server (requires NT Server; the Exchange version may require newer NT-based Windows platforms as well), or the Microsoft SMTP Services which, IIRC, started shipping with Win2K server (perhaps professional, but I don't remember off-hand).
Sending SMTP messages is really not hard at all. Just search this site for SMTP using the search box at the top of every page, or even this forum by clicking "Search comments". I personally have posted numerous examples, as well as sample source in an article on this site to resolve MX records for a specified domain (you need to know the SMTP server to send mail to). The SMTP protocol - at least for simply sending messages with no more support than MailMessage would give you - is very simple.
Note that in .NET 2.0 (formerly named "Whidbey") Microsoft will ship as part of the BCL SMTP and MIME support in classes that do not require CDO.
The System.Web.Mail classes - which should be evident by the parent namespace - is meant for use with ASP.NET, which is typically (but not limited to) run on IIS, where you can also install the Microsoft SMTP Services to send or forward mail, as well as queue received mail.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|