Thursday, 29 August 2013

Visual Studio 2012: No exports were found that match the constraint contact name

To fix this problem, simply clear/detete/rename %AppData%\..\Local\Microsoft\VisualStudio\11.0\ComponentModelCache

Prevent field validators from firing when editing a web part

I have a simple visual web part with a RequiredFieldValidator. The only problem is that when the web part properties are set, a postback is fired and the validator is complaining. The net result is that I cannot make any configuration changes to the web part.

The following code will resolve this problem:

    protected override void OnPreRender(EventArgs e)
            WebPartManager mgr = WebPartManager.GetCurrentWebPartManager(Page);
            if (mgr.DisplayMode.Equals(mgr.SupportedDisplayModes["Browse"]))
                myValidator.Enabled = true;
                myValidator.Enabled = false;


Monday, 26 August 2013

SharePoint Designer Web Cache

The web cache for SharePoint Designer sometimes causes problems and needs to be cleared. I was having this problem when adding a custom workflow activity (see here for the blog I used).

I found this blog (here) with the following script to clear the cache. It certainly saved me a lot of pain.

cd "%APPDATA%\Microsoft\Web Server Extensions\Cache"
del *.web /S /Q "%APPDATA%\Microsoft\Web Server Extensions\Cache"
cd "%USERPROFILE%\AppData\Local\Microsoft\WebsiteCache\"
rmdir /S /Q "%USERPROFILE%\AppData\Local\Microsoft\WebsiteCache\."
mkdir "%USERPROFILE%\AppData\Local\Microsoft\WebsiteCache"
dir "%APPDATA%\Microsoft\Web Server Extensions\Cache"
dir "%USERPROFILE%\AppData\Local\Microsoft\WebsiteCache"

Friday, 23 August 2013

Powershell does not resolve dynamic variables

I have been working diligently on a script to create Sharepoint groups in Powershell. It sounds easy enough until you have to create iterated allocations. For example, a group needs to be allocated permissions to multiple lists. This is where the fun starts:

My code was as follows:
For($i=0; $i -lt $scopes.Length; $i++) {
if (($scopes[$i] -ne $null) -and ($scopes[$i] -ne ""))
$list = $web.Lists["$scopes[$i]"]

if ($list.HasUniqueRoleAssignments -eq $false)



It compiles and runs, but I was getting a lot of error messages about unassigned variables in the RoleAssignment addition. Very frustrating.

The problem was traced to $list = $web.Lists["$scopes[$i]"]
Powershell will not resolve the 'inner" variable, which cause the lookup to return a null value.

The solution was simple. Put the value in a variable and use the variable.
$name = $scopes[$i]
$list = $web.Lists["$name"]

I wish I had thought of that 2 hours ago.

Thursday, 22 August 2013

SharePoint 2013: UserAgent not available, file operations may not be optimized

I encountered this problem after creating a new document library 'App'. After a little searching, I found the following code to flush the BLOB cache  to resolve the problem.

$webApp = Get-SPWebApplication ""

Wednesday, 21 August 2013

Find the field type enumerator for a Sharepoint field type in Powershell

I have been trying to add a new field to an SPWeb. It sounds simple enough, but it ended up being a little tricky. The problem came from the 'FieldType' column.

After a little research, I found that the easiest way is to use the corresponding Integer from the FieldType enumerator (see here for more details).

I ended up with the following code that returns the corresponding enumerator for the '$fieldType'. For example, '$fieldType = Integer' returns 1.

$int = [Convert]::ToInt32(( [Microsoft.SharePoint.SPFieldType]::GetValues([Microsoft.SharePoint.SPFieldType]) | Where-Object  { $_ -eq $fieldType }))

I can now add fields the easy way.

$web.Fields.Add("FieldName", $int, $CanIBeNullableOrNot)

Find the location of Central Admin in Sharepoint using Powershell

My current project requires creating a Taxonomy through the Metadata Service. The starting point for all this work is finding out where Central Administration lives.

The following code will return the WebApplication details:

$centralAdminWebApp = Get-SPWebApplication -includecentraladministration | where {$_.IsAdministrationWebApplication}

Tuesday, 20 August 2013

You cannot customize permission levels in a web site with inherited permission levels

The resolution to the problem is in the error message - the SPWeb has inherited permission levels that need to be overridden.

The following code will solve the problem.

if (!web.IsRootWeb && !web.HasUniqueRoleDefinitions)
  web.RoleDefinitions.BreakInheritance(true, false);