Skip to main content

Posts

Showing posts from December, 2009

HOW TO CREATE SPFieldLookup programmatically

This is a nice snippet I saw and will like to share Let us assume we have two list aList and bList already created. Requirement is to create a lookup column in aList which will look up values in bList. SPList aList = web.Lists["aList"]; SPList bList = web.Lists["bList"]; aList.Fields.AddLookup("Lookup", bList.ID, false); SPFieldLookup fldLookup = aList.Fields["Lookup"] as SPFieldLookup; fldLookup.LookupField = bList.Fields[SPBuiltInFieldId.Title].InternalName; fldLookup.Update();

ERROR DISPLAY SHAREPOINT

By default, the SharePoint web config only displays vague custom error which for a developer usually does not provide any meaning. To enable clear error display, do the following: Open the web config for editing, this is located inside the wwwroot. Make sure you select the right port number. The default post is 80. Find the "CallStack" attribute in the SafeMode section, change the value from false to true. Identify the "CustomErrors" in System.Web section, change the value from On to Off. Please note that this would be unnecessary in a production environment and it is only suitable in a test environment.

ERROR LOG IN SHAREPOINT

Nice little snippet to log errors using the object model and mininal code: try { } catch (Exception ex) { Microsoft.Office.Server.Diagnostics.PortalLog.LogString("Exception occurred while loading form: {0} || {1}", ex.Message, ex.StackTrace); } Merry Christmas