Tuesday, October 22, 2013

SharePoint Add Calendar Overlay Programmatically

This is sample of code to add calendar overlay pro grammatically:

using (SPSite site = new SPSite("http://sp2013-tarek294:8000/"))
     using (SPWeb web = site.OpenWeb())
          web.AllowUnsafeUpdates = true;
          SPList list = web.Lists["Calendar"];
          SPView m_view = list.Views["Calendar"];
          m_view.CalendarSettings = SerializeAccessors();
          web.AllowUnsafeUpdates = false;


private static string SerializeAccessors()
 return "<AggregationCalendars>
  <AggregationCalendar Id="{56594c0c-5649-458e-a4e3-939589ddc75d}" Type="SharePoint" Name="Holiday" Description="Holiday" Color="5" AlwaysShow="True" CalendarUrl="/Lists/Calendar/Holiday.aspx">
    <Settings WebUrl="http://sp2013-tarek294:8000" ListId="{6913f374-1a4e-4772-8c5f-9f5d56610f71}" ViewId="{0091da5e-e5a4-4e1f-ab96-19f96eeb59fa}" ListFormUrl="/Lists/Calendar/DispForm.aspx" />
  <AggregationCalendar Id="{d65114d1-cb97-41db-a7eb-7cc3614c957e}" Type="SharePoint" Name="Meeting" Description="Meeting" Color="8" AlwaysShow="True" CalendarUrl="/Lists/Calendar/Meeting.aspx">
    <Settings WebUrl="http://sp2013-tarek294:8000" ListId="{6913f374-1a4e-4772-8c5f-9f5d56610f71}" ViewId="{68513c26-b132-4d9e-b9ca-acc74a4cf1dc}" ListFormUrl="/Lists/Calendar/DispForm.aspx" />
  <AggregationCalendar Id="{cd33c105-6dd4-4cb9-b6ee-ca26dfcdb70e}" Type="SharePoint" Name="TestView" Description="TestView" Color="3" AlwaysShow="True" CalendarUrl="/Lists/Calendar/TestView.aspx">
    <Settings WebUrl="http://sp2013-tarek294:8000" ListId="{6913f374-1a4e-4772-8c5f-9f5d56610f71}" ViewId="{2D81DDC1-A360-4585-BF4A-7C0E512C7AA8}" ListFormUrl="/Lists/Calendar/DispForm.aspx" />

SharePoint 2013 Read Overlay setting using javascript

You can use the following the code to retrieve Calendar Overlay settings using Javascript:

