Monday 25 April 2011

To remove the particular Content type from New Menu

SPList list = web.Lists[<List Name>];

IList<SPContentType> ctoFolder = list.RootFolder.UniqueContentTypeOrder;

   for (int i = ctoFolder.Count -1; i >= 0; i--)
      {
           if (ctoFolder[i].Name ==
<Content Type Name>
)
           {     
             ctoFolder.Remove(ctoFolder[i]);                   
           }
      }

 list.RootFolder.UniqueContentTypeOrder = ctoFolder;
 list.RootFolder.Update();

Convert string to Color object in SilverLight

Color c;
             Type colorType = (typeof(System.Windows.Media.Colors));
              if (colorType.GetProperty(slist.color) != null)
              {
                        object o = colorType.InvokeMember("Red", BindingFlags.GetProperty, null, null, null);
                        if (o != null)
                        {
                            c = (Color)o;
                        }
                        else
                        {
                            c = Colors.Black;
                        }
                    }
                    else
                    {
                        c = Colors.Black;
                    }
                    Brush color = new SolidColorBrush(c);  

Stsadm Import and Export commands

stsadm –o export –url htpp://URL –filename E:\backup\test.cab –includeusersecurity –versions 4 –cabsize 1024 –nofilecompression  
stsadm –o import –url htpp://URL –filename E:\backup\test.cab –includeusersecurity –updateversions 3  –nofilecompression

Clearing the People Picker Control

For clearing the People Picker Control we should first clear its Accounts and then entities then only it will clear. If you do it in the reverse way or miss any of one it wont work.

WSOwner.Accounts.Clear();
WSOwner.Entities.Clear();
[WSOwner represents peoplepicker object]

Application Pool ID

For knowing the application pool ID we should run the iisapp command using command prompt in SharePoint 2007.
The above mentioned command wont work for SharePoint 2010. We should use
%windir%\system32\inetsrv\appcmd.exe list wp  

Get the Active Content Types for a list in sharepoint

Generally we use list.ContentTypes to get the content types associated to a SPList.
But for retrieving the active content types we should go with list.RootFolder.ContentTypeOrder
[list refer SPList Object]