Sunday, August 12, 2012

Create List Definition for Picture Library - C#


If you want to do it in Visual Studio, you're unable to see this definition in the drop down list. However it is very easy to do it:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint; 

namespace Console
{
    class Program
    {
        string listName = "Picture Library";
        string description = "My  Picture Library "; 

        public static void Main(string[] args)
        {
            using (SPSite oSite = new SPSite("http://contoso.com"))
            {
                using (SPWeb oWeb = oSite.OpenWeb())
                {
                    if (oWeb.Lists.TryGetList(listName) != null)
                    {
                        // SPListTemplate class - Used to represent the list definition or a list template 
                        // oWeb.ListTemplates - Used to get the "Picture Library" list template
      
                        SPListTemplate oTemplate = oWeb.ListTemplates["PictureLibrary"];

                        //Creates a new list with Title, Descrription and List Template "Picture Library" type

                        oWeb.Lists.Add(listName, description, oTemplate);
                    }
                    else
                    {
                        System.Console.WriteLine(listName + " already exists in the " + oWeb.Title + " site");
                        System.Console.ReadLine();
                    }
                }
            }
        }
    }
}

Wednesday, August 8, 2012

Add Title to Social Comments - jQuery

To insert some title or another text to social comments on a page:
You can resolve it by jQuery code:


  $(document).ready(function () {

            var socomHolders = $('div [id*="_socomHolder_"]');
            if (socomHolders.length) {

                socomHolders.each(function () {

                    var phName = $(this).attr('id');
                    var index = phName.substring(phName.lastIndexOf('socomHolder') + 
                        12, phName.length);

                    var socomContent = $('div [id*="_socomContents_' + index +'"]');
                    var newRow = $("Example : "+ index +"");
                    $(".ms-socialCommentItem", socomContent).prepend(newRow);
                });
            }
        });