January 10th, 2008Yahoo! Weather Web Part
Yeah, I know. You’re thinking this is frivolous; “What’s the point?”, you say. Well this is my first web part and I decided to go with something a little less “high profile”. However, I am still happy with it and think its got enough of that cool factor to warrant a post here.
It accesses the RSS feed from Yahoo! Weather and parses it for use within the web part. The code I provided is designed to retrieve the weather information for our location (Visalia, CA 93277) but could be easily modified for yours. Or, if you wanted, you could add a TextBox and have the user submit their own zip code!
There is A LOT of styling involved with making it look this way. I will include the styles as well as the plate graphics (which turns to gray after sunset). I would suggest, if you plan to use my styles, that you read my previous post on “Customizing the order of your stylesheets“. It’s a bit more work, but I like to have all the styles for the webparts I’ve developed in an independent stylesheet and not have those styles overwritten by the INFAMOUS core.css
I didn’t build this in a deployable package (still learning that), so this is just the C# code. You will have to build it into a .dll and deploy it to the GAC or place it into the bin folder. You will also have to set the web part namespace to be trusted in your web.config. Google will be your friend on all of that.
If all of this is just too daunting then I suggest trying Dustin Miller’s approach using SharePoint Designer (wuuuhhh!?) . The only problem I found with this, is that the datalist web part created in SharePoint Designer could not be shared easily between sites and users would not be able to add it to their own content pages (without my intervention).
Here are the source files: weather_webpart.zip
February 25th, 2008 at 6:54 pm
I’m interested in your new web part. I’ve got Bamboo, but hate how long ittakes to time out whenever the MSN site is down. Turns a <2 second load into 45+ seconds. It would be cool if the information could be cached on the server somewhow and then updated once an hour (or something). Let me know when you have something that you’d like to share.
Thanks!
February 25th, 2008 at 7:02 pm
I have done something similar to that. What I would recommend in this situation is to create an SSIS package that uses a VB Script task to do, essentially, the same thing this web part is doing. Except you could store the results in a database table. You could have this SSIS package scheduled to run every 30 min. (thats how often Yahoo! updates their info anyway).
March 6th, 2008 at 8:06 am
This web part is GREAT! I have tried so many different weather web parts, and this one is by far the simplest. However, I am finding it difficult to figure out where to put those background images and the css file in order to have this web part compile into a standalone .dll file. I would ideally like the deployment of this web part as simple as dropping the file into the GAC and registering it as a safe control, etc…, and not having to worry about copying image and css files into a certain location on the server. Especially if the web part is placed into a subsite and the image links are relative references.
March 6th, 2008 at 9:29 am
Dave – I’m glad you found this web part to be the easiest to use. Proves that, at least, I did SOMETHING right.
This is a great question you pose, and I don’t know if there is a simple answer to it. I totally agree that having all of the css styling and images available in the .dll would be useful, however, I don’t know if it would be possible in the way you’re imagining it.
One idea I had (but did not pursue due to copyright conflicts) is to use Yahoo’s own (really nice) images from there official weather site. This would put the images in a location that would (hypothetically) be available to everyone.
As far as css styling, If you don’t want to have to rely on an independent .css file, I imagine you would have to do all the styling in code which, I think, could be painful.
Good luck in your pursuit and please let me know if you’ve discovered anything new for this web part!
September 9th, 2008 at 5:08 am
Is it possible to make this show multiple days?
Thanks.
February 17th, 2009 at 9:27 am
Travis,
Great job on the webpart…wise men think alike! Turns out we have the same kind of code on our intranet, but for performance reasons we use a table to store the database feed XML and then parse that XML to use it on the webpart.
Was wondering if you have an existing version with the ZIP code text box? How would I update the feed with the zipcode, send it in as a query parm I assume?
Thanks.
February 17th, 2009 at 4:06 pm
Chetan,
Thanks for including me in your wisdom.
It makes sense to store the XML in a table for performance. This seems a bit obvious, but doesn’t the XML store the zipcode in it’s schema? If so, I would imagine passing a parameter to a stored procedure (which ultimately queries/constructs your data for the web part) would work just fine.