Recent Blogs

AvatarByRashid Aziz

Create document library programmatically in SharePoint

I have come across a scenario where I needed to create a document library programmatically inside SharePoint 2010 site collection, The “Document Library” is actually a list in SharePoint 2010 but just the template type is different.

Here is a method which I used to create a custom document library programatically.

protected void CreateNewDocumentLibrary()

{

SPSite site = SPContext.Current.Site;

SPWeb web = site.OpenWeb();

SPListTemplateType tempType = SPListTemplateType.DocumentLibrary;

web.Lists.Add("EbloginDocLibrary", null, tempType);

}

Once you run this code, go to “All site content” of your site collection you will see a new document library as you can see in below pic.

     

AvatarByRashid Aziz

Backup/restore SharePoint site collection using PowerShell

You can quickly perform site collection backup and restore using PowerShell commands. It is powerful and quick.

Back up a site collection using PowerShell

1.      Make sure that the user has rights to perform backup.

2.      On the “Start” click “All Programs.”

3.      Now click on “Microsoft SharePoint 2010 products”.

4.      Click on “SharePoint 2010 Management Shell”

5.      The PowerShell command prompt will be appear , now type the following

Backup-SPSite -Identity <Name on site collection> -Path <backup file path> [-Force] [-NoSiteLock] [-UseSqlSnapshot] [-Verbose]

If you want to overwrite the previous backup, please use force.

 

Restore a site collection using PowerShell

1.      Make sure that the user has rights to perform backup.

2.      On the “Start” click “All Programs.”

3.      Now click on “Microsoft SharePoint 2010 products”.

4.      Click on “SharePoint 2010 Management Shell”

5.      The PowerShell command prompt will be appear , now type the following

Restore-SPSite -Identity <The site collection URL> -Path <Backup file> [-DatabaseServer <Name of Database server>] [-DatabaseName <The content database name>] [-HostHeader <The Host header>] [-Force] [-GradualDelete] [-Verbose]

If you want to overwrite the existing site collection, please use force.

AvatarByRashid Aziz

Creating SharePoint 2010 permission level programmatically

If you have many sites under a web application, there will be a situation when you need to use the custom permission for a particular site. Some time you inherit the roles and sometime not. You can create custom permission level programmatically.

You can only create new role (permission level) at site collection level, and then you can use this role in sub sites.

Here is the code to create new permission level.

Add assembly reference:

using Microsoft.SharePoint;
 

//Code:

     SPSite site = new SPSite(SPContext.Current.Site.Url);
     SPWeb web = site.OpenWeb();
    if(web.HasUniqueRoleDefinitions || web.IsRootWeb)
    {
        try
        {
            web.AllowUnsafeUpdates = true;
            SPRoleDefinition roleDef = new SPRoleDefinition();
            roleDef.BasePermissions = SPBasePermissions.ManageLists | 
            SPBasePermissions.CancelCheckout |       
                 SPBasePermissions.AddListItems |
            SPBasePermissions.EditListItems |
            SPBasePermissions.DeleteListItems;
            roleDef.Name = "EblogIn Role";
           web.RoleDefinitions.Add(roleDef);
           web.Update();
  }
  catch (Exception ex) { }
  }
AvatarByRashid Aziz

SharePoint 2010 web application regional settings

You can change Time Zone of your webapplication by using “Central Admin” site.

  1. Go to “Central Admin”
  2. Click “Application management” from the quick launch.
  3. Click “manage web applications” under “Web application” heading
  4. Select web application on which you want to change the regional settings.
  5. From the ribbon click “General setting” and select “General Settings” from the dropdown.
  6. Setting modal dialog will appear, you can change the “default time zone” and other settings if you want to change, and click OK. 

 Do IIS reset to make sure that the changes are updated. You can also change regional settings on site level.

AvatarByRashid Aziz

Enable self-service site creation in SharePoint 2010 Server

It is an OOTB feature of SharePoint 2010 server which allow user (who have the use self-service site creation permission) to create sites in defined Url namespaces.

I am going to explain how you can enable this service by using central admin and stsadm commands.

Enable “self-service site creation” by using Central Administration

1.   Verify that the user is a member of farm administrator who is performing this action.

2.   Open the central administration site, click on “Application Management”.

