|
|
SharePoint or WSS AddUser generates Microsoft.SharePoint.SPException
|
 |
|
by: Jason Fortner
|
 |
|
When you are working in Sharepoint or WSS (Windows Sharepoint Services) sites many items
can be done programmatically. One webpart I have created is to add users from a tab
delimited file to the sites. This is very useful when sites are being setup for
production and a lot of users need to be added at one time. You can find more information
about the webpart on the
Total Productivity Solutions Portfolio Page.
|
 |
|
 |
|
In the creation of this webpart I was reminded of an issue that will appear
commonly when working within Sharepoint and WSS programmatically. When you
are using SPRole.AddUser or some other commands that programmatically update
data on the site you may receive a Microsoft.Sharepoint.SPException that reads
"The security validation for this page is invalid. Click Back in your Web browser,
refresh the page, and try your operation again."
|
 |
|
When you get the SPException in this situation in Sharepoint or WSS all you need to
do is allow unsafe updates to the site. This can be done by setting the
AllowUnsafeUpdates to true when you get an instance of the SPWeb that you will
be working with in your code.
|
 |
An example of this would be:
SPSite site = new SPSite(http://localhost/url);
SPWeb web = site.OpenWeb();
Web.AllowUnsafeUpdates = true;
|