Byte My Data

A personal collection of advice and solutions I've used.

About the author

Something about the author

Get the URI of the root SharePoint site in a web application and instantiate a SPWeb object for it

Here's the code from the previous post,

 

// The SharePoint portal URI of the root site.
var portalUrl = new Uri(Request.Url.GetLeftPart(UriPartial.Authority));
// The SharePoint sub site.
var portalSite = Request.QueryString["site"];
.
.
.
// Instantiate the SharePoint website object located at [portalUrl]/[portalSite].
SPWeb mySite = SPWebApplication.Lookup(portalUrl).Sites[portalSite].AllWebs[portalSite];

Categories: .NET | ASP.NET | C# | SharePoint
Permalink | Comments (1) | Post RSSRSS comment feed

Object reference not set to an instance of an object when instantiating a SharePoint SPWeb object in a web app

This is the reason we ran into this issue, it was simple and had nothing to do with the code, it's one of those "things to keep in mind" LOL.

We've got a web app in a virtual directory within the SharePoint site and a team member was trying to access it using the domain that was pointing to the site (http://portal.mydomain.com/myapp) and this was throwing the exception.

When the app was accessed via the server name, it worked (http://SERVERNAME/myapp).

The reason was that the SharePoint site was created as SERVERNAME and not portal.mydomain.com and the app was looking up the SharePoint site based on the current url (portal.mydomain.com) which did not exist.

 

// The SharePoint portal URI of the root site.
var portalUrl = new Uri(Request.Url.GetLeftPart(UriPartial.Authority));
// The SharePoint sub site.
var portalSite = Request.QueryString["site"];
.
.
.
// Instantiate the SharePoint website object located at [portalUrl]/[portalSite].
SPWeb mySite = SPWebApplication.Lookup(portalUrl).Sites[portalSite].AllWebs[portalSite];

 


Permalink | Comments (3) | Post RSSRSS comment feed

Where is the STSADM.EXE located?

It's on the WSS server located in:

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\

If not in there for you, check the bin folder in one of the other numeric directories in the web server extensions directory.


Permalink | Comments (1) | Post RSSRSS comment feed

Installing and activating SharePoint feature

Original Post: http://social.technet.microsoft.com/Forums/en-US/sharepointadmin/thread/ef50eb2d-7e12-4373-90c8-75832c20ac21

INSTALL:

stsadm.exe -o installfeature -filename "foldername\feature.xml"

ACTIVATE:

stsadm.exe -o activatefeature -filename "foldername\feature.xml" -url http:\\sharepoint.website.com

Note: the filename is the relative path to the Feature.xml file in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES.


Permalink | Comments (0) | Post RSSRSS comment feed

Deploying a site from WSS 3 or transferring to MOSS 2007

Here's a great post that tells you step by step what you need to do:

http://blogs.microsoft.co.il/blogs/joe/archive/2008/11/22/transferring-a-site-from-wss-3-to-moss-2007-part-1.aspx


Permalink | Comments (0) | Post RSSRSS comment feed

Sharepoint weather web part using RSS and weather.yahoo.com

I was looking for a free weather web part to replace an evaluation version of the one I had. I knew that the web part was using the weather.yahoo.com RSS so I figured I'd build my own with a little help from Google :-). I found a great post from Ketaanh Shah with a solution for exactly what I needed and without even creating a custom webpart!

The original post is here: http://blogs.msdn.com/ketaanhs/archive/2008/03/22/showing-weather-web-part-using-rss-weather-yahoo-com-in-sharepoint-2007.aspx

One thing to note in step #2:
For myself I am passing the following parameters (instead of p) as described on http://developer.yahoo.com/weather/#req

For the Weather RSS feed there are two parameters:

  • w for WOEID.
  • u for degrees units (Fahrenheit or Celsius).

The WOEID parameter w is required. Use this parameter to indicate the location for the weather forecast as a WOEID.

http://weather.yahooapis.com/forecastrss?w=location

For example, to get weather for Yahoo! Headquarters in Sunnyvale, CA, use the WOEID code for Sunnyvale (2502265):

http://weather.yahooapis.com/forecastrss?w=2502265

The location parameter needs to be a WOEID. To find your WOEID, browse or search for your city from the Weather home page. The WOEID is in the URL for the forecast page for that city. You can also get the WOEID by entering your zip code on the home page. For example, if you search for Los Angeles on the Weather home page, the forecast page for that city is http://weather.yahoo.com/united-states/california/los-angeles-2442047/. The WOEID is 2442047.

_____________________________________________________________

Showing Weather web-part using RSS & weather.yahoo.com (in Sharepoint 2007)

One of my Colleagues happen to ask me how do we show the weather web-part on our Sharepoint Portal. The Solution was pretty simple and thought I should share this with you all. Following are the steps:

1. Add the RSS web-part on your sharepoint portal (MOSS, Sharepoint 2007) site.

2. Give the RSS feed as: http://weather.yahooapis.com/forecastrss?p=08810 (p is the Parameter for your zip code)

3. Now the most important part, open the XSL editor of your RSS web-part and remove everything from there and then just paste one of the XSL codes (show below) into that. Thats it you are done, your weather web-part is ready now. So all that is important here is XSL.

First XSL Variation:

1st XSL Variation

<?xml version="1.0" encoding="ISO-8859-1"?> 

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<xsl:output method="html" indent="yes"/> 

<xsl:template match="/"> 

<xsl:variable name="scale">
    <xsl:value-of select="rss/channel/yweather:units/@temperature"/>
</xsl:variable> 

<table width="100%" border="0" cellspacing="0" cellpadding="3" class="Normal">
  <tr bgcolor="#CCCCCC"> 
    <td colspan="2"><strong>Weather Report - <xsl:value-of select="rss/channel/item/title"/></strong></td>
  </tr>
  <tr> 
    <td><strong>Currently <font size="4"><xsl:value-of select="rss/channel/item/yweather:condition/@temp"/><xsl:text>°</xsl:text><xsl:copy-of select="$scale" /></font></strong><br/>
      High <xsl:value-of select="rss/channel/item/yweather:forecast/@high"/> <xsl:text>°</xsl:text><xsl:copy-of select="$scale" /> <br/>
      Low <xsl:value-of select="rss/channel/item/yweather:forecast/@low"/> <xsl:text>°</xsl:text><xsl:copy-of select="$scale" /> </td>
    <td>
      <xsl:text disable-output-escaping="yes"><img src="http://us.i1.yimg.com/us.yimg.com/i/us/we/52/</xsl:text>
      <xsl:value-of select="rss/channel/item/yweather:condition/@code"/>
      <xsl:text disable-output-escaping="yes">.gif"/></xsl:text>
      <br/>
      <xsl:value-of select="rss/channel/item/yweather:condition/@text"/></td>
  </tr>
  <tr bgcolor="#CCCCCC"> 
    <td colspan="2"><strong>2 Day Forecast</strong></td>
  </tr>
  <tr> 
    <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="3" class="Normal">
      <xsl:for-each select="(rss/channel/item/yweather:forecast)[position() < 3]">
        <tr>
          <td><xsl:value-of select="@day"/></td>
          <td>
            <xsl:text disable-output-escaping="yes"><img src="http://us.i1.yimg.com/us.yimg.com/i/us/we/52/</xsl:text>
        <xsl:value-of select="@code"/>
        <xsl:text disable-output-escaping="yes">.gif"/></xsl:text>
          </td>
          <td><xsl:value-of select="@text"/><br/>High: <xsl:value-of select="@high"/>
            <xsl:text>°</xsl:text><xsl:copy-of select="$scale" /> 
             Low: <xsl:value-of select="@low"/><xsl:text>°</xsl:text><xsl:copy-of select="$scale" /> 
          </td>
        </tr>
       </xsl:for-each>
      </table></td>
  </tr>
  <tr bgcolor="#CCCCCC"> 
    <td colspan="2"><strong>More Current Condition Details</strong></td>
  </tr>
  <tr> 
    <td colspan="2"><table border="0" cellspacing="0" cellpadding="3" class="Normal">
        <tr> 
          <td>High </td>
          <td><xsl:value-of select="rss/channel/item/yweather:forecast/@high"/> <xsl:text>°</xsl:text><xsl:copy-of select="$scale" /></td>
        </tr>
        <tr> 
          <td>Low </td>
          <td><xsl:value-of select="rss/channel/item/yweather:forecast/@low"/> <xsl:text>°</xsl:text><xsl:copy-of select="$scale" /></td>
        </tr>
        <tr> 
          <td>Wind Chill </td>
          <td><xsl:value-of select="rss/channel/yweather:wind/@chill"/> <xsl:text>°</xsl:text><xsl:copy-of select="$scale" /></td>
        </tr>
        <tr> 
          <td>Wind Speed </td>
          <td>
            <xsl:value-of select="rss/channel/yweather:wind/@speed"/>
            <xsl:text> </xsl:text>
            <xsl:value-of select="rss/channel/yweather:units/@speed"/>
          </td>
        </tr>
        <tr> 
          <td>Wind Direction </td>
          <td>
            <xsl:value-of select="rss/channel/yweather:wind/@direction"/>
          </td>
        </tr>
        <tr> 
          <td>Sunrise </td>
          <td>
            <xsl:value-of select="rss/channel/yweather:astronomy/@sunrise"/>
          </td>
        </tr>
        <tr> 
          <td>Sunset </td>
          <td>
            <xsl:value-of select="rss/channel/yweather:astronomy/@sunset"/>
          </td>
        </tr>
        <tr> 
          <td>Latitude </td>
          <td><xsl:value-of select="rss/channel/item/geo:lat"/></td>
        </tr>
        <tr> 
          <td>Longitude </td>
          <td><xsl:value-of select="rss/channel/item/geo:long"/></td>
        </tr>
        <tr>
          <td>
            <p><xsl:text> </xsl:text></p>
            <p>
              <a href="http://weather.yahoo.com" target="_blank"></a>
            </p>
          </td>
        </tr>
      </table></td>
  </tr>
</table> 

</xsl:template> 

</xsl:stylesheet> 

Second XSL Variation:

2nd XSL Variation

<?xml version="1.0" encoding="ISO-8859-1"?> 

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<xsl:output method="html" indent="yes"/> 

<xsl:template match="/"> 

<xsl:variable name="scale">
    <xsl:value-of select="rss/channel/yweather:units/@temperature"/>
</xsl:variable> 

<table width="100%" border="0" cellspacing="0" cellpadding="3" class="Normal">
  <tr bgcolor="#CCCCCC"> 
    <td colspan="2"><strong>Weather Report - <xsl:value-of select="rss/channel/item/title"/></strong></td>
  </tr>
  <tr> 
    <td><strong>Currently <font size="4"><xsl:value-of select="rss/channel/item/yweather:condition/@temp"/><xsl:text>°</xsl:text><xsl:copy-of select="$scale" /></font></strong><br/>
      High <xsl:value-of select="rss/channel/item/yweather:forecast/@high"/> <xsl:text>°</xsl:text><xsl:copy-of select="$scale" /> <br/>
      Low <xsl:value-of select="rss/channel/item/yweather:forecast/@low"/> <xsl:text>°</xsl:text><xsl:copy-of select="$scale" /> </td>
    <td>
      <xsl:text disable-output-escaping="yes"><img src="http://us.i1.yimg.com/us.yimg.com/i/us/we/52/</xsl:text>
      <xsl:value-of select="rss/channel/item/yweather:condition/@code"/>
      <xsl:text disable-output-escaping="yes">.gif"/></xsl:text>
      <br/>
      <xsl:value-of select="rss/channel/item/yweather:condition/@text"/></td>
  </tr>
  <tr bgcolor="#CCCCCC"> 
    <td colspan="2"><strong>2 Day Forecast</strong></td>
  </tr>
  <tr> 
    <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="3" class="Normal">
      <xsl:for-each select="(rss/channel/item/yweather:forecast)[position() < 3]">
        <tr>
          <td><xsl:value-of select="@day"/></td>
          <td>
            <xsl:text disable-output-escaping="yes"><img src="http://us.i1.yimg.com/us.yimg.com/i/us/we/52/</xsl:text>
        <xsl:value-of select="@code"/>
        <xsl:text disable-output-escaping="yes">.gif"/></xsl:text>
          </td>
          <td><xsl:value-of select="@text"/><br/>High: <xsl:value-of select="@high"/>
            <xsl:text>°</xsl:text><xsl:copy-of select="$scale" /> 
             Low: <xsl:value-of select="@low"/><xsl:text>°</xsl:text><xsl:copy-of select="$scale" /> 
          </td>
        </tr>
       </xsl:for-each>
      </table></td>
  </tr>
    <tr>
    <td colspan="2">
        <p>
            <a href="http://weather.yahoo.com" target="_blank">Powered by Yahoo Weather</a>
        </p>
    </td>
  </tr>
</table> 

</xsl:template> 

</xsl:stylesheet>

Third XSL Variation:

3rd XSL Variation

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
 <xsl:output method="html" indent="yes"/>

 <xsl:template match="/">
  <style type="text/css">
   .location {
    width: 100%;
    text-align: left;
    font-family:  Tahoma;
    font-size: 10pt;
    background: #ffffff;
    color: #075199;
    border-collapse:collapse;
    border-color: #ace #ebf3fb #ace;
   }
   
   .location a:link, a:visited { text-decoration: none;  }
   .location a:hover   { text-decoration: underline;}
   
   .weather-condition {
    padding: 0px; 0px; 0px; 0px;
    width: 80px;
    min-width: 80px;
    max-width: 100px;
    text-align: center;
    font-family:  Tahoma;
    font-size: 8.4pt;
    bacground: #ffffff;
    color: #666;
   }

   .temprature {
    width: 50px;
    max-width: 70px;
    padding: 3px 6px 3px 6px;
    text-align: center;
    font-family: Tahoma;
    font-size: 10.5pt;
    border-collapse:collapse;
    border-color: #ace #ebf3fb #ace;
    color: #333333;
    font_weight: 700;
   }

   .high-low-text {
    padding-right: 3px;
    text-align: left;
    font-family: Tahoma;
    font-size: 8.4pt;
    font-weight: 700;
    color: #666;
   }
   .high-low-value {
    text-align: left;
    font-family:  Tahoma;
    font-size: 8.4pt;
    font-weight: 400;
    color: #075199;
    color: #333333;
   }
  </style>
  <table align="center">
   <tr>
    <td class="location" colspan="3">
     <a class="location" href="{rss/channel/item/link}">
      <xsl:value-of select='rss/channel/yweather:location/@city'/>
      <xsl:choose>
       <xsl:when test="rss/channel/yweather:location/@country='US'">
        , <xsl:value-of select='rss/channel/yweather:location/@region'/>
       </xsl:when>
       <xsl:otherwise>
        , <xsl:value-of select='rss/channel/yweather:location/@country'/>
       </xsl:otherwise>
      </xsl:choose>
     </a>
    </td>
   </tr>
   <tr>
    <td>
     <table>
      <tr>
       <td class="weather-condition" >
        <img src="http://us.i1.yimg.com/us.yimg.com/i/us/we/52/{rss/channel/item/yweather:condition/@code}.gif" />
       </td>
      </tr>
      <tr>
       <td class="weather-condition" >
        <xsl:value-of select='rss/channel/item/yweather:condition/@text'/>
       </td>
      </tr>
     </table>
    </td>
    <td class="temprature" >
     <xsl:value-of select='rss/channel/item/yweather:condition/@temp'/>
     <xsl:text>°</xsl:text>
    </td>
    <td>
     <table>
      <tr>
       <td class="high-low-text">High:</td>
       <td class="high-low-value">
        <xsl:value-of select="rss/channel/item/yweather:forecast/@high"/>
        <xsl:text>°</xsl:text>
       </td>
      </tr>
      <tr>
       <td class="high-low-text">Low:</td>
       <td class="high-low-value">
        <xsl:value-of select="rss/channel/item/yweather:forecast/@low"/>
        <xsl:text>°</xsl:text>
       </td>
      </tr>
     </table>
    </td>
   </tr>
  </table>
  <hr style="color:#C0C0C0; height:1px; padding: 0px 0px 0px 0px"/>
 </xsl:template>
</xsl:stylesheet>


Categories: RSS | SharePoint
Permalink | Comments (1) | Post RSSRSS comment feed

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

For some reason I started running into this error when I was trying to deploy a sharepoint webpart from visual studio. It just started happening out of the blue.

First I just rebooted the server and it deployed fine but when I made some changes to the code and tried to deploy it, the error came up again.

I found the answer here:http://social.msdn.microsoft.com/Forums/en/vsreportcontrols/thread/26accc30-9cfb-4d86-9c27-780f51929ecb

I had to add the ASP.NET account to each section.

  • Run dcomcnfg to bring up Component Services window.
  • Expand Component Services > Computers > My Computer > DCOM Config
  • Scroll down list, right click Windows Management and Instrumentation, and select properties.  A 5 tabbed window named Windows Management and Instrumentation Properties should be displayed.
  • Select the Security tab, then select radio buttons which activate the Edit... buttons.
  • Select the appropriate location and add the ASPNET account.
  • Reboot.
  •  


    Permalink | Comments (2) | Post RSSRSS comment feed

    Add a new line in a label control within a sharepoint webpart edit/config form

    I was creating a webpart and creating some custom edit values and I wanted to add a label for the dropdownlists I was adding.

    Adding the label before the dropdown was fine but I needed the dropdown on the next line. I tried using "<br/>" but that gave me an error when I tried to build it in visual studio.

    I tried System.Environment.NewLine but that didn't work and I tried "\n" with no luck and "\r\n" gave me an error when I tried to edit the webpart settings.

    I noticed that it seemed like the webpart error was being thrown whenever I had a slash combination in the text (i.e. "\r", "</...>") so I tried the non-html compliant "<br>" tag and that finally worked.

    Using this worked as well.

     myControl.Add(new LiteralControl("

    "))

    Categories: ASP.NET | SharePoint
    Permalink | Comments (2) | Post RSSRSS comment feed