Build in 60 Min WeatherApp in C# using OpenWeatherMap API | Tutotial - PART 3

Опубликовано: 15 Май 2026
на канале: AL-Jemaliya Modern Nursery
4,389
32

***********************************************

if (txt_cityname.Text != "")
{
using (StreamWriter str = new StreamWriter("my_weather.txt"))
{
str.WriteLine("City Name: "+lbl_cityName.Text);
str.WriteLine("Country Name: "+lbl_country.Text);
str.WriteLine("Temp Name: "+lbl_Temp.Text);

}
}




****************************************

Image setIcon(string iconID)
{
string url = string.Format("http://openweathermap.org/img/w/{0}.png", iconID); // weather icon resource
var request = WebRequest.Create(url);
using (var response = request.GetResponse())
using (var weatherIcon = response.GetResponseStream())
{
Image weatherImg = Bitmap.FromStream(weatherIcon);
return weatherImg;
}
}


******************************
for WPF Application

BitmapImage seticon()
{
string url = string.Format("http://openweathermap.org/img/w/{0}.png", iconID); // weather icon resource

BitmapImage weatherImg = new BitmapImage();
weatherImg..BeginInit();
weatherImg.UriSource = new Uri(url);
weatherImg.EndInit();

return weatherImg;
}