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