Tuesday, May 27, 2008

Creating SPField Read Only + Only Date format

There are many scenarios that you might need to have read only field which hold only the date. Using below code snippet I was able to create a date type filed which as read only value for end users. 


SPFieldDateTime spDateField = (SPFieldDateTime)sourceList.Fields.CreateNewField(SPFieldType.DateTime.ToString(), "To");
spDateField.DisplayFormat = SPDateTimeFieldFormatType.DateOnly;
spDateField.ShowInViewForms = true;
// spDateField.DefaultValue = "[today]"; // This assigns Default value today to datetime
spDateField.ReadOnlyField = true;
sourceList.Fields.Add(spDateField);

sourceList.Update();

Creating and Deleting Hidden Fields in SPList

Creating :
id = sourceList.Fields.Add("SourceRefId", SPFieldType.Guid, false);
SPField field = sourceList.Fields[id];
field.Hidden = true;
field.ReadOnlyField = true;
field.Update();
sourceList.Update();





Deleting
SPField field = sourceList.Fields["SourceRefId"];
field.Hidden = false;
field.ReadOnlyField = false;

field.Update();
sourceList.Fields.Delete("SourceRefId");

Saturday, May 3, 2008

Welcome

Welcome to My WSS 2007 Windows SharePoint Server 2007 Blog.