Jan 30, 2012

Creating List Programatically in SharePoint 2010 using Visual Studio 2010

Today we will discuss about creating List programmatically in SharePoint 2010 using Visual studio 2010.
If we are using only one instance of list we will follow this approach for creating list.
open the visual studio 2010.
File-->New-->Project
Select C#-->SharePoint-->2010
Select Empty SharePoint Project




Deploy as a Form solution.
Click on Finish



Project Solution structure is below for Empty SharePoint Project.



Select the project and click on F4 for the properties.
Check for the Sandbox Solution property it is set to false now as we select the Trust level for SharePoint solution as From Solution.
From here if you change that to Sandbox solution by setting property
Sandbox Solution=”True”
You can edit the site URL which you want to deploy using site URL property.





Right Click on Feature node and click on AddFeature.



It will add Feature1 to the Features node in the project.
Change the Title according to your requirement .Here it is Devendra Employee List feature.
I want this List available at site collection level to achieve this we need to change the
Scope From Web to Site.



Now I am using Scope as web level only.



We will create a list using object model because we are going to use only one instance of this list so there is no point of creating list definition.
To do that I will add a feature receiver.
Add Event Receiver to the Feature1 node in the project.



Go ahead and add . Then uncomment the FeatureActivated event .
We will write a code here which will add the Employee List whenever we activated this feature.

using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;

namespace Devendra_Feature_Event_Receivers.Features.AddList
{
 /// 
 /// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
 /// 
 /// 
 /// The GUID attached to this class may be used during packaging and should not be modified.
 /// 

