Geeks With Blogs
marocanu2001 technicle blog
    1. If you want a list to show up in the left side of Sharepoint site, use OnQuickLunch property, set the property to true, then update ... a few times ...

    2. When adding the fields to the list, if you want to add them to the DefaultView do not add them directly to the DefaultView object, like in list.DefaultView.ViewFields.Add .... Rather iterate through the collection of views of the list, get the one that is default and add to that object's viewFields collection.

    3. Do NOT modify properties of spList through indexer of collection, there is a bug which makes the modifications not to be saved. Rather have an object take the value and modify the object.
    Ex: USE
        spList = web.Lists[guid];
    INSTEAD of

NOTE: There is a great article about the above tips in Daniel's blog:  :

    4. You can not add a custom field (that does not have a base type) to a collection , for example Resizable Image, the only way you can add it is with
   5. The only way you can put an user other than the ones in web.AllUsers in a SPFieldUserValue is
        SPUser newUser = web.EnsureUser(@"domain\username");
        web.AllowUnsafeUpdates = true;
        SPFieldUserValue userValue = new SPFieldUserValue (web, newUser.Id, newUser.LoginId);

EnsureUser is a rather interesting method. You will see more about this on my blog or I'll put a link to a blog that explaines it ...
    6. There is no property for a column to provide context menu edit link. The column with edit link can be extended as a custom column or easier, the default Title column can have its display name changed to title you want to have on the column with link menu.
    7. SPFieldDateTime's property Date Only and default value property set to Today in UI web , can be programatically set like this:

                SPFieldDateTime field = (SPFieldDateTime)list.Fields[columnName];
                field.DisplayFormat = SPDateTimeFieldFormatType.DateOnly;
                field.DefaultValue = "[today]";

    8.When adding a workflow programatically to a list perform the next steps:

        //SPListHelper.GetList is a helper function that iterates through site lists for the wanted list.
        //name -  The name of the workflow association (cob in our case)
        const string TASKS = "Tasks";
        const string WORKFLOWHISTORY = "Workflow History";
        string COMPANYONBOARDING = "Company On Boarding";
        SPWorkflowTemplate baseTemplate = site.WorkflowTemplates[COMPANYONBOARDING];
        SPList tasks = SPListHelper.GetList(site, TASKS);
                if (tasks == null)
                    site.Lists.Add(TASKS,TASKS, SPListTemplateType.Tasks);
                    tasks = site.Lists[TASKS];
                SPList wfHistory = SPListHelper.GetList(site, WORKFLOWHISTORY);
                if (wfHistory == null)
                    site.Lists.Add(WORKFLOWHISTORY, WORKFLOWHISTORY, SPListTemplateType.WorkflowHistory);
                    wfHistory = site.Lists[WORKFLOWHISTORY];
                SPWorkflowAssociation newAssociation =
                    SPWorkflowAssociation.CreateListAssociation(baseTemplate, name, tasks,wfHistory);
                newAssociation.AutoStartCreate = true;
                list.AddWorkflowAssociation(newAssociation );

                SPListHelper.AddColumnToDefaultView(list, name);

    9. Person Or Group column appears in Sharepoint Object Model as SPFieldUser. A Person Or Group with Multiple selection and Show Field = Account, is programatically set as it follows:

                list.Fields.Add(columnName, type, true);
                SPFieldUser fieldUser = (SPFieldUser)list.Fields[columnName];
                fieldUser.AllowMultipleValues = true;                       // allow multiple selection
                fieldUser.SelectionMode = SPFieldUserSelectionMode.PeopleAndGroups;       // choose people OR groups
                fieldUser.LookupField = "Name";                           // Show field : Account

    Posted on Monday, January 28, 2008 6:35 AM | Back to top

Comments on this post: Sharepoint Object Model Tips

# re: Sharepoint Object Model Tips
Requesting Gravatar...
Sa-ti traiasca, desi dupa parerea mea ii uebernaspa sa scrii cod pe un blog.

Left by Horatiu on Jan 28, 2008 8:20 AM

# re: Sharepoint Object Model Tips
Requesting Gravatar...
Cool, I actually used 2 tips from here. Thanks! :)
Left by Adrian Hara on Jul 11, 2008 4:00 AM

# re: Sharepoint Object Model Tips
Requesting Gravatar...
Check out my blog series that covers performance considerations when using the SharePoint object model. There are good and bad ways to work with the model. Make sure you do it the right way to avoid performance issues:

Left by Andreas Grabner on Jan 30, 2009 10:01 PM

# re: Sharepoint Object Model Tips
Requesting Gravatar...
here is a post on sing sharepoint object model to create a site..
Left by Ramprasad on May 24, 2009 8:34 AM

# re: Sharepoint Object Model Tips
Requesting Gravatar...
cheers, you saved me some time (show field = Account)
Left by frevd on Jul 20, 2009 12:53 PM

Your comment:
 (will show your gravatar)

Copyright © marocanu2001 | Powered by: