Friday, 29 July 2011

Site Definition -- Defintion


Site Definition
  • Site Definitions are the foundations on which all sites and user templates are built. 
  • Site Definition is collection ox XML and .aspx file.
  • Site Definitions are predefined components needs to be included when a site was created in SharePoint server.
  • Site Definition contains information of Web Part , Lists, Features and navigation bars to be included in the site.
  • Customizing Portal Sites and other SharePoint sites using Site Definition is most appropriate for third party developer and SharePoint Administrator.
  • Site Definitions requires access to a file system of the Web Server.
  • Server administrator must be also involved in deployment of Site Definitions. 
  • Custom Site Definitions are Version and Upgrade independent. 
  • Subsequent upgrades to SharePoint products  and technologies may overwrite  existing Site Definitions. Using Custom Site definition exclude site from potential upgrade issues. 
  • To avoid Unghosting  , Custom Site Definition is to be create.
  • There are two options to create it
    1. Create New Site Definition File : Either Start from Scratch and create files one by one  or Copy an existing Site Definition and modify it.
    2. Copy a Site Definition and change it in Visual Studio:   We can make copy an existing site definition and modify it in visual studio to create new site definition.
  • The configuration of this site definitions are defined in XML file which is available in

    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\XML folder.

  • In the file system these definitions are available in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\Site Templates.
  • Each of these site definitions consists a XML folder and a Home page (default.aspx).

Thursday, 7 July 2011

How to Handle PostBack event in Sharepont 2010 C# webpart

The dynamic control generation is always done by the help of 'createchildcontrols' function.  Here we must handle the postback event to avoid the creation of control at each and every time. For that in asp we use

if(!ispostback)

like that here

we use

if(!page.ispostback)

Friday, 1 July 2011

How to Read,Update LookUp fields in SharePoint List

Lookup fields in SharePoint provides a great way to pickup dynamically changing values from a dropdown list.But programmatic access of this type of fields is not straightforward. The actual list item value is stored as ID:#Value. Where ID is reference to the id of referring list and value is the value selected. SharePoint SDK provides APIs to read and update lookup fiedls. SPFieldLookupValue object can be used to read and update/insert lookup fields.
For example:
Lets create a sample master list "Skills ", add following values:
ASP.Net
C#
SQL

Following is screen shot of the master list "Skills":






Now create another custom list "My Skills", with a lookup field which refers to Title column of "Skills" list, which is created earlier.

Following code snippet, reads and updates the "TechSkills" field of "My Skills" list.


using (SPSite site = new SPSite("http://servername"))
{
using(SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["My Skills"]; //List which has lookupfield TechSkills
SPListItemCollection itemCollection;
itemCollection = list.Items;
foreach (SPListItem item in itemCollection)
{
SPFieldLookupValue lookupField = new SPFieldLookupValue(item["TechSkills"].ToString());
string lookUpValue = lookupField.LookupValue;
Console.WriteLine("List item actual value:" + item["TechSkills"].ToString());
Console.WriteLine("List item lookfield value:" + lookUpValue);
}
SPListItem listItem = itemCollection[0];
listItem["Skill Name"] = new SPFieldLookupValue(1, "ASP.Net"); //ID field of ASP.Net is 1
listItem.Update();
}
}

How to rectify the IIS error occured at the time of debug a web part

Steps
  1. start->run type 'inetmgr' to open IIS manager
  2. Click the domain name and select your application pool the click advanced settings
  3. In the property window     
  • Set Ping Enabled to False.
  • Set Ping Maximum Response Time to a value that is larger than 90 seconds.
              

How to enable debugging in visual studio 2010 for a web part

Steps:
  1. Set break point as you needed.
  2. Debug -> Attach Process 
  3. A window appears select any wpw3.exe then click ok then click confirm
  4. Start Debug

Friday, 24 June 2011

How to Display Active Directory User details inculding Expiry Date

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.DirectoryServices;
using Microsoft.VisualBasic;

namespace AD
{
    class Program
    {
          
        static public void Main(string[] args)
        {
            string username = "testuser1";
            DirectoryEntry user = new DirectoryEntry("LDAP://CN=" + username + "," + " OU= Web Users,DC=CGSTAGE,DC=com", null, null, AuthenticationTypes.Secure);
           
            // GetInt64 is used to conver system._comObject to 64bit integer
            DateTime expires = DateTime.FromFileTime(GetInt64(user, "accountExpires"));
          
            Console.WriteLine(expires.ToString());

            Console.WriteLine("Display Name "+user.Properties["displayName"].Value.ToString());
            Console.WriteLine("First Name "+user.Properties["givenName"].Value.ToString());
            Console.WriteLine("Last Name "+user.Properties["sn"].Value.ToString());
            Console.WriteLine("Mail ID "+user.Properties["mail"].Value.ToString());


            Console.ReadKey();

        }

           
        static public Int64 GetInt64(DirectoryEntry entry, string attr)
        {           
            DirectorySearcher ds = new DirectorySearcher(
                entry,
                String.Format("({0}=*)", attr),
                new string[] { attr },
                SearchScope.Base
                );

            SearchResult sr = ds.FindOne();

            if (sr != null)
            {
                if (sr.Properties.Contains(attr))
                {
                    return (Int64)sr.Properties[attr][0];
                }
            }
            return -1;
        }

    }
}

Thursday, 23 June 2011

How to read the Roles and Groups names from a web application- program

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


namespace consolechk
{
    class Program
    {
        static void Main(string[] args)
        {
            SPSite site1 = new SPSite("http://stage2008:5678/");
            SPWeb web = site1.OpenWeb();
            SPGroupCollection groupcoll = web.Groups;
            foreach (SPGroup group in groupcoll)
             {
                  System.Console.WriteLine(group.Name.ToString());
             }

              Console.WriteLine();
              Console.WriteLine();
              SPRoleCollection rolecoll = web.Roles;
           foreach (SPRole role in rolecoll)
            {
                Console.WriteLine(role.Name.ToString());
            }

            System.Console.ReadLine();
        }
    }
}