4.15.2009

The EventHandler Can't Update Item Data

This story has two part, one is SPItem, another is update failure.
When we update the SPItem property (Field Value) in EventHandler, we know we have to update the data in the event ItemUpdated and not in ItemUpdating. I believe it is easy to find the reference in the www.

We also know we can't utilize the parameter value directly in the ItemUpdated function, we have to initial different instance from new SPSite, SPWeb by the information from patameter, and then we can utilize SPSecurity.RunWithElevatedPrivileges. But in this case, we also have to update property in the difference instance. Why? basically that just my experiences, sometimes the parameter instance will be null when the event handler triggered. Why said sometime? That's also I wonder to understand, in the many many test, I can't figure out why sometime the parameter instance is null. If anyone know the RC, please kindly enlighten me.

But even those, sometimes the instance created by us also be null. Why? I guess that is the latency of the event handler. The following is what I do for it:
SPListItem temp = null;
while (temp == null) {
Thread.Sleep(500);
temp = properties.OpenWeb().Lists[properties.ListId].Folders.GetItemById(properties.ListItemId);
}
Yes, I just sleep the thread..

This really resolve my case for half year, but before couple days, this trick don't work.
After check with MSDN, Here is the Final version.


RETRY2:
int retrycount = 0;
try {
SPListItem temp = null;
while (temp == null) {
Thread.Sleep(500);
temp = properties.OpenWeb().Lists[properties.ListId].Folders.GetItemById(properties.ListItemId);
}
temp[_TSSDocumentFieldName] = url;
temp.Update();

//UPDATE.....
} catch (Exception ex) {
retrycount += 1;
if (retrycount <= 5) {
System.Threading.Thread.Sleep(2500);
goto RETRY2;
} else {
debug.Append("[EXCEPTION][UPDATE PATH 2]" + ex.ToString());
throw ex;
}
} finally {
this.EnableEventFiring();
}
}
}

mm.....actually I am shocked when I saw the sample code in MSDN document.

3.21.2009

How we can add comment into folder in the document library of SharePoint

The document library in SharePoint 2007 is good for sharing information, but sometimes people want to add some comments into the folder. How to do it?

It’s very easy to do it by configuration. First, we have to define a new Content Type which inherit from folder type. And then we can change the document library to be able to contain multiple content type, and add the new content type we just created into the document library.

So, here is the steps:

Click Site Action –> Modify All Site Settings into the Site Setting Page.

Click Site content types which under Galleries column.

Click Create in the Site Content Type Gallery.

Key in Name and Description, Select Folder Content Types as parent content type group and select Folder as parent content type.
Note: The content in the description will be shown as image below, after all steps are completed.


After the content type is created, we can go back to the document library, and click Settings –> Document Library Settings. And select Advanced Settings under General Settings column.


Change Allow management of content types? to be Yes, and change Display “New Folder” command on the new menu? to be No.

Go back to the document library settings page and click Add from existing site content type.

Add the content type that we just created.

Now we have two content types in this document library, and then we have to create the comment column for the folder content type. Click Add from existing site column in the Columns section. Add the column called Comments, uncheck “Add to all content type”.
After the new column is added, we also have to add the column into the content type. Click the content type we just created, in this case, it’s “New Folder Type”. Click Add from existing site or list columns, select columns from List Columns and add the column we just added.
Now, it’s done, we can try a new “Folder Content Type” and edit the property “Comments”.


Change the content type to “New Folder Type”

Then you can comment your folder

1.13.2009

About PropertiesBag

最近都在忙有關MOSS的開發, 遇到一個狀況. 就是說當我開發一些SharePoint上面的應用程式時 當然會遇到要儲存資料的狀況. 一般來說 我們會把資料盡量放在SharePoint的List中. 但是如果是一些Configuration呢?

因為大部分是簡單的資料, 所以後來的做法是放到Web Site的PropertiesBag, 單純的Key Value Pair, 相對很方便.

不過後來就是因為這個所以有痛到, 因為系統有跑Content Deployment, 所以會把資料從開發環境送到正式環境. 是的, 正如你想像, PropertiesBag會蓋過去. 這下子就死定了.

所以這告訴我們, 當有Content Deployment時, 很多東西的處理上要改變一下.

 

Recently I am busy with some application development on SharePoint. Here is a usual case for the development, there always have some data have to stored, most of them are simple value, as configuration.

In the first, we stored it in SharePoint List or PropertiesBag.Seems good, right? Everything is good until deploy to another server farm. The propertiesBag will copy in content deployment! oh….My database connection, web site id…etc….

This is the lesson, we must change the view when we are utilize SharePoint content deployment

12.27.2008

Microsoft .NET Framework 2.0SP1 (x64) (CBS): Error: Installation failed for component Microsoft .NET Framework 2.0SP1 (x64) (CBS). MSI returned error code -2146889721

Today, I got this error when update to the .NET Framework 3.5 SP1 in my Vista 64bits machine. I could not found any reference about this error message except this discussion. After read this thread, the only way is remove a part of RAM. It’s hard to believe, but the update was completed, and I also determined one of RAMs was bad quality.

So, If your machine is running well in Vista 64bits, but got the error message when update to .NET Framework 3.5 SP1, just replace the RAM when update, and the problem will gone.