As most Sharepoint 2003 administrators know, Microsoft will discontinue support for their MSNBC Web Parts on February 6, 2007 (KB 929197). Since I was unable to find a suitable replacement for the MSNBC Stock Quote web part, I decided to program my own using the stock data provided by Yahoo!.
It is important to note that this web part is provided by me and I have nothing to do with Yahoo!. All of the references to Yahoo! are meant to give them all the credit for the data.
Here is a screenshot of the default web part:
In this next screenshot, you can see the settings window. Here is where your users can identify the stocks they wish to track. These stocks are a Sharepoint Personal setting, so they can be different for each user.
As you can see from the settings, there is an option to display the company name in addition to the stock symbol. Here's a screenshot of what that looks like:
Finally, if you select the display charts option in the settings, you will see charts of both the intra-day and weekly results for the stocks you've chosen. Screenshot:
To install this web part:
1. Locate the directory where sharepoint portal server is installed (i.e. C:\Inetpub\wwwroot). You should see a web.config file in this location.
2. Edit the web.config file:
2.1. In the safecontrols section, add the following line (note that this is case sensitive!):
<SafeControl Assembly="StockQuotes, Version=184.108.40.206, Culture=neutral, PublicKeyToken=24291b4f7bc336a4" Namespace="StockQuotes" TypeName="*" Safe="True" />
2.2 Change the trust level to "Full." You may skip this step if you are installing the web part to the GAC (not recommended for security reasons).
<trust level="Full" originurl="">
2.3 Save the web.config file and run iisreset at a command prompt.
2.4 In your sharepoint root directory (typically C:\Inetpub\wwwroot), create a directory called "bin" if it doesn't already exist. Copy the StockQuotes.dll file into this new directory (C:\Inetpub\wwwroot\bin). Be sure that the permissions on the bin directory and the file itself are the same as the wwwroot directory, otherwise you may see an "Access denied" error message.
Alternatively, you may install the web part to the Global Assembly Cache by dragging the StockQuotes.dll file into C:\Windows\Assembly. You must restart the server after doing this before the web part will work properly. If you do this step, you can leave the trust level at "WSS_Minimal." Please note that the best practice is to install web parts in the bin directory instead of into the GAC. Besides being better for security, it allows you to replace web parts without having to restart the whole server.
3. Import the StockQuotes.dwp file to load the web part on the page.
***Please note that the stock symbols are currently stored as a sharepoint Personal property. Some web part zones do not permit personalization (for example, the web part zones on the home page of the portal). Therefore if you load this web part in one of these restricted zones, your users will not be able to customize the settings (although you can specify the settings under Shared View). You will notice that the "Change Symbols" link is hidden when the web part is loaded in a restricted zone.
If you have a single-portal web server, you can consider editing the template file to change a web part zone so that it can be personalized by the users. To do this, edit:
C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\1033\SPS\default.aspx
Look for the web part zones at the bottom and change: AllowPersonalization="true"
The services provided by Yahoo may be changed at any time. I am not associated with Yahoo in any way and I have no idea as to the legality of your use of this code with respect to downloading data from the Yahoo.com website. Please refer to Yahoo for any applicable copyright or usage information.
My web part (StockQuotes.dll) and source code are licensed under the Creative Commons Attribution 2.5 License.
To view a copy of this license, visit http://creativecommons.org/licenses/by/2.5/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco,
California, 94105, USA.
How To Get It
Download (zip file containing .DLL file and source code) - Last Updated 2/2/2008
- I have tested on a fresh install of Sharepoint Portal Server 2003 on both portal and wss pages. The web part has not been tested with Sharepoint 2007.
- Your web server must be able to contact the Yahoo Finance web servers. Although the charts are downloaded directly by the users, the content of the stock quotes is downloaded by the server before the web part is rendered. The file downloaded by the server is extremely small (it is a comma delimited file showing on the data on the screen). Currently this data is not cached due to the variety of different searches your users may perform. Therefore, this small data file is downloaded from Yahoo each time the web part is loaded by each user. If you have a high-traffic web site, you will want to consider how this will impact the performance of your server.
Assembly stockquotes.dll security permission grant set is incompatible between appdomains.
Check the trust level setting in your web.config (typically c:\inetpub\wwwroot\web.config) and be sure that it is set to Full.
Error Access is denied: 'StockQuotes'.
Check the permissions on the StockQuotes.DLL file in the bin directory (typically c:\inetpub\wwwroot\bin). To adjust these permissions, set both the bin directory and the dll file to inherit the permissions of the parent folder (on the file properties Security tab, click Advanced and click the checkbox to Allow inheritable permissions from the parent to propagate to this object...).
Web Part Error: This page has encountered a critical error. Contact your system administrator if this problem persists. (on existing Sharepoint web parts)
This can occur if the safecontrols line is not exactly correct. In my instance miscapitalizing Safe="True" as safe="True" caused the built-in web parts to malfunction (note that the "S" must be capitalized).
A Web Part or Web Form Control on this Web Part Page cannot be displayed or imported because it is not registered on this site as safe. (when adding the web part to a page or viewing a page with the web part already added)
This can be caused by 3 issues: 1. The SafeControls entry in the web.config file is missing or incorrect, 2. Sharepoint cannot find or access the StockQuotes.DLL (is it installed in the bin directory? if installing in the GAC, did you reboot?), or 3. The DWP file you are importing contains incorrect information about the Assembly and Type info for the web part.
If you use my web part, please send add a comment here.