Real SharePoint Code

Archive for July, 2011

SharePoint Central Feature Management

My 4th open source contribution to Codeplex. Currently I am working on a Project which is product wrapper top of SharePoint. I need to activate almost 20 to 30 feature on every deployment, It takes around 10-15 minute to just activate those feature in Site Collection and Sub Sites. So I created on custom Application Page which will work as a Feature Management.and  thought its nice to contribute on codeplex with that project which can help everyone, following are the screen shots and description  of the Project. Download Source Code

SharePoint Central Feature Management provides the functionality to manage all feature in Site Collection and all Sub Sites from one central location. also allow to Activate or Deactivate multiple feature on Single Click. Also allow user to Activate all dependent feature associated with current feature. Allow you to activate and deactivate hidden feature also.

1. Activate SharePoint Central Feature Management from Site Collection Feature

Activate SharePoint Central Feature Management from the Site Collection Features

2. After enabling the feature it will add link in Site Collection Administration

After Activating the Feature it will Show you the Link under Site Collection Administration

3. Click on Central Feature Management

Landing Page of SharePoint Central Feature Management

4. Action and Filter control

Filter Tool Bar

Functionality:

1. Type dropdown will allow you to select type of feature (Site Collection Feature or Web Feature)

2. Select Web dropdown will allow you to select specific web from the dropdown (if type is web in first dropdown)

3. Show dropdown will allow you to select which type of feature you want to display “All”,”Activated”,”Needs to Activate”

4. Hidden Checkbox will allow you set whether you want to include Hidden feature or not.

5. On Filter button click will filter the result and display the result in below grid

6. Activate Button will activate all selected feature

7. Activate with Dependency will allow you to activate all dependent feature associated with selected feature

8. Deactivate button will allow you to deactivate selected feature

Hidden feature in Highligted Color

Hope this will help everyone – 🙂

Happy Coding !!!!!!

SharePoint Escape Characters

How sharepoint handles escape characters? Sharepoint internally replace escape character with some code like, if you are creating field with space in that name e.g. “my column” then sharepoint replace space with _x0020_ e.g “my_x0020_column”.
Following are the complete escape characters and their code in Sharepoint.

Blank space: _x0020_
Underscore: _x002d_
Dash: _x0027_

Here is the Format:

_x00[the escape code]_

Char Code

[space] 20
3E
# 23
% 25
{ 7B
} 7D
| 7C
\ 5C
^ 5E
~ 7E
[ 5B
] 5D
` 60
; 3B
/ 2F
? 3F
: 3A
@ 40
= 3D
& 26
$ 24

Create a custom list form for a SharePoint list

Open your site in SharePoint Designer.
Browse to your list and open the ‘NewForm.aspx’ web form.
Go File -> Save As… and give the form a new name such as ‘NewForm2.aspx’.
Hide the default List Form Web Part from the page (do not delete it!!).
Right click the List Form Web Part -> Web Part Properties -> expand Layout -> check Hidden.
Go Insert > SharePoint Controls -> Custom List Form.
In the List or Document Library Form dialog, select the appropriate list, content type and type of form.
Click OK and a new Data Form Web Part is added with controls representing all the fields from the list (in my environment all the controls show “Error Rendering Control” but this does not affect the final result).
In the newly added Data Form Web Part, delete the rows containing fields not to be shown to the user (ensure that fields being removed are not required fields without default values as this would prevent the user from submitting the form).
At this point, you can do other customisation such as rearranging the fields if you wish.
Save the site.
To make the new form the default form:

1. Open the site in SharePoint Designer.
2. Right click the list in the Folder List and select Properties.
3. Go to the Supporting Files tab.
4. Use the Browse button to enter the path to your new Edit item form.

Custom Sequential Approval Workflow via Visual Studio 2010

My 3rd and most important contribution to Codeplex. Recently I need to work on some custom approval workflow. I didn’t get much help on net on Workflows. So I have create Custom Sequential Approval Workflow via Visual Studio 2010 and  thought its nice to contribute on codeplex with that project which can help everyone, following are the screen shots of the workflow. Download Source Code

Upload Document in Document Library

Check Workflow column is In Process

 

Task is created in Task List

 

Click on Task will open the OOB Approval form Popup

 

Check Task list , Task is Approved and Completed

 

Check Workflow Status its Completed

 

Happy Coding !!!!!

Export SharePoint List Data to CSV

My 2nd open source contribution to Codeplex.

This project is provide the feature for exporting the SharePoint list data to CSV. This can be used for SharePoint 2007 also. But needs to create separate project for MOSS 2007. OOB Export to excel not work if some services is not enable on your machine (Microsoft SharePoint Foundation-compatible application). So this feature will allow you to export all the data which is not hidden to CSV file. One more advantage you can export the any list data from one location

You can access the source code from the Here

 

 

 

 

I hope this will help, Happy Coding !!!

Create Publishing Page via Feature

Following are steps for creating Publishing Page Via Feature

1. Create New Feature in SharePoint

2. Modify Feature.xml as below code

<?xml version="1.0" encoding="utf-8" ?>
<Feature  Id="{E51F42D4-9E43-4c43-B3DC-3F6F1CBE9D30}"
          Title="Create Custom Pages"
          Description="This feature will deploy custom pages in Pages Library"
          Version="1.0.0.0"
          Scope="Site"
	        Hidden="FALSE"
          xmlns="http://schemas.microsoft.com/sharepoint/">
  
  <ElementManifests >
    <ElementManifest Location="elements.xml" />
    <ElementFile Location ="CustomTemplate.aspx"/>
  </ElementManifests>   
</Feature>
3. Create New Elements.xml and modify code as mentioned below
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="Pages" Url="Pages">
    <File Name="MyPage.aspx" Url="MyPage.aspx"
      Path="CustomTemplate.aspx" Type="GhostableInLibrary"
      IgnoreIfAlreadyExists="TRUE">
      <Property Name="Title" Value="Custom Page Create by Feature"/>
      <Property Name="PublishingPageLayout"
        Value="~SiteCollection/_catalogs/masterpage/PageLayoutName.aspx"/>
      <Property Name="ContentType" Value="Content Type Name" />
      <Property Name="ContentTypeId" Value="Content Type ID" />
      <Property Name="Comments" Value="The resource or file that you have requested is not available. Please use the navigation at the top of this page to navigate the site." />
    </File>
  </Module>
</Elements>
4. Provide Content Type Name, Content Type ID and PageLayout Name
5. Create 1 Custom page with same Pagelayout manually in Pages Libaray
6. Goto Pages Library and Download the copy of the Page
7. Use that Page as template and place that page in feature folder, and update the template name in above strike through text 
Done !!!
Happy Coding !!!!

Ghosting of Page Layout or Publishing Page

Sometimes we have a scenario where we need to ghost or uncustomize the page, 
Following is the code for the same,

SPSecurity.RunWithElevatedPrivileges(delegate()
{
  using (SPSite site = new SPSite(sSiteURL))
  {
    PublishingSite publishingSite = new PublishingSite(site);
    PageLayoutCollection pageCollection = publishingSite.PageLayouts;
    foreach (PageLayout layout in pageCollection)
    {
      SPFile currentFile = site.RootWeb.GetFile(layout.ServerRelativeUrl);
      if (currentFile.CustomizedPageStatus == SPCustomizedPageStatus.Customized || currentFile.CustomizedPageStatus == SPCustomizedPageStatus.None)
      {
        try
        {
          currentFile.RevertContentStream();
          currentFile.Versions.DeleteAll();
          currentFile.Update();
          site.RootWeb.Update();
        }
        catch (Exception ex)
        {
        }
      }
    }
  }
 });