Blog Home  Home |  Breeze Home RSS 2.0 Atom 1.0 CDF  
SCAREY Sharepoint Blog - November, 2009
Shannon - Breeze Training
# Monday, November 23, 2009

One place I often see new developers get stuck when developing with the SharePoint Object Model is trying to get information from a document library or list field

The place they get stuck is they write

string smyField = SPListItem.Fields[“myField”].ToString();

This will return the name of the column/field NOT the value within it

The trick is to write it like this

string smyField = SPListItem[“myField”].ToString();

Monday, November 23, 2009 11:33:11 AM (AUS Eastern Daylight Time, UTC+11:00)  #    Comments [0]    | 
# Tuesday, November 17, 2009

For many years, well since MOSS 2007 was released, I have always wanted to use the Content Query Web Part to display the results of multiple calendars.

I know there are many different projects to do this, free ones on Codeplex such as the Planet Wilson Colour Calendar and the SharePoint Enhanced Calendar by ArtfulBits  as well as the Bamboo Solutions SharePoint Calendar Plus Web Part which you can pay for. These are all great projects and solutions,

BUT

All I want is the plain old simple content query web part to work as it always has and display a calendar view. Users know how to use it and this way I don’t have to train them on a new web part.

So what I did was create a calendar view for the content query web part (or ContentByQueryWebPart). There is one change that was made from what you might expect, and that is I appended which site the calendar is from at the start of the calendar title

Please feel free to download and use this Web Part in you SharePoint environment

n.b If the calendar is not showing all the events make sure that you have increased the Item Limit under Presentation in the Web Part Properties

ContentByQueryCalendar.wsp (39.83 KB)

ContentByQueryCalendar.zip (38.31 KB)

Tuesday, November 17, 2009 12:51:12 PM (AUS Eastern Daylight Time, UTC+11:00)  #    Comments [0]    | 

I was recently working on a piece of code that required merging 2 DataTables based on 2 columns, however the table that I was merging the results into, I need not add the row if the columns matched. After searching around the net for a while and not really finding anything very useful I decided to write my own.

Essentially we get 2 DataTable’s and loop through the first one. If we find the where column1 and column2 in the first table row match column1 and column2 in the second DataTable row the we delete the row in the second DataTable. Finally we merge the2 tables with t duplicates removed.

The magic essentially happens with DataTable.Select and DataTable.Merge

This code is C# .NET

//tables that will be merged
DataTable table1 = new DataTable();
DataTable table2 = new DataTable(); //duplicates will be removed
 
//columns used to store what is found in the row's column
string column1 = string.Empty; 
string column2 = string.Empty;
 
// loop through the rows in the first table and if
// the columns are found on an item in the second
//table then remove it
foreach (DataRow row in table1.Rows)
{
    //set the column variables to what is in the 
    //current row
    column1 = row["column 1 Name"].ToString();
    column2 = row["column 2 Name"].ToString();
 
    //get an array of each of the rows that match
    //the columns in the current row
    DataRow[] duplicateRows = table2.Select("Section = '" + 
        column1 + "' AND Subsection = '" + column2 + "'");
    
    //loop through and remove each of the rows in the 
    //table that are duplicates 
    foreach (DataRow duplicateRow in duplicateRows)
        table2.Rows.Remove(duplicateRow);
}
 
//merge the tables so that we now have 1
table1.Merge(table2);
Tuesday, November 17, 2009 11:09:53 AM (AUS Eastern Daylight Time, UTC+11:00)  #    Comments [0]    | 
Copyright © 2010 Breeze Training. All rights reserved.