Archive

Posts Tagged ‘C#’

Why can’t I access the column in my SharePoint list programatically?

October 26, 2012 2 comments

The answer might be simple. The first time a column is created and you title it “Column1” the database records that. If you (or someone else) later changes the column title to “Column2” your application will break. Why? Because behind the scenes that column is still “Column1”

Advertisement

Populate a drop-down list with SharePoint list values

October 25, 2012 Leave a comment

This video will demonstrate how to populate a asp.net drop down list control with SharePoint list column values. I’ve created a visual web part in Visual Studio 2010 and used the sever object model to demonstrate this. However, you can populate a drop down list with the client object model if you prefer.

Get the code

Populating a drop-down with list values using C# for SharePoint 2010

October 12, 2012 Leave a comment

  • Finds the list “My Tasks”
  • Gets all items from the “Title” column in the “My Task” lists
  • Uses a foreach loop to add all of the “Title” columns values to a drop-down.

Watch the video to see how it works.

Moving repeating table values to another list using a Visual Web Part in C#

October 12, 2012 Leave a comment

InfoPath 2010 repeating tables are useful and sometimes even essential to the project requirements. However, they carry with them some problems. For one thing when multiple values are entered into an InfoPath 2010 form all of the values become crammed into one SharePoint 2010 column. This will cause all kinds of problem down the road if you ever need to access that Info and/or filter it etc. So the following example shows how to move the repeating table values to a separate list where the values can be more efficiently managed.

  • I’ve created a Visual Studio 2010 visual web part that fires the code on page load
  • You must have a delimiter to separate the values. In this case I have used a ;
  • Do NOT add a ; to the last repeating table entry. If you do you will have and extra record in the new list.

How does it work? View the Video below:

How do I: Setup Visual Studio 2010 Console application to work with SharePoint 2010

October 12, 2012 Leave a comment

Sooner or later the time will come when you will need to use a console application to complete
some type of task in SharePoint 2010. For instance you might need to merge data from
one list into another list using C#. However before you can start coding you need to set up the
the console app to interact with SharePoint 2010. The following video demonstrates how.

NOTE: This will not work for SharePoint Online

A closer look: SPListItem Class and Visual Studio 2010

The web server process that was being debugged has been terminated by Internet Information Services (IIS)

October 12, 2012 Leave a comment

Recently I was working on a project that required some debugging. I found myself getting the following error. Watch the video to see how I “fixed” the problem.

Programmatically setting a field to hidden within a Content Type #SharePoint #SP2010 #in

February 9, 2011 2 comments

At a client recently, my development colleague was struggling to find out how to set a field attached to a custom Content Type in a list to be hidden to aid in document management (so it is not shown in the Document Properties panel in Microsoft Word).

The following post seemed to suggest an unofficial way:

However, we try to keep things in a supported model if possible.

Through further looking he came across the following property:

    After further playing in code, he managed to crack it with the “.hidden” method.
    Code Example:

This code will set the Hidden flag (same as you can through the UI) against the document library. The above iterates through a List of strings which contains the fields i want to hide.

    1 SPContentType docCT = docLib.ContentTypes[0]; 2 3 foreach (string fieldDispName in fieldsToHide) 4 { 5 SPField field = docCT.Fields[fieldDispName]; 6 docCT.FieldLinks[field.Id].Hidden = true; 7 } 8 9 docCT.Update(); 10

NB: Please not that this works because we are using our own content type attached to the library.

%d bloggers like this: