Sunday, August 02, 2009

SilverLight Organization Chart


There was an Organization Chart in the scope of one of the projects I’m managing, and it came to me the idea to make it in SilverLight the same way in http://svdemo02.ilog.com/SilverlightOrgChart/OrgChart.html


And here are the main points to make it out:

1. Working with Canvas
2. Drawing Lines and Boxes
3. Using ScrollViewer
4. Using Slider (for the scale)
5. Using SilverLight UserControls (the node element with the person information)
6. Reading data from XML files and web services
7. Some Calculations

And isA I’ll describe these main ideas in details during the coming days.

Update: for the source code go to http://silverorgchart.codeplex.com/

Clip a TextBlock in SilverLight

One of the things that you may need to do in SilverLight is to limit the display area of a TextBlock, and you can do that using the Clip property, there are two ways to do that.

1. From the XAML

<TextBlock x:Name="tbExtension" Width="130" Height="30" Foreground="Black" Canvas.Left="5">
<TextBlock.Clip>
<RectangleGeometry Rect="0, 0, 130, 30"/>
</TextBlock.Clip>
</TextBlock>

2. From the code behind

tbExtension.Clip = new RectangleGeometry() {
Rect = new Rect(0, 0, width, height)
};

Monday, July 20, 2009

SSO and IFrame, more details please

I have faced some projects for example intranet portal for a company or organization, and one of the modules is to make SSO with an existing application and that we will load the application within an IFrame in our page, something seems very simple, but is it that simple in the client imaginations or he will find something else at the end with the delivery, so we must make some point clear to the customer from the beginning like:

A. Points related to the SSO:
1. SSO itself
2. Sign out
3. Session expiration
4. Browse directly to the application URL

B. Point related to the Frame:
1. Frame/Iframe
2. Header
3. Welcome Message
4. Navigation



A.1. SSO itself:
A group of questions we must know here depend on the case , is it a product or the client have the source code, can we add some pages or DLLs to the application, can we use cookies, what will be the authentication type in both applications, can we encrypt/decrypt, can we use ISA to authenticate the users, can we use MOSS SSO, is there a common membership provider, and so on.

A.2. Sign out:
Is it required to sign the user out from the portal if he click on sign out in the other application, or is it required to sign him out from the application if he click on sign out from the portal? Where I’ll redirect the user in the portal if he logged out from the application?

A.3. Session expiration
How we will manage the session expiration in any of the two applications, the user may expend more time on the application and his session on the portal is expired and vies versa. Is it required to keep the session live while the user is browsing the other application?

A.4. Browse directly to the application URL
What if the user type the URL of the application while he is already signed in on the portal, is it required to authenticate him on the application also or not.

B1. Frame/Iframe:
What about the look of the page, is it okay to have many scroll bars in the same page, is the size of the frame is sufficient to display the application screens? What about the color schema of the application, is it okay with the portal colors? So we can ask, what is the problem with a popup/new window?

B2. Header:
If the application has his own header, so you will have two headers in the same page which mean more lost space, and may be two logos.

B.4. Navigation:
The same here for the navigation, if the application has its own navigation, so we will have extra navigation and extra lost space, and for the usability it is not a good practice.

B3. Welcome Message:
In case the two applications have separated membership providers or user profiles, you will see in the same page for example, Welcome omourad and Welcome Osama Mourad, is it okay? And the user may sign in with another user in the application, you will see in the same page for example Welcome omourad and Welcome Ahmed El Said.

Tuesday, July 14, 2009

Paging SPList with ListItemCollectionPosition

Using ListItemCollectionPosition to make paging is somehow tricky, you have to take care if you are using order in your CAML query that you need to make paging on, as the parameters passed to ListItemCollectionPosition like “Paged=TRUE&p_ID=8” is not just to say star from the itemID = 8, when it is used like this, the paging will page based on the default order.

But if you want to order by example the created date in your CAML query, so you have to include that also in your ListItemCollectionPosition parameters, ex:

Paged=TRUE&p_Created=20091208%2006%3a24%3a35&p_ID=8

Where p_Created=20091208%2006%3a24%3a35 is the created date of the itemID = 8

If it is not used like that you will see unrealistic output.
A good idea to make paging is by making an array that its index will be the page index, and its value will be the ListItemCollectionPosition.PagingInfo like this:

void SetupPager(SPList tmpList, string queryString)
{
    myPagingData.Add("Paged=TRUE");
    SPQuery query = new SPQuery();
    query.Query = queryString;
    query.RowLimit = 5;
    do
    {
        SPListItemCollection itemList = tmpList.GetItems(query);
        query.ListItemCollectionPosition = itemList.ListItemCollectionPosition;
        if (query.ListItemCollectionPosition != null)
        {
            myPagingData.Add(query.ListItemCollectionPosition.PagingInfo);
        }

    }
    while (query.ListItemCollectionPosition != null);

}

The above method can be called in the first time the page is opened, and you can add array to the viewstate and reload it with each postback and pass it to the query like this:
SPListItemCollectionPosition objSPListColPos = new SPListItemCollectionPosition(myPagingData [e.CurrentPage]);
query.ListItemCollectionPosition = objSPListColPos;

Wednesday, July 08, 2009

Forms Authentication with LDAP provider in Sharepoint - Part 2

We talked on how to configure a SharePoint site to use Forms Authentication on LDAP provider, but to complete the scenario we have to update the UI of the login page, this will work the same if any other forms authentication providers will be used.

Once the authentication provider is changed from the central administration the web.config file will be also updated as:

<authentication mode="Forms">
<forms loginUrl="~/layouts/ login.aspx" />
</authentication>

Where the login.aspx file is the default login page for SharePoint and you can go to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS and update the login.aspx directly in this path, or make a copy from this page to any folder under your application ex. In a folder named login, you may also need to update the master page that this page is using, you can do this, by coping the new master page to the same folder, or copy simple.master from the same path and update it.

To change the master page that the login.aspx page use you can type:

<script runat="server">
void page_PreInit(object sender, EventArgs e)
{
this.Page.MasterPageFile = "~/login/mymasterpage.master";
}
</script>

This will update the master page on the fly as you can't just update the masterpage path from the aspx page.

Also, you may need to add StyleSheet file and some images to be displayed in this login page, and you can’t reference any file stored in the SharePoint libraries and you have to be authenticated first, so you can add a web.config file in the same folder that just have:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration>
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</configuration>

This will allow the anonymous user (till now) to be able to request the css, js and images.

Tuesday, July 07, 2009

Forms Authentication with LDAP provider in Sharepoint - Part 1

I was working on an extranet SharePoint project, on the requirement gathering it was agreed to have windows authentication, but after the deployment and during the UAT, the customer reported to us that he didn’t like the popup login window, and he want it to be forms authentication to have a better look, one solution is to publish the site using the ISA server that will request the username and password from the user via a form and path it to the SharePoint. Here is a good article on how to be done.

Another solution is to use forms authentication with LDAP provider, and here are the steps to do it:

Configure the Central Administration and the application:
1. Extend the application
2. Update the authentication type of the extended application to forms authentication, add the membership provider name, ex: LdapMembership
3. In the extended site folder update the web.config file, add:

<membership defaultProvider="LdapMembership">
<providers>
<add name="LdapMembership"
server="devtfs08-ksa"
port="389"
useSSL="false"
userDNAttribute="distinguishedName"
userNameAttribute="sAMAccountName"
userContainer="CN=Users,DC=Devksa,DC=com"
userObjectClass="person"
userFilter="(ObjectClass=*)"
scope="Subtree"
otherRequiredUserAttributes="sn,givenname,cn" type="Microsoft.Office.Server.Security.LDAPMembershipProvider, Microsoft.Office.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C" />
</providers>
</membership>

4. In the above code, “devtfs08-ksa” is my server name, my domain name is “devksa.com” The port number 389 is the default number, and userFilter=”(ObjectClass=*)” will get all the users and groups.
5. Update the web.config file of the central administration site to be able to set the site administrator, you can make the first user as the admin on the default zone, and the second user is the admin on the extended zone.
6. Browse to the extended site and test the login.

Configure the User Profiles import:
1. Go to the User Profiles and Properties in the SSP
2. Click on View Import Connections, delete the current Active Directory connection, and create a new one.
3. Select the type “LDAP Directory” and use the same values in the above membership provider as a values to the form.
4. Click on the button “Auto Fill …”
5. In the search base update it to use UserContainer value from the values above.
6. Update the user filters to use the same values as above.
7. Add a username and password to an account that can list the directory.
8. Start full import.

The same can be done for MySite, but the user will be asked for his username and password when he browse from the intranet portal to his Site in case they are both on different application polls which is recommended.

Monday, June 29, 2009

UmAlQura Calendar in SharePoint

I was working on a calendar webpart that is used to display events stored in a MOSS list, each item in the list will have a start date and end date, when this webpart is added in an English site it shows Gregorian calendar and on an Arabic site is shows the Hijri calendar based on the regional settings for each site, but the problem was that the Hijri calendar is not accurate and the admin must go the regional settings page to add or subtract day or two to show the right dates.

On the other side there is the UmAlQura calendar which is based on an array that relate the start of each Hijri month to a Gregorian calendar day, It can be used for dates in range between 1318/01/01 and 1450/12/29 which is good to be used for articles dates and events and birthdates and so on.

So I changed the calendar format for my culture to be UmAlQura and it works perfect, but the problem is that the events are added in the list that is using Hijri calendar as a default for the Arabic site, and there is no UmAlQura calendar option in the regional settings to select, so I searched for how to make and add a custom calendar to SharePoint and found this link but still can’t find the answer

The other thing I found and it was very weird when I write e.Day.Date in the calendar cell (in the Arabic site) it gives me a full Hijri date (27/09/1430) but when adding e.Day.Date.Day it gives me the equivalent day number from the Gregorian calendar

Wednesday, June 17, 2009

Alternate Styling

Want to make alternate styling in a DataViewWebPart or ContentQueryWebPart? Here is the way:

<tr>
    <xsl:if test="position() mod 2 = 0">
        <xsl:attribute name="class">AlternatingClass</xsl:attribute>
    </xsl:if>

    <td ...>
    ...
</tr>

Where AlternatingClass: is the alternating class name that will be the value of the class attribute of the TR tag.

Saturday, June 13, 2009

Separate XSL files for Content Query Webpart (CQWP) - Part 2

We have talked before on how to Separate XSL files for Content Query Webpart (CQWP), but we didn’t go in details for how to make your own Main.xsl file that can be used as the ContentQueryMain.xsl, the steps in the previous post will be used, we will create a new XSL file and name it for example “usefulLinksMain.xsl” and add its path to the “MainXslLink” property in the webpart file.

The next step is to have a look on the minimal main xsl file:

<xsl:stylesheet
version="1.0"
exclude-result-prefixes="x xsl cmswrt cbq"
xmlns:x="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cmswrt="http://schemas.microsoft.com/WebPart/v3/Publishing/runtime"
xmlns:cbq="urn:schemas-microsoft-com:ContentByQueryWebPart">


<xsl:include href="/Style Library/XSL Style Sheets/ContentQueryMain.xsl"/>


<xsl:template match="/">
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row" />
<xsl:variable name="RowCount" select="count($Rows)" />
<xsl:variable name="IsEmpty" select="$RowCount = 0" />
<xsl:choose>
<xsl:when test="$IsEmpty">
<xsl:call-template name="OuterTemplate.Empty" >
<xsl:with-param name="EditMode" select="$cbq_iseditmode" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:choose>

<xsl:when test="dsQueryResponse/Rows/Row/@Style='UsefulLinks'">

<xsl:for-each select="$Rows">
<xsl:variable name="CurPosition" select="position()" />
<xsl:call-template name="MyMain.CallItemTemplate">
<xsl:with-param name="CurPosition" select="$CurPosition" />
</xsl:call-template>
</xsl:for-each>

</xsl:when>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="MyMain.CallItemTemplate">
<xsl:param name="CurPosition" />
<xsl:apply-templates select="." mode="itemstyle">
<xsl:with-param name="CurPos" select="$CurPosition" />
</xsl:apply-templates>
</xsl:template>

</xsl:stylesheet>



You can also update the three values to point to the same xsl file like that:

<xsl:stylesheet version="1.0"
exclude-result-prefixes="x d xsl msxsl cmswrt"
xmlns:x="http://www.w3.org/2001/XMLSchema"
xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"
xmlns:cmswrt="http://schemas.microsoft.com/WebParts/v3/Publishing/runtime"
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">

<xsl:template match="/">
<xsl:call-template name="MyTemplateName" />
</xsl:template>

<xsl:template name="MyTemplateName">
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>

<table border="0" cellpadding="0" cellspacing="0" width="100%">

<xsl:for-each select="dsQueryResponse/Rows/Row">
<tr>
<td><a href="{@LinkUrl}" ><xsl:value-of select="@Title"/></a></td>
</tr>
</xsl:for-each>


</table>

</xsl:template>
</xsl:stylesheet>

The two solutions are the same idea, but in the first one you can select the ItemStyle you want from the content query web part tool part.

Sunday, June 07, 2009

MCTS: Microsoft Office SharePoint Server 2007 – Configuration

I have attended a five days course “50047A: Advanced IT Pro Course for Microsoft Office SharePoint Server 2007 and Windows SharePoint Services 3.0” at Microsoft Innovation Center – Al-Yamama University , The instructor was Muhannad Omar. At the end of the course Muhannad gave me a book “Microsoft Office 2007 – Best practice” and it was very nice from him.

And today, Al-Hamd Lellah, I passed the exam “70:630 - Configuring Microsoft Office SharePoint Server 2007” and now I’m Microsoft Certified Technology Specialist: Microsoft Office SharePoint Server 2007 – Configuration.

أمي ... أبي

كتبت هذه الاسطر في الصف الأول الثانوي لأهديها لأمي وأبي:

أمــــي أبــــي ، قــط وليــث عــنـدنـا و حـبـذا الأبـويـن في الحيـوان
فـالـقـط معـروف بتربية الصغار والـلـه قـد خلقه لكون حـــــــــــنان

الناسُ قـد شهدوا النظافة للقطط، أحـرص عليها فإنها لإيــــــــــمـان
والأًســدُ تـرعى م الـمـخـاوف شبلهـا والـلـه قـد خلقه لكون أمــــان
إن كنت تعرف في الأسود شجاعة، فالشبل يعرف في الأسود حنان

Tuesday, May 26, 2009

From My Site to the Portal

Many people are asking “Why there is no link to go back from My Site to the portal?” and the answer is very simple, My Site may be shared between more than a portal, in this case which link you will display?

But still you can make a link to a preferred portal, go to Site Actions > Site Settings > Site Collection Administration > Portal Site Connection > then type the URL and the title for the portal you want the users go back to from My Site.

Monday, May 25, 2009

Absolute Paths in SharePoint

What if you want to add an image to your MasterPage that will be changed in each sub site, a logo for example, you can add an image tag like this:

<img src="../SiteImages/MyLogo.gif" alt="SubSiteLogo " />

