Thursday, May 23, 2013

Adding Fields tp Contenttypes programatically



The SPContentType object also has a Fields property that returns an SPFieldCollection object. You cannot add columns directly to this collection. When you add an SPFieldLink object to the FieldLinks collection, a corresponding SPField object is added automatically to the Fieldscollection. Each SPField object in this collection represents a "merged view" of the base column definition and any overwritten properties that are specified in the column reference.


http://msdn.microsoft.com/en-us/library/aa543526.aspx



Wednesday, April 10, 2013

Add/Move ListItems to a folder in SharePoint List, adding folders if needed


///  Adding Items under folder in List

SPList oList = web.Lists["ListName"];
     
SPListItemCollection items = oList.Items;

SPListItem item = items.Add("/sites/[webname]/Lists/[ListName]/[FolderName]",                                
                                             SPFileSystemObjectType.File);

                item["Title"] = "Something";
               item.Update();



/////    Moving Listitems to different folder in same list

SPListItemCollection items = oList.Items;

foreach (SPListItem item in items)
                    {                      
                        SPFile file = web.GetFile(item.Url.ToString());
                   
  file.MoveTo(string.Format("Lists/[ListName]/{0}/{1}_.000", "FolderName", item["ID"].ToString()));

                        item.Update();
                                           
                    }



///    Creating Folders if needed


oFolder = oList.Items.Add(oList.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder, FolderName);
                      newFolder.Update();
                      oList.Update();


Monday, April 8, 2013

Tuesday, July 31, 2012

SecurityElement class

SecurityElement.Escape(string)


SPDiagnosticsService.Local.WriteTrace   write to logs

Wednesday, July 18, 2012

Useful Find

http://stackoverflow.com/questions/621777/select-the-next-n-elements-of-an-ienumerablet

Skip() and Take() in Linq can be used to select a certain sequence irrespective of its order.

Skip() and Take() can be used in combination to select a sequence starting anywhere.

Difference between Where() and TakeWhile() is TakeWhile() stops when first negative result is encountered, former does not..