3.   The application management page will appear, now click ”Manage web applications”.

4.   Click a web application on which you want to enable self-service site creation feature.

5.   The ribbon will be active, from the ribbon click “Self-Service Site Creation”.

6.   The “Self service management page” will appear, select “on” option.If need to supply a secondary contact name on the sign-up page , select Require secondary contact. (picture is given below) 

                 

 7.   Click ok to complete.

Enable “self-service site creation” by using the stsadm.exe command-line tool

1.   Verify that the user is a member of farm administrator who is performing this action and also in the administrators group of local computer. 

2.   Open the command prompt  by right click on it and  “Run an administrator”.

3.   Go to the following location to run stsadm commands.

cd %CommonProgramFiles%\Microsoft Shared\Web server extensions\14\bin

         To enable self-service site creation, tye this command:

        stsadm.exe -o enablessc -url<url> -requiresecondarycontact
        Where <url> is the URL of the Web application.
        This command will enable self-service site creation and requires a secondary

        contact.

AvatarByRashid Aziz

SharePoint on iPhone (iShare)

iShare is an iPhone application. By using which user can serach and browse all the required important documents from the phone. It’s the world’s first iphone application.

It connects with Microsoft SharePoint Server 2007.That connection provides you a secure and authenticated access to team, group & company that allows information like documents, lists, tasks, announcements and meeting collaboration.Services:

                                           

 Services

It provides different useful services such as:

1).Browsing: iShare Browse through the sites and provide access to the lists and the document liberaries.

2).Search: This feature of iShare allows you to search across all of the SharePoint.

3).Access Documents: iShare allow us to open and read documents of different formats i.e. word, acrobat, excel, powerpoint, PNG, GIF, JPEG etc.

4).Modification of List Items: It can create, delete and update the list items that can be tasks, calendar items New. And you can view Metadata in the documents.

5).Support: document libraries, custom lists,out-of-the box and large documents paging.

6).Quick Access: It provide multiple account access to different SharePoint sites.

 

Platforms & Technical Requirements:

1).Microsoft Office 2007

2).Windows SharePoint Services and SharePoint Online

 

For getting started you need to have:

·         URL address of a SharePoint site

·         Your domain

·         Username & password 

For SharePoint server requirements: 

  • SharePoint Server 2007 (WSS or MOSS or Sharepoint Online)
  • iPhone must be able to make a network connection to SharePoint server
  • http or https (https recommended for better security if not using VPN)
  • Windows Authentication or SharePoint Forms Authentication

Your iPhone needs to be:

  • Network connection (Wifi or Cellular) to your SharePoint server.
  • iPhone’s built-in VPN client to connect to your company network.
AvatarByRashid Aziz

Configure recycle bin in SharePoint 2010 foundation and server

 The recycle bin in SharePoint is used to help site users to protect and recovery of data.

Configure recycle bin in SharePoint 2010 Server

You need to verify first that the account you are using to configure the recycle is a member of Farm administrator.

Go to the central admin site and click on “Application management” tab

From the “Application Management” page, click “Manage web application” link.

Select a web application on which you want to configure the recycle bin. (The ribbon will be active).

Click the “General Settings” dropdown menu from the ribbon and click “General Settings”.

You are on the web application setting page; in the recycle bin section you can do the configuration as following.

You can set the recycle bin for the web application “ON” or “OFF” mode, By default it will be “ON”

Also you can set the timing, after how long an item will be removed from recycle bin automatically.

You can also configure a percentage of live site quota for second-stage deleted items.

After you done the setting’s , click “OK”

Configure recycle bin in SharePoint 2010 Foundation

You need to verify first that the account you are using to configure the recycle is a member of Farm administrator.

Go to the central admin site and click on “Application management” tab

From the “Application Management” page, click “Manage web application” link.

Select a web application on which you want to configure the recycle bin. (The ribbon will be active).

Click the “General Settings” dropdown menu from the ribbon and click “General Settings”.

You are on the web application setting page; in the recycle bin section you can do the configuration as following.

You can set the recycle bin for the web application “ON” or “OFF” mode, By default it will be “ON”

Also you can set the timing, after how long an item will be removed from recycle bin automatically.

You can also configure a percentage of live site quota for second-stage deleted items.

After you done the setting’s , click “OK”

