Byte My Data

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

About the author

Something about the author

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

Comments

Exam Cram United Kingdom

Thursday, February 09, 2012 1:18 PM

Exam Cram

I collected a lot of interesting things from your blog especially its discussion. I believe I’m not alone having all the enjoyment here! keep up the great work.

Official Nike soccer cleats People's Republic of China

Tuesday, March 06, 2012 3:25 AM

Official Nike soccer cleats

I first became <strong><a href=http://www.gotsoccershoes.com/>Official Nike soccer cleats</a></strong>interested in current events<strong><a href=www.gotsoccershoes.com/...-sl-c-157.html>Adidas adiPure IV SL</a></strong> in 1956 when I was just 10 years old.

business directory United States

Sunday, May 13, 2012 10:06 PM

business directory

Another insightful post. You know, I am absolutely delighted I found this. I'll digg this blog so my friends can read your writing too!

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading