July 2009 - Posts

Trước hết đó là giao diện cài đặt mới. Với sự hỗ trợ của Microsoft SharePoint Products and Technologies 14 Preparation Tool, hầu như chúng ta không phải mất công để chuẩn bị môi trường cài SharePoint 14. Chỉ cần OS (có thể SQL Server nếu cài Farm). Tool sẽ tự động cài đặt và cấu hình các yêu cầu cần thiết.

image image

Sau khi quá trình cài đặt hoàn tất. Đó là sự xuất hiện của Central Admin hoàn toàn mới để cấu hình.

Một giao diện mới, hỗ trợ thêm các Tabs: Browse, Edit….Kiểu giao diện tương đối đồng nhất với Office 2007

image image image

Rất nhiều services đi kèm: Visio, Lotus Note, Business Data Catalog….

image 

Application Management

image image image

Tạo Site Collections

image 

Đây là bản SharePoint Server 2010 (SharePoint 14) Technical Review , chưa phải chính thức.

In MOSS 2007 and WSS 3, we have “People and Group” field to specify User or Group. Some time we need to set default value for this. But It’s not default function of “People and Group”. You must create one custom field using Visual Studio 2008 Extensions for WSS 3 and Custom Field template. The code is very easy to write and understand:

public class CurrentUserFieldField : SPFieldUser
    {
        public CurrentUserFieldField(SPFieldCollection fields, string fieldName)
            : base(fields, fieldName)
        {
        }
        
        public CurrentUserFieldField(SPFieldCollection fields, string typeName, string displayName)
            : base(fields, typeName, displayName)
        {
        }
        public override string DefaultValue
        {
            get
            {
                SPWeb web = SPContext.Current.Web;
                SPUser currentUser = web.CurrentUser;
                return string.Format("{0};#{1}", currentUser.ID.ToString(), currentUser.Name);
            }
            set
            {
                base.DefaultValue = value;
            }
        }        
    }

Sometime, we need to set item permission dynamically for SharePoint List item or SharePoint Document. To do that, we create Item event handler then implement extension method for setting permission to the item.

the code as following:

public static SPListItem SetItemLevelPermission(this SPListItem listItem, SPPrincipal userOrGroup, SPRoleType roleType)
        {
            SPListItem item = listItem;
            Guid listId = listItem.ParentList.ID;
            Guid itemId = listItem.UniqueId;
            SPUserToken token = item.Web.Site.SystemAccount.UserToken;
            SPSecurity.RunWithElevatedPrivileges(
                delegate()
                {
                    using (SPSite site = new SPSite(item.Web.Site.ID, token))
                    {
                        site.AllowUnsafeUpdates = true;
                        using (SPWeb web = site.OpenWeb(item.Web.ID))
                        {
                            web.AllowUnsafeUpdates = true;
                            SPWebApplication webApp = web.Site.WebApplication;
                            webApp.FormDigestSettings.Enabled = false;
                            item = web.Lists[listId].Items[itemId];
                            item.BreakRoleInheritance(false);
                            web.AllowUnsafeUpdates = true;

                            SPRoleDefinition roleDefinition = web.RoleDefinitions.GetByType(roleType);
                            SPRoleAssignment roleAssignment;

                            roleAssignment = new SPRoleAssignment(userOrGroup);
                            roleAssignment.RoleDefinitionBindings.Add(roleDefinition);
                            item.RoleAssignments.Add(roleAssignment);

                            item.Update(); // call this function before finished
                            webApp.FormDigestSettings.Enabled = true;
                            web.AllowUnsafeUpdates = false;
                        }
                    }
                }
                );
            return item;
        }

 

In the ItemAdding or ItemAdded Event, We use:

public override void ItemAdded(SPItemEventProperties properties)
       {
           SPWeb currentWeb = properties.ListItem.Web;
           SPUser currentUser = currentWeb.CurrentUser;
           properties.ListItem.SetItemLevelPermission(currentUser, SPRoleType.Contributor);
       }

I’ve waiting for “LINQ to SharePoint” feature from Microsoft a long time. Now, with SharePoint SP2 and VS 2008, We’ll easy to use LINQ feature to query SharePoint data.

Before, I tried to use “LINQ for SharePoint” from CodePlex, but I didn’t happy. I think the support from Microsoft for LINQ to SharePoint is the best.

Thanks for the improvement. I’m waiting for some improve features in next version of SharePoint, maybe SharePoint 2010.

Here are my code using LINQ with SharePoint data

SPSite site = new SPSite("http://basquang:8001");
SPWeb web = site.RootWeb;
var listItems = from SPListItem item in web.Lists["Tasks"].Items
                where DateTime.Parse(item["Due Date"].ToString()) <= DateTime.Today
                select item;
foreach (var item in listItems)
{
    Console.WriteLine(item.Title);
}

with 1 comment(s)
Filed under: