472,340 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,340 software developers and data experts.

Need help Web Application VS 2005

I'm trying to debug the following code against a moss 2007 portal, using vs 2005. It's a web application with an .aspx page that contains a label, a text box and a button. The user writes a user account in the text box and on button click the groups for the user are returned. The error that it appears is
'An exception of type 'System.NullReferenceException' occurred in WebApplication2.DLL but was not handled in user code

Additional information: Object reference not set to an instance of an object'

highlighting the code line:
SPWebCollection allSites = mySite.AllWebs;
The whole code follows:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Utilities;

namespace WebApplication2
public partial class _Default : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)


protected void Button1_Click(object sender, EventArgs e)
string userList = TextBox1.Text + " is a user in the following webs:<br>";

SPSite mySite = SPControl.GetContextSite(Context);
SPWebCollection allSites = mySite.AllWebs;

foreach (SPWeb subSite in allSites)
string listGroups = "";

SPUserCollection allUsers = subSite.Users;

foreach (SPUser user in allUsers)
if (user.LoginName == TextBox1.Text)
SPRoleCollection allGroups = user.Roles;
foreach (SPRole group in allGroups)
listGroups += SPEncode.HtmlEncode(group.Name) + " ";

userList += subSite.ServerRelativeUrl.ToString() + " -- " + listGroups + "<BR>";

Label1.Text = userList;

Any suggestions would be more than welcomed...
Jan 15 '07 #1
0 1165

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Dmitry Demchuk | last post by:
Hi everybody. Recently I ran into situation with System.Threading.Timer in my ASP.NET application. I reinstalled Windows on one of my servers and...
by: Mike Owen | last post by:
Hi, I have just used the import Wizard to import a VS 2003 app to VS 2005. I have a lot of work to do to enable it to compile successfully with...
by: ChrisWinterscheid | last post by:
We are running DB2 8.1 on AIX 5.2. DB2level shows: DB21085I Instance "db2inst1" uses "32" bits and DB2 code release "SQL08016" with level...
by: fayez | last post by:
Hi. I have a sql Stored Procedure running on aix5.1, db2 udb 8.1.2 it has a temp table, but when it's done running it does not free heap memory,...
by: Likhith Areekkal | last post by:
Hi, My background: Passed Bachelors in Computer Science 2 years back with distinction in Canada. Had to do survival jobs for 2 years as the...
by: Mart | last post by:
Hi, I have just written (my first) VB.net app using MS Visual Basic 2005 Express Edition Beta. It is fairly simple, it reads some configuration...
by: nihad.nasim | last post by:
Hi there, I have a database in Access that I need on the web. The web page should connect to the database and write records for certain tables and...
by: Algonquin J. Calhoun | last post by:
I've developed an application that exceeds the Access 2GB limit. This application was developed as a prototype and the users have found it very...
by: cj | last post by:
I have used web services before WSDL files and such but never written one. I need some basic starting info. 1. Can I write a web service in a...
by: rmgalante | last post by:
I was developing a large web site in VS 2005 as a web site project. I was having problems with the VS 2005 publish tool. It was slow, and provided...
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.