How to redirect a user to a custom page after adding a new List Item

This took me a while to figure out how to do this so I thought I’d share my experience.

Problem:
User needs to perform additional tasks after a new list item has been added to a list. I my case, I wanted the user to create a new list item of information that needed to be emailed to a certain group of people, based on what he/she selected in the new list item form.

Solution:
Create an Event Handler for the list and overriding the ‘ItemAdding’ method to:
(more…)

How to hide a SharePoint list column from a list form (New, Edit, and Display)

Managing the Content Type of a SharePoint List will provide you with the option to Show or Hide a column (aka Field) from the “New.aspx”, “Edit.aspx”, and “Display.aspx” list forms. If you didn’t want to show a column on any of the forms, you could select the column and ‘hide’ it from all forms.

Unfortunately, if you manage the content type of a list form, you are not able to choose which of these forms you can hide a column from. By default, hiding a column will be hidden on all forms.

In this post, I will show you how you can view all columns in your list and then choose which form to hide the column from.

(more…)

How to get all ‘Inherited Security’ sites in your SharePoint site collection

This article is nothing new to SharePoint developers. In fact, there are better options of getting a listing of all subsites in your site collection. However, for those who are not experienced developers, this article will give you an idea of what you can do with the SharePoint web services.

(more…)

How to add a SharePoint List field programmatically

You probably won’t have any reason to do this outside of the SharePoint UI, but it can be helpful if you have a number of lists you want to add a column (field) to. This little piece of code can come in handy.

(more…)

Code Snippet: Delegating elevated priviledges to your SharePoint method


try
{
	SPSecurity.RunWithElevatedPrivileges(delegate()
	{
		using (SPSite site = new SPSite(properties.WebUrl))
		{
			using (SPWeb web = site.OpenWeb())
			{
				//do code
			}
		}
	});
}
catch (Exception ex)
{
	//
}

(more…)

When to use SystemUpdate when editing a SharePoint list item programmatically


When coding against the SharePoint object model, I will generally do the following:

  string newFolderName = "My new folder name";
  folder.Item[SPBuiltInFieldId.Title] = newFolderName;
  folder.Item.Update(); // or SystemUpdate(false)

(more…)

Adding an attachment to a SharePoint list item programmatically

I needed a way to upload an attachment to a list item within an Event Handler but discovered it was not that simple. Now that I have the code to add attachment to a list item, I don’t want to lose it.

The following code can be called from a web part or an application page easily. What was complicated for me was trying to attach a file from the ItemAdding/ItemAdded Event Handler.
(more…)

Connecting to the SharePoint ‘Lists.asmx’ web service without having to manually create a Web Service Reference

Up until recently I have been manually adding a Web Service Reference to my WinForms and WPF projects. I have been connecting to the SharePoint Web Services to pull data from my sites because of the limitations of not having access to the server to use the SharePoint Object Model. In an ideal situation, I would much rather use the SharePoint Object Model to access SharePoint data because I can do more with it and it’s not as complicated as using the SharePoint Web Services.

I’ve often wondered how I can reference the ‘lists.asmx’ web service without having to manually add a Web Service Reference in Visual Studio. Following this approach, you can call a web service (any web service) from your WinForms, WPF, Javascript, ASP.NET, etc. applications. (more…)

Using an XML “settings” file to store values for your SharePoint projects

I recently created a SharePoint timer job solution that relied on the data in a list as to what the function of the job was to do. The solution requirement was to have a timer job set to run at 8:00am every Thursday that would read SharePoint list data and create a customized email of that data for the week.

Since I work in an environment with multiple SharePoint farms, I had to rely on a ‘settings’ file that I could easily change without having to recompile and redeploy my WSP solutions. I will show you how to read the nodes and values of an XML file located in a SharePoint list that your SharePoint solutions can reference, thus eliminating the need to recompile your code for each SharePoint farm. Let’s get started…
(more…)

How to add a new list item to SharePoint using the List Item web service

I have spent many hours trying to research something so simple that its almost embarassing. I have been a C# developer for 7 years, but am self-taught. Not this is an excuse for my inability to comprehend how to do such a simple task.

Thanks to Stamit’s CamlViewer 2007 and the U2UCamlCreator, I have been able to understand more about how CAML queries work. This has helped me understand the concepts behind adding new List Items.

First, Add a new Web Reference to your SharePoint site’s List webservice (more…)