AvatarByRashid Aziz

Change site actions menu text in SharePoint

The “Site actions” text is set by the “text” property of SharePoint:SiteActions control in master page.

The text property is not editable, it is read only.

I have done this in a different way. Here is the alternative solution.

You need to create an image which includes the text you want to show instead of actions menu.

Open master page in SharePoint designer.

Select “Manage styles” pane at the right hand, if you don’t see it then  click “task pane” and go to “manage styles” from menu bar od SharePoint designer.

Select “.ms-siteaction,.ms-siteaction a” , double click to open core.css which only applys to current site.

Add  the following code to the tab.

Font:0px;
Background-image <url of your image with text>
Text-decoration: none;
width: 50px;
height: 20px;

The width and height could be change according to your requirement.

Now save the changes in core.css and go back to your user interface of your site, the text will be replaced by the text you defined in the image.

AvatarByRashid Aziz

SharePoint 2010 Managed Metadata columns programatically

You can provision managed metadata column into the content type.

You need to add the “Metadata” column into the site columns and content type using element xml file, and also need to connect the field to metadata column in the feature activation.

Here is the solution

1.    You need to add a new field element of the type “TaxonomyFieldType”.

<xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Field ID="{46138ADB-1778-4E05-8371-114006F725A0}"
    Type="TaxonomyFieldType"
    DisplayName="Locations"
    ShowField="Term1033"
    Required="TRUE"
    EnforceUniqueValues="FALSE"
    Group="_Custom"
    StaticName="Locations"
    Name="Locations"
     />
</Elements>

2.    Add this filed to the content type, just need to add a new “FieldRef”

<FieldRef ID="{46138ADB-1778-4E05-8371-114006F725A0}" Name="Locations"/>
 
3.    Now we have to connect this field to managed metadata service(MMS).
 For this we need to create an event receiver for the feature. Right click on the feature 
 and select “Add event receiver”.
Uncomment the “feature activate” code and replace it with the following code. 
public override void FeatureActivated(SPFeatureReceiverProperties properties) { 
    SPSite site = properties.Feature.Parent as SPSite; 
    Guid fieldId = new Guid(“{46138ADB-1778-4E05-8371-114006F725A0}"
    if (site.RootWeb.Fields.Contains(fieldId)) { 
        TaxonomySession session = new TaxonomySession(site);
        if (session.TermStores.Count != 0) { 
            var termStore = session.TermStores["Managed Metadata Service"]; 
            var group = termStore.Groups.GetByName("Locations Group"); 
            var termSet = group.TermSets["Towns"];
 
                    TaxonomyField field = site.RootWeb.Fields[fieldId] as TaxonomyField;
            field.SspId = termSet.TermStore.Id; 
            field.TermSetId = termSet.Id; 
            field.TargetTemplate = string.Empty; 
            field.AnchorId = Guid.Empty; 
            field.Update(); 
        } 
    } 
}

This method will check if the field has been deployed. We used Guid to retrieve the filed as defined in the XML.  Your term store group definition should look like this.  

                           

If it is different then you need to change the “group name” and “term set” name in the feature activation according to your MMS environment.

Now you deploy your content type and can test it by creating a new list from that content type.

 

The result with the metadata column is shown in the below picture.

 

             

AvatarByRashid Aziz

SharePoint 2010 custom actions page inside Modal Dialog

If you have a custom action under SharePoint 2010 “welcome menu” or under “site actions menu” and when you click on the custom action you want to open the application page in standard SharePoint modal dialog. Here is the solution,

You need to change the UrlAction code in the element file as given below

<?xml version="1.0" encoding="utf-8"?> 

<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> 
  <CustomAction 
        Id ="CustomMenu_MoreInformation"
        GroupId="PersonalActions"
        Location="Microsoft.SharePoint.StandardMenu"
        Sequence="1000"
        Title="More Information"
        Description="View more information"  
        ImageUrl="_layouts/ebloginImages/logo.png">
    <UrlAction Url="javascript:OpenPopUpPageWithTitle('{SiteUrl}/SitePages/MoreInformatin.aspx, RefreshOnDialogClose, 600, 400,'My Custom Action')"/>

  </CustomAction>
</Elements>

Now when you click on the menu option, your application page will open in modal dialog as shown in below pictures.