 [Guid("5bf5f6c5-c371-419a-984b-f0ecf9ddeda0")]
 public class Feature1EventReceiver : SPFeatureReceiver
 {
     // Uncomment the method below to handle the event raised after a feature has been activated.
     public override void FeatureActivated(SPFeatureReceiverProperties properties)
     {
         try
         {
             //get the current web object.
             SPWeb web = properties.Feature.Parent as SPWeb;

          
             SPList list = web.EnsureList("Employee", "This list contains Employee details.", SPListTemplateType.GenericList);

         
             if (list != null)
             {
              
                 SPField field = list.EnsureField("Title", "", SPFieldType.Text, true);
                 field.Title = "FirstName";
                 field.Update();

              
                 SPField fld = null;
             
                 fld = list.EnsureField("LastName", "Employee LastName", SPFieldType.Text, true);

              
                 if (fld != null)
                 {
                     SPView view = list.Views[0];
                     view.ViewFields.Add(fld);
                     view.Update();
                     fld = null;
                 }
              
                 SPListItemCollection listItems = list.Items;
                 AddItems(listItems, "Devendra", "Velegandla");
             }
             else
             {

             }
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
     public static void AddItems(SPListItemCollection listItems, string FirstName, string LastName)
     {
         SPListItem item = null;
         item = listItems.Add();
         item["FirstName"] = FirstName;
         item["LastName"] = LastName;
         item.Update();
     }

     public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
     {
     
         SPWeb web = properties.Feature.Parent as SPWeb;
   
         web.DeleteList("Employee");
     }



 }

}


add one more class called utilities.cs of type static.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace Devendra_Feature_Event_Receivers.Features.AddList
{
 public static class Utilities
 {

     public static SPList EnsureList(this SPWeb web, string listTitle, string desc, SPListTemplateType lstTemplateType)
     {
     
         SPListCollection lstCollection = web.Lists;

    
         SPList lstObj = (from SPList lst in lstCollection
                          where string.Equals(lst.Title, listTitle, StringComparison.InvariantCultureIgnoreCase) == true
                          select lst).FirstOrDefault();

     
         if (lstObj != null)
         {
             return lstObj;
         }
     
         Guid lstGuid = web.Lists.Add(listTitle, desc, lstTemplateType);
         try
         {
             SPList newList = web.Lists.GetList(lstGuid, true);
             newList.OnQuickLaunch = true;
             newList.Update();
             return newList;
         }
         catch
         {
             return null;
         }
     }
 
     public static SPField EnsureField(this SPList list, string fldDisplayName, string fldDesc, SPFieldType fldType, bool isMadatory)
     {
     
         SPFieldCollection fieldCollection = list.Fields;

     
         SPField spField = (from SPField field in fieldCollection
                            where string.Equals(field.Title, fldDisplayName, StringComparison.InvariantCultureIgnoreCase) == true
                            select field).FirstOrDefault();

     
         if (spField != null)
         {
             return spField;
         }
      
         try
         {
             list.Fields.Add(fldDisplayName, fldType, isMadatory);
             SPField spfield = list.Fields.GetField(fldDisplayName);
             spfield.Description = fldDesc;
             spfield.Update();
             return spfield;
         }
         catch
         {
             return null;
         }
     }
 
     public static bool DeleteList(this SPWeb web, string listTitle)
     {
      
         SPListCollection lstCollection = web.Lists;

      
         SPList lstObj = (from SPList lst in lstCollection
                          where
                              string.Equals(lst.Title, listTitle, StringComparison.InvariantCultureIgnoreCase) == true
                          select lst).FirstOrDefault();

      
         if (lstObj != null)
         {
             try
             {
                 lstObj.Delete();
                 return true;
             }
             catch (Exception ex)
             {
             }
         }
         return false;
     }
 }
}




Add Item to the list data to the Employee List.
Once we deactivate this feature the list will get deleted.
Add one more class call utilities.



Once you click on the package .go to Bin folder of the project get the WSP file.



Add the solution using stsadm command.
Click on run: type CMD
Execute below command
Stsadm –o addsolution –filename c:\Devendra_Feature_Event_Receiver.wsp.

Open Central Admin to deploy the solution.
Got o system settings -> Manage Form solutions



Deploy the solution.
You can see the below screen solution deployed globally.



Open the site URL which we deployed the solution.
Click on SiteActions-->Site settings
Under Site Actions click on Manage Site Features.




Activate the feature Devendra Employee List Feature.



After activation we can see the Employee list and data inserted into the list.



Once you deactivate the feature list will get deleted.

SharePoint-Journey for Administrators, Developers and users

Jan 27, 2012

Contentype in Sharepoint 2010 using visual studio 2010 - Second Part


How to use the Content Type:


To use the content type developed in First part we will create a document library with the name of devendra.
Go to Site Actions-->View All site Content--> Create-->Select Library-->Select Document Library.




Enter a Name. Click on Create, a document library will get created. Select the Library which you create click on Library settings.



Click on Advanced settings.




Check Allow management of content type to Yes



In the below screen you can see the option Add from existing content types.



Select the content type which we created and Click on add.





To make the content type added to be default click on Change new button order and the default content type.



Only check the content type you developed or change the position to 1.here I am just checking the DevendraContentType.



Go to the document library; click on Add Document .see the Grade column with choice values.



The document has been added to library. To get Grade column to be displayed in the default view.



Go to library settings and click on All Documents under Views.



Check the Grade column.




Now you can see the Grade under default view.



you are done with associating content type developed using visual studio 2010 to document library.

SharePoint-Journey for Administrators, Developers and users

Contentype in Sharepoint 2010 using visual studio 2010 - First Part

Hello guys ...
Today we will work with content types in SharePoint 2010 using visual studio 2010.

First Part we will develop a content type using visual studio 2010.
In Second part how will use the developed content type .

shall we start now.........

here we go..

I will inherit from parent document content type and associate with the document library.

Create a project with the template type Content Type.

Give Project Name here it is with my name DevendraContenType 



Deploy as Form solution.



Click on Next.
Select the content type which you need to Inherit from.
Here I am selecting as Document content type.



Click Finish.It will show the below project structure.



I want to add the field called Grade to the content type.
This is of choice type. and choice values are GradeA,GradeB,Grade C and Grade D.

I need to generate a schema for the field like below.


  Grade A+
  
