Search This Blog

Thursday, December 19, 2013

Solution to authentication error while opening browser enabled Infopath forms with data connections

Recently I was working on creating a browser enabled InfoPath Form in SharePoint 2013. I created some data connections in the form and published it in Forms library. But at the very first step it started giving me authentication error-

"An error occurred querying a data source. 
Click OK to resume filling out the form. You may want to check your form data for errors. "

I also checked the Logs folder inside 15 hive and found this:

"Data adapter failed during OnLoad: Authentication information in the UDC file could not be used for this connection because user forms are not allowed to use UDC authentication."

To resolve this Issue go to your IIS and click on the web application in which you want to publish your InfoPath form and then click on the "Authentication" tab (as shown in below screen shot)

Under Authentication tab, double click on the "ASP.Net Impersonation" and set it to "Disable".
Now re-open your InfoPath form and see it working.

Tuesday, December 17, 2013

Programmatically adding JQuery, custom JS and CSS file reference to your master page without modifying the master page

I found very interesting component of SharePoint -AdditionalPageHead Content Place Holder in master page which can be used for adding JavaScript, Meta Tags, CSS Styles or other content to the page without modifying them.

One practical scenario would be programmatically adding JQuery, custom JS and CSS file reference to your master page without modifying the master page it.

You need to create a Delegate Control and deploy it using a feature. Below is the snapshot for Feature.XML file.
<?xml version="1.0" encoding="utf-8"?>
  <Control Id="AdditionalPageHead"

Change the sequence number and control path and name as per your requirement. 

In the MyCustomPageHead.ascx add the references of JS/CSS

<script type="text/javascript" src="/_layouts/../JS/jquery-1.7.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="/_layouts/../../../jquery-ui-1.8.18.custom.css" />
<script type="text/javascript">

Just deploy your feature and activate it in the site where you want to add JS and CSS references.

Monday, December 16, 2013

SharePoint App Model: Viability on public facing websites including Office 365

Failed to get data. Error: Access denied. You do not have permission to perform this action or access this resource.

Well when one thinks of deploying their SharePoint apps (those which interact with SharePoint lists and libraries) on public facing websites there’s a challenge that one gets stuck into. The anonymous users by default do not have access to the Client Side Object Model (by default) nor to the REST API. There’s a solution of enabling the CSOM access for the anonymous users in 2 ways: first, go to Site Settings / Site Permissions and then click the Anonymous Access button on the ribbon.  There’s a checkbox which says “Require Use Remote Interfaces permission” uncheck it and click OK. The second method one can set the same property is by using a PowerShell command UpdateClientObjectModelUseRemoteAPIsPermissionSetting

Using any one of the above described methods the CSOM access by the anonymous users is enabled and the anonymous users can have access to the SharePoint Lists and libraries. When one removes the required remote interface permission for an anonymous site, the entire CSOM is available to anonymous users but that does not mean the entire site can be accessed by the anonymous user rather the SharePoint permissions still apply and can be used to restrict access to confidential/important data that does not need to be shared with such users.

This is the situation when one is using a public facing SharePoint site but this does not apply to an Office 365 public facing site wherein there’s a limitation. A SharePoint app (that interacts with SharePoint lists and libraries) does not work on an office 365 public facing site for anonymous users by default. There’s a solution though: a sandbox solution can be made for enabling the anonymous access on Office 365 public facing site (as far as possible). For more information on this one can visit the following URL:

Saturday, December 14, 2013

How to update BDC / BCS custom connector DLL programmatically in SharePoint 2010

using System.Management.Automation.Runspaces;
using System.Management.Automation;

public static void UpdateBDCDLL(string webappURL, string strModelName)
// Mapping Assembly of BDC
                string DllPath = @"@"<DLL PHYSICAL PATH>";
                //create powershell runspace
                RunspaceConfiguration config = RunspaceConfiguration.Create();
                PSSnapInException OExSnapIn = null;
                PSSnapInInfo pssnap = config.AddPSSnapIn("Microsoft.SharePoint.PowerShell", out OExSnapIn);
                Runspace cmdlet = RunspaceFactory.CreateRunspace(config);                cmdlet.Open();
                RunspaceInvoke scriptInvoker = new RunspaceInvoke(cmdlet);

// set powershell execution policy to unrestricted

                scriptInvoker.Invoke("Set-ExecutionPolicy Unrestricted");  