This is fine when you are browsing a page in the Pages list (http://www.mysite.com/subsite/pages/mypage.aspx), but what if you are browsing an overview.aspx page for example for a Survey list (http://www.mysite.com/subsite/lists/surveyname/overview.aspx), you will need to change the tag to:

<img src="../../SiteImages/MyLogo.gif" alt="SubSiteLogo " />

So how to add the image tag to make it work for both pages?
The solution is to change your tag to this:

<img src="<% $SPUrl:~Site/SiteImages/MyLogo.gif %>" alt="SubSiteLogo" runat="server"/>

Where ~Site is your absolute current site URL

Okay, now what if this image is not changed per sub site, but it is changed per SiteCollection and the url is something like this: (http://www.mysite.com/anothersitecollection/subsite/pages/mypage.aspx), in my default SiteCollection I can make the tag like this:

<img src="/SiteImages/MyLogo.gif" alt="SubSiteLogo " />

But in another site collection this will not work with me, so I can make it like this:

<img src="<% $SPUrl:~ SiteCollection/SiteImages/MyLogo.gif %>" alt="SubSiteLogo" runat="server"/>

The same thing here with the stylesheet, you can do the same:

<link rel="stylesheet" type="text/css" href="<% $SPUrl:~Site/StyleSheets/MyStyle.css %>" runat="server"/>

Wednesday, May 13, 2009

Things to ask the client about before working on My Site

In a MOSS project the RSD may say: “out of the box My Site”, but you have to make sure that the system analyst has asked the client the below questions:

1. Do you really need My Site, or can the requirements be developed?
Sometimes the user just wants to display the user information, but he heared that there is something called MY SITE and he wants it.

2. What is the expected number of users that will create My Site?
The expected number of MY SITEs is very important, as it is a factor of space and performance, as each My Site is a site collection and the default quota is 100 MB for each site. I was working on a project for a big organization that has 15000 users, but for obviously not all of those users will create My Site.

3. Will all the users be able to create "My Site"?
Some organizations like the 15k users case, for obviously not all of them will be able to create My Site as some of them are contractors that are doing a task and will leave after two or three months and may be more, but they will not be allowed to create My Site.

4. Do we need the 100MB for each site?
100MB is a very large space, and may be very small for others, but the expected or the planed size is very important to make your hardware architecture regarding the performance and the storage space and the storage place (this is another question but you will need to answer it yourself, as you may need to create a group of My Sites that belong to a group of users in a place and another group in another place).

5. Do you have only one AD domain or more?
More domains means that a username may be duplicated, so you must configure the settings to take the domain name in site URL, not just the username.

6. What is the authentication type of the OWA, In Case you will use Outlook webparts?
You will need to know this, as the forms authentication will display the login window inside each webpart iframe with a scroll if the webpart size is smaller, you may decide to pass the credentials using JavaScript and submit the form (you have to configure the trusted sites in the browser and make the OWA and the intranet site on the same domain but using a different sub-domains) , also what is the used version of the Exchange Server

7. Is the email address the same as the username?
Some organizations are using username like domain\usr24hr and the email for this user is ramy.fawzy@domain.com for security reasons. In this case take care while working on customizing Outlook webparts automatically to set the exchange server address and the email inbox name.

8. Will you allow the user to select his "My Site" language or not?
In multiple language websites it may be a needed to allow the user to select his My Site interface language. The client may imagine that it can be English/Arabic the same as his portal for example.

9. Do you need to customize in the layout or not?
Some customers ask for My Site, but they don ‘t know that it will not inherit the portal MasterPage, and they will be shocked after the site deployment, so make it clear from the beginning for him and for yourself.

Wednesday, May 06, 2009

Listing Folders, SubFolders and Items in one page

It was requested from me to make a page in MOSS that will display Departments in an organization, and there is a set of sub departments and in each sub department there may be another group of sub departments and then a list of file library that may also be divided into groups.

I want to save all these files in only one document library but divide them into folders and subfolders as required, and make the minimum number of pages and code to display these folders and items and without any .net coding.So my solution is to make a page in SharePoint designer and add a DataSource and a DataView then make the following steps:

1. In the SPDataSource add Scope="RecursiveAll" this will make the datasource get all the items (folders and documents) not just the folders in the first level.

2. Add parameter to the DataView, ex. Name: FolderPath, Source: QueryString, QueryStringVariable: FolderPath, DefaultValue: En/DownloadCenter/Documents (which is the path to your document library)

3. Make a filter in the DataView to have Path, Equals, [FolderPath]

4. Make a variable to be used as the page link or the document link as:

<xsl:variable name="url">
<xsl:choose>
<xsl:when test="@ContentType = 'Folder'">documents.aspx?FolderPath=<xsl:value-of select="substring(@FileRef, 2)">
</xsl:value-of>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@FileRef"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

5. The above code will check if the item is a folder so we will need the link to redirect to the same page (documents.aspx in our case), and if the item is a document so we need to redirect to the document URL.

6. substring(@FileRef, 2) is used to remove the first / character in the URL Path (not the Path), to know what is the difference between both, Path: En/DownloadCenter/Documents, URL Path: /En/DownloadCenter/Documents/Subfolder1

Tuesday, April 28, 2009

Separate XSL files for Content Query Webpart (CQWP)

Using the same ItemStyle.xsl for all the content query webparts in the site is a very bad thing to do, especially with the big sites.
But you can make an XSL file for each content query webpart and here is how to do:

  1. Edit the page you want to add the webpart in.
  2. Add a content query webpart.
  3. Export the webpart.
  4. Open the exported file.
  5. Search for “ItemXslLink”
  6. Update the line to:

    <property name="ItemXslLink" type="string">/Styles/XSL/MyCQWebpart.xsl</property>

  7. Update the property "ItemStyle" to the templete name ("UsefulLinks" in this example)
  8. Upload the XSL file (remember to update "CommonViewFields" as needed)
  9. The XSL file can be something like this to display a useful links (Title, Link):

    <xsl:stylesheet version="1.0" exclude-result-prefixes="x d xsl msxsl cmswrt" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:cmswrt="http://schemas.microsoft.com/WebParts/v3/Publishing/runtime" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
    <xsl:template name="UsefulLinks" match="Row[@Style='UsefulLinks']" mode="itemstyle">
    <xsl:param name="CurPos" />
    <xsl:variable name="TitleLenght" select="string-length(@Title)" />
    <xsl:variable name="RowLimit" select="40" />
    <xsl:variable name="LinkURL" select="substring-before(@Link,',')" />
    <xsl:variable name="LinkText" select="substring-after(@Link,',')" />
    <li>
    <a href="{$LinkURL}" target="_blank" title="{$LinkText}" class="newsTitle">
    <xsl:value-of select="$CurPos" /> - <xsl:value-of select="@Title" />
    </a>
    </li>
    </xsl:template>
    </xsl:stylesheet>

  10. Import the webpart and configure it to read from the right place, filtration and sorting order and so on.
  11. Go to the “ContentQueryMain.xsl” file and search for “OuterTemplate.CallItemTemplate”
  12. In <xsl:apply-templates select="." mode="itemstyle"> add <xsl:with-param name="CurPos" select="$CurPosition" /> and any other parameters you want to send to the itemstyle.
  13. You can also make your own ContentQueryMain XSL by updating the “MainXslLink” property in the webpart file, and the same for the header by updating the “HeaderXslLink” property.

Monday, April 27, 2009

Delete WorkItem from TFS database

To delete workitem added by mistake, you have to delete every thing related to it, so you can go to the TFS database and run the following

Declare @DeleteThisID int set @DeleteThisID = 10000

DELETE FROM [WorkItemLongTexts] WHERE ID = @DeleteThisID
DELETE FROM [WorkItemsAre] WHERE ID = @DeleteThisID
DELETE FROM [WorkItemsWere] WHERE ID = @DeleteThisID
DELETE FROM [WorkItemsLatest] WHERE ID = @DeleteThisID

Monday, April 20, 2009

Error 'Code-blocks are not allowed in this file'

http://www.hammendorp.net/post/Error-Code-blocks-are-not-allowed-in-this-file.aspx

Features included in Office SharePoint Server 2007

"Features are modular groups that provide a collection of functionality. Features are available depending on the license type of the Office SharePoint Server 2007 installation, and are activated at various levels of the logical structure of Office SharePoint Server 2007: farm level, Web application, site collection, and site level."

http://technet.microsoft.com/en-us/library/cc678862.aspx

This article contains information about Microsoft Office SharePoint Server 2007 features and the level at which you can activate them.

Sunday, April 12, 2009

SPListItem: Update(), SystemUpdate() and UpdateOverwriteVersion()

If you are working with MOSS APIs to create list items and updating them, you have the option to update the item by using Update(), SystemUpdate(), SystemUpdate(false) or UpdateOverwriteVersion() methods, but what is the difference between them?

Update()

  • will make a new version of the item
  • Update the modified time and modified by fields
  • If the item is published it will be pending again
UpdateOverwriteVersion()
  • No new version.
  • Updates the item without creating a new version of the item
  • Update the modified time and modified by fields
SystemUpdate()
  • Nothing will be changed in the item except the fields you want to change
  • No new version (You can pass false to the method just to enable generating a new version)
  • The events will be fired and the modifications will be logged, but no alerts will be sent, and you can disble the event firing before using the SystemUpdate then enable it again

SystemUpdate() is very useful if you want to modify something like the rating value after the item is published without reapproving it every time.