    Grade A+
    Grade A
    Grade B+
    Grade B
    Grade C
  


one of easy way to achieve this is.....

To create field schema I am using list called Devendra. Go to list setting page.Click on create column.




Create column called Grade. This is of choice type. Enter few values.
GradeA
GradeB
Grade C
Grade D


Open SharePoint Manager 2010. And open the site then under List section got to fields section .Check for the Grade field



Click on Schema Xml. And copy the content




Open elements.xml file from the solution which is under ContentType1.Add the Fieldref tag also. Change the Name and Group properties under Countertype tag section to required values.



Click on the feature1 to change the Title and description.
Right click on the project and deploy the solution.







You can observe what are steps happening in the output window.




After deployment we need to check the content type deployed properly or not.
Click on Site Actions-> site settings
Under Site Collection Administration: Click on Site collection Features



See the below site collection feature is already activated



Click on Site Actions-> site settings

Under Galleries: Click on Site Content Types



we are done with it.You can see the Group name and the content type.




Congratulations... you have developed a content type in sharePoint 2010 using Visual studio 2010.
we will see in second part how to use the content type which you developed just now.

SharePoint-Journey for Administrators, Developers and users

Jan 21, 2012

Sharepoint diagrams

Six pillers of sharepoint2010

Image Hosted by ImageShack.us


Image Hosted by ImageShack.us


Image Hosted by ImageShack.us


Image Hosted by ImageShack.us

sharepoint 2010 and 2007 workflow Videos

sharepoint Interview Questions

1.What is webpart.

As the name implies, it means parts of a web.

Web Parts are the building blocks for building web pages in SharePoint.

Web Parts are essentially ASP.NET web controls that inherit the web control base class in ASP.NET but have special abilities compared with ordinary ASP.NET web controls.



Sandbox Solution vs. Form Solution:

1.
a. Sandboxed solutions are hosted in the SharePoint user code solution worker process (SPUCWorkerProcess.exe)
b. Farm solutions are hosted in the IIS worker process (W3WP.exe)
2.
a. Sandboxed solutions are specific site collection
b. Farm solutions are run at Form level

3. Mapped folders cannot be added to the project in Sand box solutions.

4. Sandbox solutions does not support
• Visual Web Parts
• Application Pages
• Custom Action Group
• HideCustomeActionelement
Web Application-scoped Features.
• Farm-scoped features
• Workflow with code

Jan 18, 2012

out of box workflows in sharepoint

Three-state workflow
This workflow having states like Active, Ready for Review,and Complete. This workflow can be customized and used in other lists or in custom SharePoint lists, and the names of the three states are configurable.

Approval workflow
This work flow can happen serial or parallel order.
Example: submitter submits the document, and the participants gets email alert.they may reject or approve the document and enter the reason.

Collect Feedback workflow
The Collect Feedback workflow gives submitter the ability to acquire feedback for their peers on the status of the submitted document. This workflow sends the document to the specified team members and contribute their feedback on the document. After it has circulated through the team, the feedback is compiled and the submitter is notified.

Collect Signatures workflow
An alternative to the Approval workflow where the approval process makes no
changes to the document, the Collect Signatures workflow will require each approver to place a digital signature on the document. After those signatures have been acquired through the workflow, you can take the document off line and the approval will still be recognizable. Note that this workflow can only be initiated from the Office Tools for building custom SharePoint workflows 15 client, such as Microsoft Office Word. It cannot be initiated from the browser like other workflows can.

Disposition Approval workflow
This workflow allows you to manage document expiration and retention. This enables you to decide what will happen to documents when they expire. A possible option,instead of deleting a document, is to archive it and send email notifications.

SharePoint-Journey for Administrators, Developers and users

workflows in Sharepoint 2010


Sharepoint workflows built on three different layers of windows workflow foundation services


what are the new things in workflows in Shareoint 2010.? we will discuss more on that..

there are two new workflows are introduced in Sharepoint 2010.

1.Reusable workflow
we can create reusable workflows and deploy them to the site or site collection level to be consumed by various objects within that scope.

Advantage:There is no need to maintain more than one copy of the same workflow.

2.Site Workflow
Site workflows more advanced of reusable workflows.
we can run site workflow on a list, library, or list item within a site.

Example:Entire site’s list items regardless of the list in which they reside, are can be manipulated like changing status,updating list Author etc...

SharePoint-Journey for Administrators, Developers and users