Pages

Showing posts with label Sharepoint. Show all posts
Showing posts with label Sharepoint. Show all posts

Friday, 9 March 2012

Move SharePoint List Item (SPListItem) To Sub Folder



Below is a sample code to move SPlist item  from Root Location to sub folder. as every list item have unique url they can treated as File(SPFile). With SPFile Object we know how SPFile.Move() works.

In this sample code will try to move SharePoint list item from root folder to subfolder during ItemAdded Event.


/*
* /Move  List Item to folder ( not Document library folder )
* with sahrepoint 2010(not sure if poosible in MOSS 2007 )
* Key point sahrepont create unique URL for every list item also . it will look like 
* http:///sites//Lists//1_.000    where 1 is SPitem ID
* 
*/
          
SPWeb web= properties.Web;
//Folder123 is Inside root location of List
string DestinationFolderName="Folder123";

// Source item outside folder Folder123 
SPListItem listitem = properties.ListItem;

SPFile listitemFile = web.GetFile(listitem.Url);

//Create New Destination  URL ../Lists/Folder123/1_.000
string NewDestinationUrl=listitemFile.Url.Replace(listitem.ID.ToString()+"_.000",DestinationFolderName+"/"+listitem.ID.ToString()+"_.000"); 

//Move Item Insite Folder123
listitemFile.MoveTo(NewDestinationUrl);

Monday, 20 February 2012

Sharepoint 2010 Date Column Validation with [Today] Date

with new SP 2010 Column validation . 1st thought that came to my mind is date field validation with respect to today's date. then quickly create a date column TestDate and  and add the validation formula as below .
=[ TestDate ]>=[TODAY]

Then it will give you a error.
after some hit and trial I found actual expression should be
=[ TestDate ]>=TODAY()


Yapee......