Wednesday, 1 June 2011

Adding New Discussion and replying to the Discussion Item using Object Model

New Discussion:
SPListItem oListItem =SPUtility.CreateNewDiscussion(oList.Items, TitleField.Text);
oListItem[SPBuiltInFieldId.Body] = MessageBox.Text;
 Discussion reply:
SPListItem parent = list.GetItemById(parentId);
         SPListItem reply = SPUtility.CreateNewDiscussionReply(parent);
reply[SPBuiltInFieldId.Body] = body;

Virto Bulk Upload

Ø  Site gets updated with Virto Bulk File Upload Web Part for SharePoint 2010, Ribbon Item for the lists to Attach Multiple Files and ECB Action Item for the lists to Attach Multiple Files.

Ø  From the web part properties we can choose the any choose the site and then Bulk Upload or Attach Multiple Files.

Ø  If we choose Bulk Upload we get an option to choose single document library for uploading multiple files.

Ø  If we choose Attach Multiple Files we get an option to choose List and single list Item for attaching multiple files to the selected list item.

Ø  If we have any required fields it gives an alert.

Ø  We can edit the metadata for single item or for all the items at a time



Ø  At a time we cannot upload to 2 document libraries. Every time we should change the web part properties for uploading into different list/library

Ø  If we have any Managed Meta Data field type as column as required field, this field is not showing in the Properties screen. As it is a required field we are not able to upload single item to that library.

Ø  Under Web Part properties it has an option to enter Redirect Url. I didn’t find any use of this value.

Ø  After uploading it will not show any message like uploaded successfully.

Delegate Control

The Delegate Controls comes into picture when want to brand a SharePoint Site. The delegate control acts like a container control which encapsulates default content (set of child controls inside it). The default content (set of child controls associated with delegate) can be substituted by a specific control, by creating a feature. The ability to override or substitute the delegate controls brings the power & flexibility to brand SharePoint Sites.

The out-of-box SharePoint Foundation Master Page defines many controls like Top Navigation Data Source, Left Navigation Data Source, Search Box and Additional Page Head etc as delegate controls. The list is illustrated below :-
<SharePoint:DelegateControl runat="server" ControlId="AdditionalPageHead" AllowMultipleControls="true"/>
<SharePoint:DelegateControl runat="server" ControlId="GlobalNavigation" />
<SharePoint:DelegateControl runat="server" ID="GlobalDelegate0" ControlId="GlobalSiteLink0" />
<SharePoint:DelegateControl ControlId="GlobalSiteLink2" ID="GlobalDelegate2" Scope="Farm" runat="server" />
<SharePoint:DelegateControl runat="server" ControlId="PublishingConsole" Id="PublishingConsoleDelegate" />
<SharePoint:DelegateControl ControlId="GlobalSiteLink3" Scope="Farm" runat="server" />
<SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox" Version="4" />
<SharePoint:DelegateControl runat="server" ControlId="TopNavigationDataSource" Id="topNavigationDelegate"/>
The above listed delegate controls can be substituted at runtime to achieve custom branding. Or else we can create our own delegate and we can add to our master page.
<SharePoint:DelegateControl ControlId="TimeZoneDelegate" runat="server"/>

Steps to create DelegateControl:
  1. File -> New Project -> SharePoint Empty Project.
  2. Add New Class and change its base class to System.Web.UI.WebControls.WebControl
  3. Override required methods like OnLoad,CreateChildControls or Render.
  4. Add New Module with Elements.xml and add the below tag. add the safe control entry as well.
    <Control Id="TimeZoneDelegate"  Sequence="100" ControlClass="addedclassFullName" ControlAssembly="$SharePoint.Project.AssemblyFullName$"  ></Control>
  5. Instead of adding a class we can use an UserControl and refer it in ControlSrc property of Control tag in place of ControlClass and ControlAssembly.
  6. Deploy the feature.

Friday, 27 May 2011

Hide First Tab(Home) in SharePoint 2010 Navigation

You will notice that the Home tab actually is the first node and then has a child UL which represents the rest of the navigation Items. So the approach is to hide the first <li> <a> (display: none) and then simply just use (display:block ) to show the hidden <ul> <li> <a> tags.
Here is the CSS you could use to hide just the first node (home) tab in a SharePoint 2010 application:
.s4-tn li.static > a{
display: none !important;
.s4-tn li.static > ul a{
display: block !important;

Changes in SharePoint Designer are not gettings saved

If we do any xslt modifications for XSLT List View WebParts, those changes wont get reflected in the UI but you can observe those changes in the design mode. To resolve this issue search for ddwrt:ghost="hide" and remove.

Regional Settings

User can specify the regional settings from his My settings section. If he didnt specify system will take the current web regional settings.
Object Model:
SPRegionalSettings regionalSettings;
SPUser user = SPContext.Current.Web.CurrentUser;
regionalSettings = user.RegionalSettings;
if (regionalSettings != null)
lblTimeZone.Text = regionalSettings.TimeZone.Description;
lblTimeZone.Text = regionalSettings.TimeZone.Description;

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>

 list.RootFolder.UniqueContentTypeOrder = ctoFolder;

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;
                            c = Colors.Black;
                        c = Colors.Black;
                    Brush color = new SolidColorBrush(c);  

Stsadm Import and Export commands

stsadm –o export –url htpp://URL –filename E:\backup\ –includeusersecurity –versions 4 –cabsize 1024 –nofilecompression  
stsadm –o import –url htpp://URL –filename E:\backup\ –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 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]