EnsureScriptFunc('sp.js', 'SP.ClientContext', function(){
            var clientContext = new SP.ClientContext.get_current();
            if (clientContext != undefined && clientContext != null) {
                 var web = clientContext.get_web();
                 var listCollection = web.get_lists();
                 var list = listCollection.getByTitle("Calendar");
                 var viewCollection = list.get_views();
                 this.view = viewCollection.getByTitle("Calendar");
                 clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),    Function.createDelegate(this, this.onQueryFailed));
 function onQuerySucceeded() {
        alert(this.view.get_htmlSchemaXml()); //this contains overlays settings
 function onQueryFailed(sender, args) {
       alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());

Monday, October 21, 2013

Remove “recent” links from the Left Nav in SharePoint 2013

You can use the following script to master page to remove recent links from Quick launch in SharePoint 2013
jQuery(document).ready(function() {

Friday, October 11, 2013

SharePoint Impersonation mistake

SharePoint API give us function  SPSecurity.RunWithElevatedPrivileges to impersonate by system account users. Some users make mistake in using it by using current site instead of initiate new SPSite.:

SPSecurity.RunWithElevatedPrivileges(() =>

using ( SPSite site = SPContext.Current.Site)
using (SPWeb web = site.OpenWeb())

Developer need to use:
SPSite site = new SPSite(SPContext.Current.Site.Url)

instead of:
SPSite site = SPContext.Current.Site

Code will be:
SPSecurity.RunWithElevatedPrivileges(() =>

using ( SPSite site = new SPSite(SPContext.Current.Site.Url) )
using (SPWeb web = site.OpenWeb())

Thursday, September 19, 2013

Enable Validator in Email in arabic DisplayName

To Create formula validation for fields in arabic display name you needto replace all commas ',' with semicolons ';'

Check below Email Formula validation  for Arabic field:

=AND(ISERROR(FIND(" ";[البريد الالكترونى];1));IF(ISERROR(FIND("@";[البريد الالكترونى];2));FALSE;AND(ISERROR(FIND("@";[البريد الالكترونى];FIND("@";[البريد

الالكترونى];2)+1));IF(ISERROR(FIND(".";[البريد الالكترونى];FIND("@";[البريد الالكترونى];2)+2));FALSE;FIND(".";[البريد الالكترونى];FIND("@";[البريد الالكترونى];2)+2)

Safari Browser does not run videos in Asset Library

When used Safari browsers and tried to access videos in asset library, I found black block.
I know Safari supports Html 5 and can run Video tag. After some investigation I found article describe the problem, Safari needs to install quick time to run video using Video tag for more details check Url:


Thursday, August 29, 2013

Move Search Components To Different Server in SharePoint 2013 Problem

I want to move search components from front end server to separate server, I used the flowing url:

After doing the following steps and checked search components, I found only crawled components moved successfully and others are suspended.

After investigations I remembered,  We did memory limitations for Fixing Performance Issue Caused By Node Runner In SharePoint 2013.
Memory limitations prevent creation of new search components successfully. I removed memory limitation and success to move search components.

Friday, August 16, 2013

SharePoint Migration Utilities

When I Migrated or revamped SharePoint I need to do some tasks help migrate old items, alerts, etc with new structure. I wroted some utilities to do these tasks using SharePoint API. I know there is many tools can do these tasks but here will find free utilities to do simple tasks.
Copy Files
Copy list Document libraries  and mapped old properties to new properties.

Copy Alerts
Copy Alerts from source web to destination Web

Copy Images
Copy Images from source image library to destination image library

Copy List Items
Copy List Items from source list to destination list

Copy Pages with resources
Copy Publish Pages between source and destination, Update layouts, clean HTML

Copy SharePoint Security
Copy Security between source and destination list.

Utilities help in migration tasks

Thursday, May 16, 2013

Reduce the size of logging database

To reduce the size of the logging database or to purge the old data from the logging database we can these steps:
By Default the system retains 14 days of Usage data in this database. You need to decrease value of the retention days by the following PowerShell Command:
Set-SPUsageDefinition –Identity "Event Selection" -DaysRetained days
Set-SPUsageDefinition –Identity “Page Requests" -DaysRetained 3
You can get values of retention days by the following command
After that we need to run the two timer jobs to clean the old data, Go to Job Definitions and Run the following Jobs:
  • Microsoft SharePoint Foundation Usage Data Import
  • Microsoft SharePoint Foundation Usage Data Processing
Once the timer jobs is run you can check and confirm database has released the space.

Failed to unlock sitecollection

For some unknown reason for the admin user of our Moss site (and all other users who had full control permissions) the Site Action -> Site Settings menu option have disappeared from the home page. I can navigate to it by going to mysite/_layouts/settings.aspx but I can't change anything it says I do not have permissions.

IF the user logged IS the Site Collection administrator and still gets theses access denied messages, your Content Database seems to be locked. This happens during backups or when backups go wrong (get interrupted for example)
stsadm -o getsitelock -url http://server_name

if it is not showing as 'none', it is locked. fix command:
stsadm -o setsitelock -url http://server%5Fname -lock none

I used this command many times but when try to use with some sites it didn't work. I found Power Shell Commands Solved my Problem.
$Admin = new-object Microsoft.SharePoint.Administration.SPSiteAdministration(SiteUrl)

Monday, May 6, 2013

SharePoint 2013 Content source does not crawl

Where created new search service application and tried to crawl, It generate status starting and take a long time without changes and crawl duration still empty like image below.

I tried to recreate service many times and problem still exists.
I found error in Search Application Topology:
I fixed these problems by Fixing Query Processing, Steps to Fix Query Processing:
  1. Run SharePoint PowerShell
  2. Get the Search Service Application and clone the search topology:
    # Clone the active search topology
    $ssa = Get-SPEnterpriseSearchServiceApplication -Identity "Service Application Name"
    $active = Get-SPEnterpriseSearchTopology -SearchApplication $ssa -Active
    $clone = New-SPEnterpriseSearchTopology -SearchApplication $ssa -Clone –SearchTopology $active
  3. Get QueryProcessingComponent ComponentId by run command
    Get-SPEnterpriseSearchComponent -SearchTopology $clone
    Get component Id as Figure
  4. Remove the component by using the ComponentId
    Remove-SPEnterpriseSearchComponent -Identity 1c138785-382e-45f3-8e55-ee8d189cf1c0 -SearchTopology $clone -confirm:$false
  5. Add new Search component using command:
    $wfe = Get-SPEnterpriseSearchServiceInstance -Identity "Web front name"
    New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $clone -SearchServiceInstance $wfe
  6. Activate search component
    Set-SPEnterpriseSearchTopology -Identity $clone

After this step error disappear and search topology does not generate error and I succeed crawling.

Monday, April 29, 2013

Cannot delete Column from List

When tried to delete some columns from list using GUI, Some of them don't give me option to delete.
Problem: I Can't delete column if it is sealed, hidden, or readonly
Solution: Change values of these properties to false before trying to delete

You can use PowerShell to change these properties and remove column from List like below:
$web = Get-SPWeb -identity SiteUrl
$list = $web.Lists[listName]
$column = $list.Fields[FieldName]
$column.Sealed = $false
$column.Hidden = $false
$column.ReadOnlyField = $false

Thursday, April 25, 2013

SharePoint Variation Labels error

When tried to access Variation Label on SharePoint I faced error:

Field not found: Label

After investigation, I found article solved my problem:

Problem is some one in team changed Display Name of Label Field to Title. variationlabels.aspx page looks reads the item data based on the display name of the field. To solve problem Goto Variation Labels List and Change Title Field to Label and problem will be solved.

Wednesday, April 17, 2013

Design View in SharePoint Designer 2013

Microsoft removed Design View from SharePoint Designer 2013. SharePoint supposed new 2 options for the display of information in custom formats, SharePoint 2013 provides us with two options: 

  1. JSOM (JavaScript Object Model)/JQuery Custom Format
  2. Application of custom display templates to the Content Search web part to display the cross site information.

But we still need to use DataView for these reasons:

  • Problem of first option we need to handle cases of client browsers and crawlers does not support client side.
  • Content Search web part is not up to date.
Although  Microsoft removed Design View from SharePoint Designer 2013 we can create dataview with Share Point Designer 2013. When started to do this i faced many problems like ribbon actions activated or dimmed unexpected, DataView is not exported correctly.

I found article helped me to solve my problem:

I found my problem. I created blank page, I should created it as BlankWebPart. After created page as BlankWebPart and Edit page it in advanced View(with advanced view I cannot edit the page).

Tuesday, April 16, 2013

An exception of type Microsoft.SharePoint.Upgrade.SPUpgradeException was thrown.

I faced the following error when to run sharepoint 2010 configuration wizard in my windows 8 machine:

An exception of type Microsoft.SharePoint.Upgrade.SPUpgradeException was thrown. Additional exception information: Failed to call GetTypes on assembly Microsoft.Office.Server.Search, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c. Could not load file or assembly 'System.Web.DataVisualization, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

I found problem I am not installed Chart Control in my machine. Problem is solved after download and installed. Chart control can be downloaded from the following location:

Monday, April 15, 2013

SharePoint 2013 Localizing Display Template

SharePoint 2013 is new and we didn't find documentation for  many items. One of missing items detailed documentaion about scripts in display templates.

I need to localize my template after I checked existing templates I found localization through JavaScript:
  1. They added local string in resource javascript file. You can create a JavaScript and add to your code as below:
      $includeLanguageScript(this.url, "~sitecollection/_catalogs/masterpage/Display Templates/Language Files/{Locale}/YourCustomStrings.js");
    < /script >
  2. Code you will add to JavaScript:
    // Add your custom localized strings and then include these string dictionaries in your display templates using the $includeLanguageScript function

    $registerResourceDictionary("en-us", {
    "sampleCustomStringId": "Sample custom string",
    "rf_RefinementTitle_ManagedPropertyName": "Sample Refinement Title for ManagedPropertyName"
  3. To access resource using the following code:
    var diagRes = $resource("item_Diagnostic_ItemTitleFormat");

Monday, April 1, 2013

SharePoint Designer: Error while Compiling

I tried to create workflow in SharePoint Designer:

The Error occurrs only, if the workflow contains a workflow lookup and i want to compile it.
In this case the following error-code appears:
Microsoft.Workflow.Client.ActivityValidationException: Workflow XAML failed validation due to the following errors:
Cannot set unknown member 'LookupSPListItemStringProperty.ItemId'. HTTP headers received from the server - ActivityId: 9aefe91b-ad3d-4942-a9d6-62b23573db09. NodeId: WFFE_IN_1. Scope: /spo/2066dfc3-753d-448e-8402-3a0b9b06492d/42fbc970-d795-4c3e-b511-3d6368d46642/8a0077c0-0b4b-45e4-bde5-07ece5ae2c20. Client ActivityId : 2114fc9b-50c5-c037-e339-58dfee5e3821. ---> System.Net.WebExcepti

It took long time from me to solve. I decided to Re-register service into my side using command:

Register-SPWorkflowService -SPSite 'https://myhost/mysite' -WorkflowHostUri 'https://workflowhost' -AllowOAuthHttp -Force

I reopened SharePoint Designer again and problem disappeared.

Thursday, March 28, 2013

SharePoint 2013 Sign as different user

SP2010 environment shows that the actual link for signing in as a different user is /_layouts/closeConnection.aspx?loginasanotheruser=true

SharePoint 2013 removed from the UI
But link still exists you can use.
They remove it because this option uses an unsupported browser feature which is unreliable and causes other issues. It is not supported by IE10, Safari

Thursday, March 14, 2013

Optimizing Server Configuration for Development Farm

Setting up development environments for SharePoint Server has always been very difficult and costly because of the hardware requirements specifications needed.You can use hardware with lower specs by some tips and tricks I found in article below:

Thursday, February 28, 2013

Create a dataview in sharepoint with datasource webservice

To create DataView in SharePoint Desgner based on SOAP Web Service do the following Steps:
  1. From Navigation Pane, click Data Sources.  From Ribbon, click the SOAP Service Connection Menu Item. DataSource Dialog Properties will appear:
    1. Service Description Location: This is the URL to the service description (WSDL) file.
      ex: http://[SharePoint Site URL]/_vti_bin/lists.asmx?wsdl
      Click Connect Now so SharePoint Designer can retrieve the description file. 
    2. Data Command: Like a REST service connection, this box identifies the command  that your data source is going to be configured to run. You need to support multiple datasource if you will use multiple command.
    3. Port: If the web service supports multiple interfaces, they will be listed here. The
      default port will be selected.
    4. Operation: When the Connect Now button is clicked, the wizard retrieves the WSDL
      file, which defines all of the operations that can be performed on the web service.
    5. Parameters: As mentioned previously, if the operation selected in the previous step
      requires parameters, those will be listed.
      If you tried to modify any parameter to set its value you will find check-box you must checked it if you want to your parameter dynamic read from (Control, QueryString, Cookie, Post Data,...)
  2. The wizard has two other tabs that are the same as the other data sources. 
    1. The Login tab can be used to set default login credentials.
    2. The General tab is used to provide a description of the data source configuration. 
  3. Create a new web part page, call it TestSOAP.aspx, and open it in Edit mode. . 
  4. Click in the web part zone, and then from the Ribbon, click Data View and add your data source.
  5. Drag your needed columns from the datasource and apply your adjustment and formatting of data view.
  6. When you finish you can export DataView by the following steps:
    1. click into the Web Part ribbon tab under List View Tools
    2. You have two options, To Site Gallery, and To File. 
Tips and Tricks:
  1. If you set parameter in your web service to read from connected webpart you find ParameterBindings appeared as below (check text in red). You can add more parameters with same way:

  2. <DataSources>
       <SharePoint:SoapDataSource runat="server" id="SoapDataSource1" AuthType="Basic"  
      SelectUrl="http:// ServerUrl/_vti_bin/lists.asmx"
      SelectAction="http://schemas.microsoft.com/ sharepoint/soap/GetList"
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
       <GetList xmlns="http://schemas.microsoft.com/sharepoint/soap/">

        <SelectParameters><WebPartPages:DataFormParameter Name="listName"    
              ParameterKey="listName" PropertyName="ParameterValues"        

      <ParameterBinding Name="listName" Location="None"  
      <ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>
      <ParameterBinding Name="ManualRefresh" Location="WPProperty[ManualRefresh]"/>
      <ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>
      <ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>
      <ParameterBinding Name="dvt_firstrow" Location="Postback;Connection"/>
      <ParameterBinding Name="dvt_nextpagedata" Location="Postback;Connection"/>

SharePoint Designer 2013 will not support Design View

Design View removed SharePoint Designer 2013. they say the reason new web standards for client side rendering of pages such as JavaScript, JSON, and OData, there is no longer a need to support a visual web page editor within SharePoint Designer.

Monday, February 25, 2013

Snippets for SharePoint 2013 masterpages and layouts

A snippet is an HTML representation of a SharePoint component or control such as a navigation bar or a Web Part. By using the Snippet Gallery in Design Manager, you can quickly add SharePoint functionality to your HTML master page or page layout.
To insert a snippet:
1.       Browse to your publishing site.
2.       In the upper-right corner of the page, choose the Settings gear, and then choose Design Manager.
3.       In Design Manager, in the left navigation pane, choose Edit Master Pages or Edit Page Layouts, depending on what type of file you're editing.
4.       Select the name of the master page or page layout that you want to add snippets to.
5.       To open the Snippet Gallery, choose Snippets in the upper-right corner of the server-side preview.
6.       On the ribbon, on the Design tab, choose the snippet that you want to add to your page.
To Understand the markup in an HTML snippet check url:

Creating a Custom Page Layout in SharePoint 2013

To Create a Custom Page Layout in SharePoint 2013 do the following steps:

  1. Create Content Type:
    1. From Site Settings select Site Content types
    2. Press button Create to create Content Type 
      Select parent content type from: Publishing Content Types
      Parent Content Type: Page  Layout
    3. Add the following fields to the content type:
      • LargeHeadline – Single line of text
      • RightHandBlurb – Multiple lines of text
      • LeftLinkList – Full HTML
      • LeftColumnTitle – Single line of text
      • LeftColumnText – Full HTML
      • RightColumnText – Full HTML
  2. Creating a Page Layout:
    1. Go to the Design Manager
    2. Edit Page Layouts
    3. Create a page layout
  3. Publishing Your Page Layout
    To publish your page layout, go to Site Settings –> Master pages and page layouts. 
    To publish your layout, click on the HTML file and then Publish this will reflect also in aspx:

  4. Creating a Page:

  5. Now we can publish our page.
  6. Customizing Page Layouts. There are two ways to grab the file: 
    1. Go to Design Manager –>3. Upload Design Files and map a network drive to your master page directory.
    2. Go to Site Settings –> Master pages and page layouts and you can download your file.
    3. Moving the snippets provided by SharePoint 2013 into the appropriate spots,  to customize layout page.

Sunday, February 24, 2013

Creating a Custom Master Page in SharePoint 2013

 To Create a custom master page in SharePoint 2013:
  1. Design your master page as html with structure folder:
  2. Go to The Design Manage
  3. Mapping to the Master Page Directory by Edit Master Pages:

  4. Click on that link and you will see this dialogue box:
  5. If you use  Windows Server 2012  you need to install feature “Desktop Experience” for next steps.

  6. You need to select the folder containing Master Page and Page Layouts as well as their dependent assets (CSS files, scripts, images, etc.). To do this:

    • Go to Windows Explorer, right click on your computer and select Map Network Drive. 

    • Connect to network drive
    • Select url to map to folder
    • Now we can simply copy our template and dependent files into this folder
  7. Now you can select your html master page and click insert.
    NOTE: SharePoint 2013 expects your HTML to be XML Compliant. If you have older or non-compliant HTML you will get an error. Fix your file and try again.
  8. Press Conversion and successful link to see preview of this page.

  9.  At the bottom of the page you will see a Yellow Box that represents the place holder where dynamic content is going to be inserted. We're going to now move that place holder into where we want it to replace our dummy text in the middle of the page.
  10. Download the HTML file from the Share Point 2013 environment and open it in your HTML editor and you will see that Share Point 2013 has decorated your HTML with a number of tags.  These tags are used by Share Point 2013 as markup to specify where to put to insert content when it generates the Master Page. 
  11. Publish HTML file it will reflect automatically in master file.

SharePoint 2013 Customize master-page

To Customize sharepoint master-page:
  1. Open SharePoint 2013 in SharePoint Designer 2013
  2. Find corresponds html to your master page 
  3. Edit in advanced mode
  4. Add html before end of workspace div:
    <div class="s4-notdlg" id="Footer" style="background: black; color: white;"> © CopyRight 2013</div> </div> 
  5. Check the result

Saturday, February 23, 2013

SharePoint Server 2013 Top New Features for Public-Facing Internet Sites

This blog will list top new features of SharePoint 2013 for Publishing Site:

  1. Catalogs 
  2. Cross-site Publishing 
  3. Content (by) Search Web Part 
  4. Multiple SPSite URLs 
  5. Managed Navigation
Multilingual Sites:
  1. Improved Variations 
  2. Integration with Cross-site Publishing 
  3. Improved Metadata Management 
  4. Machine Translation Service 
  5. Country Code Top-level Domains
  1. Cleaner HTML markup 
  2. Image Renditions 
  3. Video Improvements
  4. Content Copy-Paste 
  5. Custom Error Pages  
Look and Feel:
  1. Design Manager 
  2. Composed Looks 
  3. Theming Model 
  4. Device Channels 
  5. HTML 5 Compatibility
Search Engine Optimization (SEO)
  1. No Home Page Redirection  
  2. Robots.txt and XML Sitemaps 
  3. Friendly URLs
  4. Canonical URL Filtering 
  5. SEO Properties
  1. CSOM  
  2. App Model 
  3. REST 
  4. Search 
  5. Mobile