Click here to Skip to main content
16,007,687 members
Home / Discussions / C#
   

C#

 
GeneralRe: Close MessageBox automaticly Pin
pcaeiro20-Mar-08 14:36
pcaeiro20-Mar-08 14:36 
GeneralRe: Close MessageBox automaticly Pin
Jordanwb20-Mar-08 15:38
Jordanwb20-Mar-08 15:38 
GeneralRe: Close MessageBox automaticly Pin
pcaeiro20-Mar-08 17:26
pcaeiro20-Mar-08 17:26 
GeneralRe: Close MessageBox automaticly Pin
PIEBALDconsult20-Mar-08 17:12
mvePIEBALDconsult20-Mar-08 17:12 
GeneralRe: Close MessageBox automaticly Pin
pcaeiro20-Mar-08 17:51
pcaeiro20-Mar-08 17:51 
GeneralRe: Close MessageBox automaticly Pin
MNFlyer21-Mar-08 11:17
MNFlyer21-Mar-08 11:17 
GeneralRe: Close MessageBox automaticly Pin
pcaeiro22-Mar-08 5:30
pcaeiro22-Mar-08 5:30 
QuestionHow to obtain external facing IP Address in C# Form Pin
PsychRich20-Mar-08 11:59
PsychRich20-Mar-08 11:59 
Had a lot of trouble finding an easy way to accomplish this; thought I would pass this code on.

I wrote a program called SatAmp that has a WebControl http page it sends out for external control of the application, and I wanted a way to help people find their external IP Address from the program itself without requiring them to actually visit a website for the purpose.

Here is my solution:
// Create a class called IPRequest with the following code:<br />
<br />
using System;<br />
using System.IO;<br />
using System.Net;<br />
using System.Text;<br />
<br />
namespace SatAmp.Utility_Classes<br />
{<br />
  class IPRequest<br />
  {<br />
    public static string GetIP()<br />
    {<br />
      // used to build entire input<br />
      StringBuilder sb = new StringBuilder();<br />
<br />
      // used on each read operation<br />
      byte[] buf = new byte[8192];<br />
<br />
      // prepare the web page we will be asking for<br />
      HttpWebRequest request = (HttpWebRequest)<br />
        WebRequest.Create("http://www.whatismyip.com/automation/n09230945.asp");<br />
<br />
      // execute the request<br />
      HttpWebResponse response = (HttpWebResponse)<br />
        request.GetResponse();<br />
<br />
      // we will read data via the response stream<br />
      Stream resStream = response.GetResponseStream();<br />
<br />
      string tempString = null;<br />
      int count = 0;<br />
<br />
      do<br />
      {<br />
        // fill the buffer with data<br />
        count = resStream.Read(buf, 0, buf.Length);<br />
<br />
        // make sure we read some data<br />
        if (count != 0)<br />
        {<br />
          // translate from bytes to ASCII text<br />
          tempString = Encoding.ASCII.GetString(buf, 0, count);<br />
<br />
          // continue building the string<br />
          sb.Append(tempString);<br />
        }<br />
      }<br />
      while (count > 0); // any more data to read?<br />
<br />
      // print out page source<br />
      //Console.WriteLine(sb.ToString());<br />
<br />
			return sb.ToString();<br />
    }<br />
<br />
<br />
  }<br />
}<br />
<br />
<br />
// ---------<br />
<br />
// Add this to your form - Make a "Get My IP" button, Make a label to display:<br />
<br />
    public void buttonGetMyIP_Click(object sender, EventArgs e)<br />
    {<br />
      try<br />
      {<br />
        string ip = IPRequest.GetIP();<br />
<br />
        this.labelMyIpAddress = ip;<br />
      }<br />
      catch<br />
      {<br />
        this.labelMyIpAddress = 000.000.000.000;<br />
      }<br />
    }<br />

Questionhow to find location of an object Pin
netJP12L20-Mar-08 11:52
netJP12L20-Mar-08 11:52 
AnswerRe: how to find location of an object Pin
J$20-Mar-08 12:17
J$20-Mar-08 12:17 
AnswerRe: how to find location of an object Pin
Christian Graus20-Mar-08 12:54
protectorChristian Graus20-Mar-08 12:54 
AnswerRe: how to find location of an object Pin
Derek Bartram21-Mar-08 15:47
Derek Bartram21-Mar-08 15:47 
GeneralUpdating db using command builder or manualy Pin
baranils20-Mar-08 10:01
baranils20-Mar-08 10:01 
GeneralC# Object Serialization Problem Pin
Jammer20-Mar-08 10:01
Jammer20-Mar-08 10:01 
GeneralRe: C# Object Serialization Problem Pin
ChrisKo20-Mar-08 11:19
ChrisKo20-Mar-08 11:19 
GeneralRe: C# Object Serialization Problem Pin
Jammer20-Mar-08 12:44
Jammer20-Mar-08 12:44 
QuestionHow to receive messages on the same socket sent from multiple UDP client using different ports? Pin
gix6520-Mar-08 8:43
gix6520-Mar-08 8:43 
GeneralRe: How to receive messages on the same socket sent from multiple UDP client using different ports? Pin
Paul Conrad21-Mar-08 10:04
professionalPaul Conrad21-Mar-08 10:04 
GeneralRecursive Generics for Fluent Interfaces [modified] Pin
TWang20-Mar-08 8:16
TWang20-Mar-08 8:16 
GeneralInstantiating Array of objects. Pin
Ravi Mahavrathayajula20-Mar-08 7:29
Ravi Mahavrathayajula20-Mar-08 7:29 
GeneralRe: Instantiating Array of objects. Pin
Russell Jones20-Mar-08 7:51
Russell Jones20-Mar-08 7:51 
GeneralRe: Instantiating Array of objects. Pin
Ravi Mahavrathayajula20-Mar-08 7:59
Ravi Mahavrathayajula20-Mar-08 7:59 
GeneralC# Used to send E-mail Pin
w20920-Mar-08 6:56
w20920-Mar-08 6:56 
GeneralRe: C# Used to send E-mail Pin
J4amieC20-Mar-08 7:20
J4amieC20-Mar-08 7:20 
GeneralRe: C# Used to send E-mail Pin
led mike20-Mar-08 8:16
led mike20-Mar-08 8:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.