Creating a custom Weather Web Part in SharePoint 2010

Update :- The below solution doens’t work any more


Recently we had a requirement to create a web part that will show the weather information based on the address of the user, which we were pulling from Microsoft Dynamics CRM’s database.

These following two links were of immense help

This is how the web part looks

Below is the sample source code for the web part

public class MyWeatherWebPart : WebPart
String UserLocation = "Ahmedabad"; // user city
String UserCountry = "India"; // user country
String RequestforURL = string.Empty; // URL which use to get xml data ( rss feed response ) from
System.Web.UI.WebControls.Xml xmlResults = new System.Web.UI.WebControls.Xml(); // this object contain final data we need to publish(write on sharepoint site)

protected override void Render(HtmlTextWriter writer)
String reqUrl = "<a href=""></a>" + GetLocaleID() + "?cc=*&dayf=5&link=xoap&prod=xoap&par=xxxxxxxx&key=xxxxxxxxxxxxxxx";
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(reqUrl);
//load the response into a response object
WebResponse resp = wr.GetResponse();
// create a new stream that can be placed into an XmlTextReader
Stream str = resp.GetResponseStream();
XmlTextReader reader = new XmlTextReader(str);
reader.XmlResolver = null;
// create a new Xml document and locading feed data in to it
XmlDocument doc = new XmlDocument();

// as xml style sheet is use for publishing data so we loading it into envornment
HttpContext context = HttpContext.Current; // getting refrence of current environment
// getting reference of path where sml style sheet stays
string path = context.Request.MapPath("/_layouts/RSSWeatherXSL.xsl");

// this object need to convert xml data into xml style sheet view
XslTransform trans = new XslTransform();

trans.Load(path); // loading xsl file
xmlResults.Document = doc; // loading xml data
xmlResults.Transform = trans; // transforming xml to xsl
xmlResults.DataBind(); // binding data
xmlResults.Visible = true; // setting property
xmlResults.RenderControl(writer); // rendering/publishing data as html

catch (Exception ex)

/// <summary>
/// </summary>
/// <returns></returns>
public string GetLocaleID()
RequestforURL = "<a href=""></a>=" + UserLocation.ToString() + "," + UserCountry.ToString();
// First we request our content from our provider source .. in this case .. The Weather Channel
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(RequestforURL);
//load the response into a response object
WebResponse resp = wr.GetResponse();
// converting it into stream
Stream str = resp.GetResponseStream();
// creating xml reader
XmlTextReader XmlTextReader = new XmlTextReader(str);
XmlTextReader.XmlResolver = null;
XmlDocument doc = new XmlDocument();
// loading xml data in xml doc
// searching location id
return doc.DocumentElement.ParentNode.LastChild.FirstChild.Attributes[0].Value;
catch(Exception ex)
throw ex; // any exception then default value i.e toronto, canada


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

One thought on “Creating a custom Weather Web Part in SharePoint 2010”

Please share your thoughts

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

CRM for You and Me

Customer Relationship Mgt App for the Professional

D CRM Explorer

Learn about Microsoft Dynamics CRM Power Platform customization and implementation and other cool stuffs

Stroke // Jonas Rapp

I know pre-stroke. I will improve who I was.

Power Melange

Power Melange By Shalinee

Clavin's Blog

Power Automate - Power Apps - SharePoint Online - Azure - Nintex - K2 - Artificial Intelligence

Sat Sangha Salon

An Inquiry in Being

The Indoencers

The Influencers & Influences of Indian Music

Monika Halan's blog

Hand's-free money management

D365 Demystified

A closer look at Microsoft Dynamics 365.

Microsoft Mate (msftmate) - Andrew Rogers

Experienced consultant primarily focused on Microsoft Dynamics 365 and the Power Platform


Specific topics by Django Lohn on the whole Microsoft365 Stack

Manmit Rahevar's Blog

One Stop Destination for Microsoft Technology Solutions


Naturally Curious

Brian Illand

Power Platform and Dynamics 365

Steve Mordue MVP

A Microsoft Business Applications MVP

Subwoofer 101

Bass defines your home theater

SQLTwins by Nakul Vachhrajani

SQL Server tips and experiences dedicated to my twin daughters.

Everything D365

Discovering Azure DevOps and D365 Business Applications

Tech Wizard

Lets do IT Spells

Two Bite Tips

Valuable Tips To Grow Your Business

XRM Tricks (Power Platform & Dynamics CRM )

Power Platform & Dynamics CRM


Mail to for queries and suggestions

Giving back to the community what I have learned

xrm CRM Dynamics

Dynamics CRM Technical & Functional Info

Dynamics 365 Blogs - Explained in unique way

Sometimes you need to look at things from different perspective.

CRM Keeper

Dynamics 365 Customer Engagement, CRM, Microsoft CRM, Dynamics CRM


Step into the world of a Dynamics 365 Consultant

Dianamics PCF Lady

Diana & Dynamics 365 & Power Platform

Sara Lagerquist

No Code Customization Concepts


developer, designer, writer, fun loving, patriotic, humble and a sweet person inside out :) love and respect people who have a great sense of humor.

Temmy Wahyu Raharjo

Dreaming to be a clean coder and TDD minded programmer.

Transform 365

We blog about problems we face and code we write to help others

%d bloggers like this: