Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to C# - need help making C# app to execute a URL 3

Status
Not open for further replies.

twofive

Programmer
Jan 9, 2007
27
0
0
US
Assuming I have a simple C# asp page online, sendsms.aspx, whose function is to parse the parameter for a 10 digit phone number and use SmtpMail.Send to send an email to a mobile device.

I'd like to make it so that the user doesn't have to open a web browser to run this web page--instead, they'd have a simple Visual Studio based GUI in which they enter in a phone number and this client side application would use a function to execture websitename.com/sendsms.aspx?5556667777. My question is, What is this function?
 
The easiest thing for you would be to embed the WebBrowser control and use that.

The webbrowser control can easily be added to the toolbox if you right click on the toolbox and click "Select Items"



 
There is only one line of code to start automatically the default web browser on the desired URL:
Code:
System.Diagnostics.Process.Start("[URL unfurl="true"]http://finance.yahoo.com/q?s=BCE");[/URL]
obislavu
 
Take a look of this code that is doing the job without openning the browser:^
Code:
		//[URL unfurl="true"]http://finance.yahoo.com/q?s=BCE[/URL]
		public void GetStock(string strURL, stockName)
			 
		{
			
			WebRequest req = null;
			WebResponse rsp = null;
			StreamReader readStream = null;
			string strRec="";
			StringBuilder sb = new StringBuilder();
			try
			{
				
				req = WebRequest.Create(strURL+"/q?s=" + stockName);
				req.Method = "GET";
				req.Timeout = 20000;
				rsp = req.GetResponse();
				Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
				readStream = new StreamReader( rsp.GetResponseStream(), encode );
				Char[] read = new Char[256];
				int count = readStream.Read( read, 0, 256 );
				while (count > 0) 
				{
					String str = new String(read, 0, count);
					sb.Append(str);
					count = readStream.Read(read, 0, 256);
				}
				strRec=sb.ToString();
				sb=null;
                                // Parse here the html string strRec if you need
				
			}
			catch (Exception ex2)
			{
				string sErr = "Cannot connect to Internet. " + ex2.Message;
				MessageBox.Show(sErr, strURL, MessageBoxButtons.OK, MessageBoxIcon.Stop);
			}
			finally
			{
				if (rsp !=null )
					rsp.GetResponseStream().Close();
				if (readStream != null)
					readStream.Close();
			}
			
		}
obislavu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top