stsadm Access Denied Error

02/02/2010

This is probably because you have User Access Control (UAC) turned on. Turn it off, via-Control Panel and you would not have the problem anymore.


Create a List Item (70-541)

18/12/2009

SPSite oSite = new SPSite("http://rootsite");
SPWeb oWeb = oSite.AllWebs["subsite"];

SPListItemCollection oItems = oWeb.Lists["list title"].Items;

// Create a New Item
SPListItem oItem = oItems.Add();
oItem["field"] = "value";
// Code that populates other fields

oItem.Update();

// Clean up
oWeb.Dispose();
oSite.Dispose();


Delete a List Item (70-541)

18/12/2009

SPSite oSite = new SPSite("http://rootsite");
SPWeb oWeb = oSite.AllWebs["subsite"];

SPListItemCollection oItems = oWeb.Lists["list title"].Items;

// Enumerate through all list items
foreach (SPListItem oItem in oItems)
{
   // Delete a List Item
   if(oItem["field"].ToString() == "value")
   {
      oItem.Delete()
      return;
   }
}

// Clean up
oWeb.Dispose();
oSite.Dispose();

Note, the return statement right after the item has been deleted. You do not want to keep looping through all list items once we’ve deleted the one required, as you will be thrown an exception.


Update a List Item (70-541)

18/12/2009

SPSite oSite = new SPSite("http://rootsite");
SPWeb oWeb = oSite.AllWebs["subsite"];

SPListItemCollection oItems = oWeb.Lists["list title"].Items;

// Enumerate through all list items
foreach (SPListItem oItem in oItems)
{
   // Update a List Item
   if(oItem["field"].ToString() == "value")
   {
      oItem["field"] = "new value";
      oItem.Update();
      return;
   }
}

// Clean up
oWeb.Dispose();
oSite.Dispose();


Enumerate List Items (70-541)

18/12/2009

SPSite oSite = new SPSite("http://rootsite");
SPWeb oWeb = oSite.AllWebs["subsite"];

SPListItemCollection oItems = oWeb.Lists["list title"].Items;

// Enumerate Through All List Items
foreach (SPListItem oItem in oItems)
{
   // Additional Code
}

// Clean Up
oWeb.Dispose();
oSite.Dispose();


Remove a User from a Site Group (70-541)

17/12/2009

SPSite oSite = new SPSite("http://rootsite");
SPWeb oWeb = oSite.AllWebs["subsite"];

SPGroup oGroup = oWeb.Groups["securitygroup"];
SPUser oUser = oGroup.Users["domain\\loginname"];

oGroup.RemoveUser(oUser);
oGroup.Update();

// Clean Up
oWeb.Dispose();
oSite.Dispose();


Add a User to a Site Group (70-541)

17/12/2009

SPSite oSite = new SPSite("http://rootsite");
SPWeb oWeb = oSite.AllWebs["Subsite"];

SPGroup oGroup = oWeb.Groups["SecurityGroup"];
oGroup.AddUser("domain\\loginname", "emailaddress", "username", "notes on user");
// Alternatively use oGroup.AddUser(SPUser object);

oGroup.Update();

// Clean Up
oWeb.Dispose();
oSite.Dispose();

Note: When specifying a user login name, don’t forget the domain name before (e.g: domain\\loginname). It is also not necessary to specify a user’s email address or notes on the user.


Custom Application Page “is inaccessible due to its protection level”.

01/12/2009

“is inaccessible due to its protection level at System.Web.Compilation.AssemblyBuilder.Compile()”

This was the error I got when I navigated to my custom application page (Note: I have custom errors turned off and call stack set to true on my web.config)

The problem faced here was that my class access modifier was not specified (so it defaults as private). All I had to do was change my class access modified to public and this fixed the problem.


Custom Application Page "does not contain a static method suitable for an entry point"

01/12/2009

This error came up as I attempted to build my code. No biggie here, and it was totally my own silly fault. You see, my Visual Studio project Output type was set to Console Application.

To fix this, all I did was right-clicked on my Project, then selected Properties. On the Project Properties window, I selected the Application tab. And on the Application window, I changed the Output type from Console Application to Class Library. Save the project and rebuild, no problems at all.

error


Custom Field, The given assembly name or codebase was invalid

01/12/2009

This is often the case where our control(s) have not been created appropriately. Have a look at the CreateChildControls() override method.

Remove or comment out the base.CreateChildControls() line from the method.

Rebuild and replace the assembly back into the Global Assembly Cache (GAC), and the field would work as it should with no exceptions.