So after following some tutorials and using , I got some code going and now I've been spending hours trying to figure out why it won't work. I started by making a Windows Forms app and made this interface. At first it was going to be able to find the weather of any city you typed in, but I can't find such an option on openweathermap so I only restricted it to Seoul, Korea. However I don't understand why nothing happens when I click the button, I thought it should bring back the forecast in the text boxes.. If anyone could help it would be really appreciated.
This is my full code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
using System.IO;
using System.Net;
namespace WindowsFormsApp3
{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { string city; city = txtcity.Text; string uri = string.Format("", city); XDocument doc = XDocument.Load(uri); string iconUri = (string)doc.Descendants("icon").FirstOrDefault(); WebClient client = new WebClient(); string maxtemp = (string)doc.Descendants("temperature.max").FirstOrDefault(); string mintemp = (string)doc.Descendants("temperature.min").FirstOrDefault(); string maxwindm = (string)doc.Descendants("maxwind_mph").FirstOrDefault(); string maxwindk = (string)doc.Descendants("maxwind_kph").FirstOrDefault(); string humidity = (string)doc.Descendants("avghumidity").FirstOrDefault(); string country = (string)doc.Descendants("country").FirstOrDefault(); string cloud = (string)doc.Descendants("text").FirstOrDefault(); txtmaxtemp.Text = maxtemp; txtmintemp.Text = mintemp; txtwindm.Text = maxwindm; txtwindk.Text = maxwindk; txthumidity.Text = humidity; label7.Text = cloud; txtcountry.Text = country; } private void button1_Click(object sender, EventArgs e) { } }
} 2 1 Answer
You have burned this info in your link that you are asking for a certain city (Seul):
""
There is no info in your code that you changed it in this link. Please try this:
String.Format("",city);Hope will fine :)