// create a pipeline and load it with command object
                  Pipeline pipeline = cmdlet.CreatePipeline();
              StringBuilder sbPSCommand = new StringBuilder();
                sbPSCommand.AppendLine("$assemblyPath = '" + DllPath + "'");
                sbPSCommand.AppendLine("$lobSystem = '" + strModelName + "'");
                sbPSCommand.AppendLine("$url='" + webappURL + "'");
                sbPSCommand.AppendLine("$serviceContext = Get-SPServiceContext $url");
                sbPSCommand.AppendLine("$lobSystem = Get-SPBusinessDataCatalogMetadataObject -ServiceContext $serviceContext -BdcObjectType lobsystem -Name $lobSystem");
                sbPSCommand.AppendLine("Import-SPBusinessDataCatalogDotNetAssembly -LobSystem $lobSystem -Path $assemblyPath -Confirm:$false");
                Pipeline pipeline2 = cmdlet.CreatePipeline();
            catch (Exception ex)
                //exception handling goes here

Saturday, September 21, 2013

Microsoft SharePoint Server 2013 Licensing and pricing

Now again Microsoft has changed the paradigm of licensing with SharePoint 2013

Lets have a look, how it works now. This content has been taken from a Microsoft document which might change in future,  Please contact Microsoft licensing team before taking any final decisions on licensing part.

Concepts that Provide a Framework for SharePoint Server Licensing

Internal Users: Users who are the licensee’s or its affiliates’ employees and on-site agents and contractors.
External Users: Users who are not the licensee’s or its affiliates’ employees or on-site agents or contractors.
Intranet: Website hosting content, information, or software that is accessible inside the firewall to internal users only.
Extranet: Website hosting content, information, or software that is accessible inside the firewall to internal users and named external users only.
Internet: Website hosting content, information, or software that is publicly accessible to all users (internal and external).


Microsoft SharePoint Server 2013 Licensing

Microsoft licenses SharePoint Server 2013 under the Server/Client Access License (CAL) licensing model. The Server/CAL licensing model requires both a server license for each copy of the server software a customer installs and uses and CALs for the users (or devices) that access that software. CAL requirements vary based on user status, and CALs are generally required for internal users to access all SharePoint Server software. An exception to this is internal user access to Internet websites (public-facing websites such as e-commerce sites). In this case, the SharePoint CAL requirement is waived. In contrast to the general requirement for CALs for internal user access, CALs are not required for external users to access SharePoint Server. In other words, the server license provides access rights for external users. The same criteria can be used for determining when CALs are required for SharePoint base CALs and Enterprise CALs; however, SharePoint Enterprise CALs are required only if functionality corresponding to the SharePoint Enterprise CAL is accessed. For more information about which SharePoint features are part of the base product and which features are considered additional functionality requiring additive CALs, refer to


The following decision tree illustrates whether a user needs a SharePoint CAL or not. “Restricted” refers to content stored inside the firewall for internal access and possibly limited, identified external user access. “Public/Internet” refers to content stored outside the firewall for broad, unrestricted access.


User Scenarios

This document also illustrates common deployment scenarios to further explain the licensing requirements of SharePoint Server 2013. Users can license these same deployment scenarios under device-based CALs.

Scenario A: Intranet

Description: Internal users accessing content, information, or applications inside the firewall through a local area network (LAN) or the Internet. No other users have access.
Example: A professional sports team sets up an intranet site that the manager, coach, and players access. It is also used for support staff such as the physiotherapist who is an on-site contractor rather than an employee, and for CAL requirements, an internal user. A news reporter trying to access the SharePoint Server site is denied access.
Server: One SharePoint Server 2013 license per running instance of the software.
Internal Users: One CAL/user.


In Figure 3, the internal users (the team’s managers, coach, players, and on-site therapist) each must be assigned a CAL. This requirement does not change if the same users are accessing the intranet site remotely from the team’s offices. Given that this is an intranet site, no external user access is permitted.

Scenario B: Extranet

Description: An organization extends access to otherwise restricted content inside the firewall to a limited number of identifiable external users.
Example: The Elm University publishes research papers that are available to specific educators from other universities (external users). This situation is an intranet plus extranet scenario.
Server: One SharePoint Server 2013 license per running instance of the software.
Internal Users: One CAL/user.
External Users: SharePoint CALS are not required; the server license permits external user access.


