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 (0) | Post RSSRSS comment feed

Get the next auto increment id in MySQL for Joomla articles

Here's a great little query to get the next auto increment id. It's better than grabbing the last id and incrementing it because entries may have been deleted that were added after the last id.

SELECT AUTO_INCREMENT AS id
FROM information_schema.tables
WHERE table_schema = 'mydatabase'
AND table_name = 'mytable';

Or for Joomla where I needed it:

$query = "SELECT AUTO_INCREMENT AS id FROM information_schema.tables WHERE table_schema = 'mydatabase' AND table_name = 'jos_content'";
$db->setQuery($query);
$rows = $db->loadObjectList();
$nextid = $rows[0]->id;

 


Permalink | Comments (0) | Post RSSRSS comment feed

MSN Live Messenger video call not working on Windows 7

When I tried to go into a video call on msn messenger with my Microsoft LifeCam VX-1000, it would throw an error something to the effect of "messenger is not available".

In order to fix it, I changed the compatibility setting in the properties for Windows Live Messenger (right click properties on Start -> All Programs -> Windows Live -> Windows Live Messenger) to "Windows XP (Service Pack 3)".

 


Permalink | Comments (0) | Post RSSRSS comment feed