Pages

Thursday 28 February 2013

Configure People Picker for Multi-Domains(or Cross Domains), Forests Environments - SharePoint 2007 and SharePoint 2010

Excellent post by Salaudeen Rajack to

Configure People Picker for Multi-Domains(or Cross Domains), Forests Environments

 
 

Sunday 24 February 2013

How to replace an instance of a string within a string using javascript

If you have a long string, for  example "This is a long string, I want to remove the second string from this string" and you wanted to remove the 2nd instance of the word "string" from the long string using javascript. This method is helpful:

I am sure there are heaps of ways to do this, since I am new to javacript, I found this function helpful

function CustomReplace(strData, strTextToReplace, strReplaceWith, replaceAt) {
    var index = strData.indexOf(strTextToReplace);
    for (var i = 1; i < replaceAt; i++)
        index = strData.indexOf(strTextToReplace, index + 1);
    if (index >= 0)
        return strData.substr(0, index) + strReplaceWith + strData.substr(index + strTextToReplace.length, strData.length);
    return strData;
}


usage:

var txt = CustomReplace(txt,'string','',2);




Hope it helps :)

Monday 18 February 2013

Shutting down the mobile redirect for SharePoint 2010 sites

We had this problem the other day, where all internet requests were getting redirected to the mobile version and it kept prompting for credentials. 

The file that you need to modify is compat.browser
Location:  C:\inetpub\wwwroot\wss\VirtualDirectories\<webApp>\App_Browsers

Make a copy of the file in a different location and edit the file. Search for the entry:

<capability name=”isMobileDevice” value=”true” />. and change the value to false




For more detail visit this blog

Wednesday 13 February 2013

"Test Connection' button in Nintex Workflow 2010 does not work with MySQL connection strings

We had a situation where an end user was complaining about the connection string not working in Nintex Workflow 2010. My immediate conclusion was that the connection string was not correct, I double checked with www. connectionstrings.com and to my surprise it was fine.

The end user was testing by clicking on the test connection button 

 
The following error was returned:

 

Turns out that the "Test Connection" button defaults to MS SQL. The test connection button returned the following error but the workflow completed successfully.

There has been a support ticket logged with Nintex
http://connect.nintex.com/forums/thread/23150.aspx  

Tuesday 12 February 2013

When opening office (word, excel) documents from anonymous Internet facing site hosted on SharePoint 2010, users receive logon prompts

Scenario: 

When using IE and opening office (word, excel) documents from anonymous access enabled Internet facing site hosted on SharePoint 2010, users receive logon prompts. After hitting the escape key a couple of times the document does open. When using Firefox the logon prompt does not appear.

Reason:

IE opens word first and then word tries to download the document, however other browsers download the document and then open word to view the document.

According to the Microsoft Knowledge base article, giving "OpenItems" permission allows anonymous users to have view source rights to certain files that could potentially contain sensitive info.



Programmatically give "OpenItems" permission to the SPWeb to anonymous users. Note that you should only do this if you understand & accept the security implications. The sample script below can be used to add the "Open Items" permission:

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

$siteUrl = "http://URL_of_your_SITE";
$site = New-Object Microsoft.SharePoint.SPSite($siteurl);
$web = $site.OpenWeb();

$enumPerms = [Microsoft.SharePoint.SPBasePermissions];

Write-Host $web.AnonymousPermMask64;
$web.AnonymousPermMask64 = $web.AnonymousPermMask64 -bor $enumPerms::OpenItems
$web.Update();
Write-Host $web.AnonymousPermMask64;

$web.Dispose();
$site.Dispose();