In Figure 4, the internal users (the school’s faculty and staff) each must be assigned a SharePoint CAL. This requirement does not change if the same users access the site remotely while they are off-campus. The identifiable external users (educators from other universities) who are permitted to access otherwise restricted content inside the firewall do not require SharePoint CALs, because external user access is permitted under the server license. No other users are permitted to access the site.

Scenario C: Internet

Description: Internal users make content, information, and applications publicly available to users via the Internet (for example, on a public-facing company website). A mix of internal and external users anonymously accesses the site, including employees. No SharePoint CALs are required. External user access is permitted under the server license, and SharePoint CAL requirements for internal users are waived for access to content, information, and applications made publicly available via the Internet.
Server: One SharePoint Server 2013 license per running instance of the software.
Internal Users: CALs are not required.
External Users: CALs are not required.


In Figure 5, access is unrestricted. The only license required is the server license. SharePoint CALs are not required to access content, information, and applications made publicly available to users via the Internet (that is, not restricted to intranet or extranet scenarios). The same licensing applies for an e-commerce site where access is not strictly anonymous. Again, SharePoint CALs are not required to access content, information, and applications made publicly available to users via the Internet.

Simplifying Licensing

SharePoint Server 2013 simplifies SharePoint access and use. This is because SharePoint Server 2013 collapses internal and external use under a single licensing offering/model. Customers no longer need to look to SharePoint for Internet Sites to license anonymous access. Additionally, SharePoint Server 2013 integrates functionality that was previously available separately under FAST Search Server for SharePoint.

Monday, June 17, 2013

Send Large data with SharePoint Webservice

When ever you need to send lots of lots of data in WCF REST service using custom SharePoint MultipleBaseAddressWebServiceHostFactory then you will encounter following error 

(400) HTTP Bad Request

When you look into service trace you will find the actual root cause of this issue is that the data sent is not supported by default and its failing internally in deserialize process

<ExceptionType>System.ServiceModel.Dispatcher.NetDispatcherFaultException, System.ServiceModel, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter The InnerException message was 'There was an error deserializing the object of type System.String. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader.'.  Please see InnerException for more details.</Message>

Now if you try to override the settings in web.config then web service will complain about multiple settings for the same end point because factory it self creates the dynamic end points so web.service changes can't be used unless you remove the factory class and do it conventional way.

So what is the solution :

Its easy that we need to just extend two classes


 public class CustomMultipleBaseAddressWebServiceHostFactory : Microsoft.SharePoint.Client.Services.MultipleBaseAddressWebServiceHostFactory
        protected override System.ServiceModel.ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
            return new CustomMultipleBaseServiceHost(serviceType, baseAddresses);


    public class CustomMultipleBaseServiceHost : Microsoft.SharePoint.Client.Services.MultipleBaseAddressWebServiceHost
        public CustomMultipleBaseServiceHost(Type serviceType, params Uri[] baseAddresses)
            : base(serviceType, baseAddresses)

        protected override void OnOpening()


            foreach (ServiceEndpoint endpoint in this.Description.Endpoints)
                Binding binding = endpoint.Binding;
                if (binding is WebHttpBinding)
                    var web = binding as WebHttpBinding;
                    web.MaxBufferSize = Int32.MaxValue;
                    web.MaxReceivedMessageSize = Int32.MaxValue;
                var myReaderQuotas = new XmlDictionaryReaderQuotas();
                myReaderQuotas.MaxStringContentLength = Int32.MaxValue;
                binding.GetType().GetProperty("ReaderQuotas").SetValue(binding, myReaderQuotas, null);

Now if you see we can make the changes to any parameters like maxBufferSize or MaxrecievedMessageSize at the time of opening of channel.

Now instead of using default Microsoft class in the svc file we will use our custom dll reference. Deploy your solution. DO an IISRESET and you will be able to transmit huge data now :)

<%@ ServiceHost Language="C#" 
Factory="CustomMultipleBaseAddressWebServiceHostFactory, $SharePoint.Project.AssemblyFullName$"  %> 

Monday, May 6, 2013

Parameter count mismatch

If you are working with BCS to pull data for search service application or FAST Search then you might have encountered this error when ever you try to update a dll where you have added or removed parameters for either paging or some custom logic.

"Parameter Count Mismatch"

Here are the steps that you should use to resolve this issue :

1. Upload your dll in GAC
2. Run following commands in powershell

$url = "http://gdc-encore"
$assemblyPath = "Assembly path"
$lobSystem = "Lob system name"
Write-Host "Adding assembly to LOBSystem"
$serviceContext = Get-SPServiceContext $url
$lobSystem = Get-SPBusinessDataCatalogMetadataObject -ServiceContext $serviceContext -BdcObjectType lobsystem -Name $lobSystem
Import-SPBusinessDataCatalogDotNetAssembly -LobSystem $lobSystem -Path $assemblyPath

3. Reset search service from the services named "SharePoint Server Search 14" which is running mssdmn behind the scenes and caches the dll which causes the mismatch in assembly reference.

Saturday, March 23, 2013

Create Managed Path via PowerShell

#-----Function to Load SharePoint PowerShell Environment----#
function LoadSharePointPowerShellEnvironment
 write-host "Setting up PowerShell environment for SharePoint..." -foregroundcolor Yellow
 Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue
 write-host "SharePoint PowerShell Snapin loaded." -foregroundcolor Green

function Create-SPManagedPath
  param ($webApplicationUrl, $managedPathName)
  $managedPath = Get-SPManagedPath -WebApplication $webApplicationUrl -Identity $managedPathName -ErrorAction SilentlyContinue
  if ($managedPath -ne $null)
  Write-Host "Managed path $managedPathName already exists."

  Write-Host "Creating managed path $managedPathName ..."
New-SPManagedPath –RelativeURL $managedPathName -WebApplication $webApplicationUrl
  Write-Host "Managed path $managedPathName created sucessfully" -foregroundcolor Green

Create-SPManagedPath "http://mywebappurl" "logical"

Tuesday, March 19, 2013

Convert SharePoint 2010 solution to SharePoint 2013 in Visual Studio

Recently I tried to convert a SharePoint solution in visual studio 2010 to Visual Studio 2012, but it gave me errors like:

"The primary reference "Microsoft.SharePoint" could not be resolved because it has an indirect dependency on the .NET Framework assembly "mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" which has a higher version "" than the version "" in the current target framework."

You can refer to below steps if you want to convert your SharePoint 2010 solution (created with visual studio 2008 or 2010) to visual studio 2012 for SharePoint 2013: 
  • Open your visual studio .csproj file in notepad or visual studio and change the value of  tag "TargetFrameworkVersion" to 4.5

  • Add a new tag just below the one you modified in above step as:

This way your modified csproj file will have attributes as shown below:

  • You will also need to change the SharePoint Product version property of your  Package file from 14.0 to 15.0 as shown below. 
  •  In your aspx pages and code files, where you are referencing any image from Layouts folder, you need to append "/15" as:
           /_Layouts/15/<your image path>

Friday, February 1, 2013

Download all solutions wsp from sharepoint 2010 central admin using powershell

[Microsoft.SharePoint.Administration.SPFarm]$farm = [Microsoft.SharePoint.Administration.SPFarm]::get_Local()

Write-Host -foregroundcolor White "Starting solutions download process..."

foreach ($solution in $farm.Solutions)
Write-Host -foregroundcolor White ""
Write-Host -foregroundcolor Yellow "Downloading solution $solution..."
$file = $solution.SolutionFile
$solutionName = $
Write-Host -foregroundcolor Green "Solution $solutionName downloaded successfully."

Write-Host Write-Host -foregroundcolor Green "All solutions downloaded in c:\solutions folder"
Read-Host 'Done...'

Friday, January 4, 2013

Reset IIS on all the servers in FARM

Save the commands in a power shell script file and execute it in any of the servers present in FARM.

Write-Host -foregroundcolor Green "Restarting IIS on all the servers in FARM..."

# Get the local farm instance

[Microsoft.SharePoint.Administration.SPFarm]$farm = [Microsoft.SharePoint.Administration.SPFarm]::get_Local()

#Step through each server in the array and perform an IISRESET
#Also show IIS service status after the reset has completed

foreach ($server in $farm.Servers)
    if($server.Role -ne "Invalid")
       Write-Host -foregroundcolor White ""
       Write-Host -foregroundcolor Yellow "Restarting IIS on server $server..."
       IISRESET $server.Name /noforce
       Write-Host -foregroundcolor Yellow "IIS status for server $server"
       IISRESET $server.Name /status
Write-Host Write-Host -foregroundcolor Green IIS has been restarted on all servers
Read-Host 'Done...'