In my case this did not work, so I had to change the approach to pass the relative path to the document to /_layouts/download.aspx

 Added this script to the Scripts.js (custom Javascript library for my SharePoint site) and called the method in $(document.ready.....


function rectifyOfficeDocumentLinks()
{
     $("a").each(function(){
                if (this.href.match(/.doc$/i) || this.href.match(/.docx$/i) || this.href.match(/.rtf$/i) || this.href.match(/.xls$/i) || this.href.match(/.xlsx$/i) || this.href.match(/.ppt$/i) || this.href.match(/.pptx$/i))
                {
                    if (this.href.indexOf("/_layouts/download.aspx?SourceUrl=") == -1)
                    {
                     this.href = _spPageContextInfo.siteServerRelativeUrl + "/_layouts/download.aspx?SourceUrl=" + this.href.replace("http://" + window.location.host,''); 
                    }
                }
                });
}


References:
  • http://social.msdn.microsoft.com/forums/en-SG/sharepointgeneralprevious/thread/62381802-20b9-49ee-985b-8d2dcd2453ea 
  • http://support.microsoft.com/kb/2498047/en-us
  • http://blogs.technet.com/b/acasilla/archive/2011/10/01/add-openitems-permission-to-the-default-anonymouspermmask64-so-that-you-can-open-office-docs-within-an-anonymous-accessible-sharepoint-site.aspx

Thursday 7 February 2013

Custom List form loading error "Error while executing web part: System.StackOverflowException: Operation caused a stack overflow"

To solve this issue either 
  • SharePoint will throw the stack overflow exception if a transform takes longer than 1 second. Then in such circumstances, please break the “dvt_1.rowedit” template into smaller template.
 Or

  • Microsoft has released february 2012 CU for SharePoint: http://support.microsoft.com/default.aspx?scid=kb;EN-US;2597150 where it it possible to modify the XSL tranformation timeout by using Powershell. This will fix the issue as the original timeout was hardcoded to 1 second. After installing the CU, you are able to do the following by using PowerShell:
 
 
$farm = Get-SPFarm 
$farm.XsltTransformTimeOut = 5 //timeout in seconds 
$farm.Update() 

How to Deploy changes to the web.config file as a feature for a SharePoint web application

I am currently working for a SharePoint hosting provider and as part of the general guidence, direct web.config changes are not allowed. Any change should be incorporated as a SharePoint feature, if you think about it, this is a good practice to get into.

Pros for deploying as features:
  • A solution repository can be maintained, which will make migration easy
     
  • Any future upgrades can lead to missing manual config changes
  • Fuctionality can be targeted to a web application or a sitec collection etc

Anyways, the post is about how to deploy changes to a web config via a feature.

*** Warning - Programatically modifying web.config changes are not very clean, so

Web config changes are specific to a web app, hence we will write and deploy a feature targetting a web app.

  1. Open visual studio and create a empty SharePoint project
  2. Add a new feature and set the Target to " Web Application"  (Make sure you name your Feature with an appropriate name)
  3. Double click on the Feature and in the Properties window, set the "Activate on Default" to false - We want to manually activate the feature per web application
     
  4. Add a Feature Receiver
  5. in the feature activated event, add the following code:


     public override void FeatureActivated(SPFeatureReceiverProperties properties)
            {
                try
                {
                   SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://mywebapp"));

                    SPWebConfigModification moduleModification = new SPWebConfigModification();
                    moduleModification.Path = "configuration/system.webServer/modules runAllManagedModulesForAllRequests=\"true\"";
                    moduleModification.Name = "add[@name=\"myHttpModule\"][@type=\"myHttpModule.myHttpModuleClassLib, myHttpModule\"]";
                    moduleModification.Sequence = 0;
                    moduleModification.Owner = "admin";
                    moduleModification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
                    moduleModification.Value = "<add name=\"
    myHttpModule\" type=\"myHttpModule.myHttpModule, myHttpModule\" />";
                    webApp.WebConfigModifications.Add(moduleModification);

                    webApp.Update();
                    //service.ApplyWebConfigModifications();
                    webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
                }
                catch (Exception ex)
                {
                    //Log exceptions in the Event Log
                    using (EventLog eventLog = new EventLog("Application"))
                    {
                        eventLog.Source = "myHttpModule";
                        eventLog.WriteEntry(string.Format("{0}: - {1} Error: \"{2}\" ", EventLogEntryType.Error, "myHttpModule- Feature Activating", ex.ToString() + Environment.NewLine + ex.StackTrace.ToString()), EventLogEntryType.Error);
                    }
                   
                    //Throw the exception for the admin
                    throw ex;
                }

            }
  6.   Add the following code to feature deactivating


     public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
            {
                try
                {
                    SPWebConfigModification configModFound = null;
                    SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://mywebapp"));
                    Collection<SPWebConfigModification> modsCollection = webApp.WebConfigModifications;
                    for (int i = 0; i < modsCollection.Count; i++)
                    {
                        if (modsCollection[i].Owner == "fu1adm" && modsCollection[i].Name == "add[@name=\"
    myHttpModule\"]")
                            configModFound = modsCollection[i];
                    }
                    if (configModFound != null)
                    {
                        modsCollection.Remove(configModFound);
                        webApp.Update();
                        webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
                    }
                }
                catch (Exception ex)
                {
                    //Log exceptions in the Event Log
                    EventLog eventLog = new EventLog("Application");
                    eventLog.WriteEntry(string.Format("{0}: - {1} Error: \"{2}\" ", EventLogEntryType.Error, "myHttpModule- Feature Deactivate", ex.ToString() + Environment.NewLine + ex.StackTrace.ToString()), EventLogEntryType.Error);
                    throw ex;
                }


            }
  7.  Build the solution and add it to the solution store
  8. Deploy the solution to the web app or globally
  9. In Central Admin > Click on the Application management > Manage web applications > Select the appropriate web application and click on Manage Features > Click on activate.
  10.  Make sure the web.config has been modified.

There are numerous reasons why web.config changes should be avoided via code. Microsoft has limited documentation on this

References:
http://msdn.microsoft.com/en-au/library/bb861909%28v=office.14%29.aspx