Posts

Showing posts from 2015

SharePoint: How do I get all the groups for the current user in Javascript and AngularJS?

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () { $scope.UserGroups = []; var clientContext = new SP.ClientContext.get_current(); this.collGroup = clientContext.get_web().get_siteGroups(); currentUser = clientContext.get_web().get_currentUser(); clientContext.load(collGroup); clientContext.load(collGroup, 'Include(Users)'); clientContext.load(currentUser); clientContext.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this, onQueryFailed)); function onQuerySucceeded() { var groupEnumerator = collGroup.getEnumerator(); while (groupEnumerator.moveNext()) { var oGroup = groupEnumerator.get_current(); var collUser = oGroup.get_users(); var userEnumerator = collUser.getEnumerator(); while (userEnumerator.moveNext()) { var oUser = userEnumerator.get_current(); if (oUser.get_loginName() == currentUser.get_loginName()) { $scope.UserGroups.push({ ...

AngularJS: Why does my module not render in my webpage?

I have been coding a simple Single Page Application solution using Angular JS running a in content editor web part in SharePoint 2010. I had the following code in my .aspx page: <div class="table-cell mainbody"> <div> <div id="first" ng-controller="Controller1" ng-include="src='/StyleLibrary/pages/first.Module.html'" > </div> <div id="second" ng-controller="Controller2" ng-include="src='/StyleLibrary/pages/second.Module.html'" > </div> </div> </div> However, when I ran $("#second") in my console window, I received an empty object. Hmmmmmm. It appears that that each module injection needs to be surrounded by its own DIV, so I change the code to the following to make it work: <div class="table-cell mainbody">  <div> <div id="first" ng-controller="Controller1" ng...

SharePoint: How do I get the location of the MySite url using PowerShell?

[void][reflection.assembly]::Loadwithpartialname("Microsoft.Office.Server"); [void][reflection.assembly]::Loadwithpartialname("Microsoft.Office.Server.UserProfiles"); [void][reflection.assembly]::Loadwithpartialname("System.Web"); [void][reflection.assembly]::Loadwithpartialname("Microsoft.SharePoint"); $mySiteUrl = "http://mysitecollection.com" $sc = Get-SPServiceContext($mySiteUrl) $upm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($sc) Write-Host $upm.MySiteHostUrl NOTE: If you encounter a 'Permission Denied' error, make sure that your user has 'Full Control' permissions on the User Profile Service.

SharePoint: How do I upload a file structure to a document library?

My current project uses a custom 'style library' document library. The deployment process needed to replicate the files and file structure from the disk in the target library. I used CSOM and Powershell to solve the problem. I created a 'Common' dll that contains the methods I needed: 1. CreateFolder (to create a folder structure) 2. UploadFile (to load the file).     public static class FileHelper     {         public static Folder CreateFolder(Web web, string listTitle, string fullFolderPath)         {             if (string.IsNullOrEmpty(fullFolderPath))                 throw new ArgumentNullException("fullFolderPath");             var list = web.Lists.GetByTitle(listTitle);             return CreateFolderInternal(web, list.RootFolder, fullFolderPath);         }...

JQuery DatePicker: How do I add a watermark?

A watermark is always a great way to provider a meaningful hint to a user. Using the JQuery DatePicker control, I wanted to tell the user the expected format of the date.  I added a new class called 'watermarkrequired' to the required html elements to help me identify them. I looked at several option: 1. Using the blur and focus events. $('.watermarkrequired').blur(function () { if ($(this).val().length == 0)    $(this).val(watermark).addClass('watermark'); }).focus(function () { if ($(this).val() == watermark)     $(this).val('').removeClass('watermark'); }).val(watermark).addClass('watermark'); 2. Using the 'AppendText' option of the DatePicker $( ".watermarkrequired" ).datepicker( "option", "appendText", "(yyyy-mm-dd)" ); Finally, I settled on the placeholder attribute $( ".watermarkrequired" ).attr("placeholder", "dd/mm/yyyy");

FAST Search: Failed to communicate with the WCF service

I was creating my managed properties to my FAST server (via FAST PowerShell) when I encountered this error Get-FASTSearchMetadataManagedProperty : Failed to communicate with the WCF service The resolution was pretty simple - I followed the steps in  this  link: 1. Add the user to the Windows group FASTSearchKeywordAdministrators 2. Log off the machine and log in again. 3. Problem resolved.

JQuery UI Dialog: Cannot call methods on dialog prior to initialization

My current project (using Angular JS on SharePoint 2010) requires a modal dialog window with some data passed between the different modules. We used dialog-service  from GitHub, which is a great utility for this purpose. All was great until I deployed the solution to a new environment. Suddently, my modal dialog stopped working and was complaining about 'initialization' issues. I stepped through the code and found that the initialization code was being called and  dialog.ref.is(':data(dialog)') was returning true. So what was different? To cut a long story short, the culprit was the Document ID Service (which was enabled on the new environment). It was appending text to the HTML, which was causing all the problems. Two solutions presented themselves: 1. Disable the feature (not likely) or 2. trim the appended text: if (html.indexOf('<html xmlns:') >= 0)    html = html.substring(0, html.indexOf('<html xmlns:')){ } I chose the lat...

Why are my accounts always locking/not authenticating when connecting to an old site in Windows 7?

I recently changed my password and found that all of my old connections were failing. And I was not being prompted to enter new credentials. Fortunately, the fix is pretty simple. Windows 7 has a Credential Manager (in the Control Panel) that stores all the saved information. I updated the relevant passwords and all was well with the world.

SharePoint 2010: How do I set the value multi select lookup column?

A seed data script I was writing required a multi value selection lookup column to be pre populated. Setting a single value is simple - use <Id>;#<Text> - and all is well. But how do you set multiple values? The solution is just as simple; use ;# as the delimiter between items. For example, you could set your column with the following: <ID1>;#<Text1>;#<ID2>;#<Text2> Semi-colon Hash (;#) is the delimiter of choice.

SharePoint 2010: How do I install SharePoint Server on Windows 7?

Once you have download SharePointServer.exe, you will need to extract the files from the executable. From the command prompt run: SharePointServer.exe /extract:c:\sp2010\ This will extract the installation files. Second, you need to 'enable' a Windows 7 installation. In order to do this, you will need to edit one of the configuration files. Navigate to C:\sw\sp2010\Files\Setup and add the following line to the bottom on the config.xml (before the closing Configuration tag). <Setting Id="AllowWindowsClientInstall" Value="True"/> You should be good to go IF YOU HAVE SQL SERVER 2008 R2. If you are running SQL Server 2012, you will need SharePoint Server 2010 SP1.

MVC 4: The required anti-forgery form field "__RequestVerificationToken" is not present

It seems the best things in life come in pairs: If you have a ValidateAntiForgeryToken annotation in your controller, you need to have a @Html.AntiForgeryToken() in your view.

Windows Server 2012: Why cant I install Windows Server 2012 RTM on a Virtual Box?

I encountered this problem today while setting up a SharePoint 2013 Development environment. The solution is to run a simple command: "C:\Program Files\Oracle\VirtualBox\VBoxManage" setextradata [vmname] VBoxInternal/CPUM/CMPXCHG16B 1 For example, my Virtual Box was called SP2013, so my command was: "C:\Program Files\Oracle\VirtualBox\VBoxManage" setextradata SP2013 VBoxInternal/CPUM/CMPXCHG16B 1

Why cant I add a new web application is my Windows 7 Sharepoint environment?

I recently installed a test environment on my Windows 7 laptop [using New-SPConfigurationDatabase] but I was unable to add a new Web Application. I created a new user, added it to the Local Administrators group. Two issues were apparent: A. I could not add a new Farm Administrator as 'I needed Local Administrator rights' [from the ULS] B. I could not create a new Web Application [due to security trimming] The solution lies in the OOTB Administrator account that is provisioned in the Windows 7 installation; it is deactivated by default. I activated the account and, presto, used its credentials to perform all the required activities.

Why cant I add a SharePoint project to Visual Studio 2013 Community Edition?

While configured my AWS development machine for SharePoint, I found that my 'SharePoint' options were missing when I tried to create a new project. Fortunately, all I had to do was download the Office Tools for Visual Studio 2013 from here

SharePoint 2013 Pre requisites install fail, Error: The tool was unable to install Application Server Role, Web Server (IIS) Role.

I was configuring a new development environment in Amazon Web Services and I encountered the following error message: SharePoint 2013 Pre requisites install fail, Error: The tool was unable to install Application Server Role, Web Server (IIS) Role. I tried several suggestions from Google, but to no avail. The problem was I was trying to solve an unsolvable problem. Huh? I was attempting to install  SharePoint Foundation 2013 on Windows Server 2012 R2 WHICH IS NOT SUPPORTED. I needed to install SharePoint Foundation 2013 SP1 .

How can I easily debug an email utility in SharePoint?

Image
Working with emails (especially in Timer Service jobs) can be a pain to debug. Fortunately, there are a few freely available utilities that make this chore very simple. I recently wrote a simple server that send numerous emails using the following code:                         var headers = new StringDictionary                         {                             {"from", web.Site.WebApplication.OutboundMailSenderAddress},                             {"to", user.Email},                             {"subject", subject},                             {"content-type", "text/html"}   ...

SharePoint 2013: What do the items in a claims token mean?

The code for 'All Authenticated Users' is c:0(.s|true. Its all very confusing - but everything is revealed  here

SharePoint 2013: How can I get a users SPPrincipal token?

In a SharePoint Claims authenticated environment, you need to extract the full claims token  (not just DOMAIN\Username). Here are two simple methods using the ResolvePrincipal  function to get the information: PowerShell: function GetUserPrincipalFromUsername($siteUrl, $login) { $web = Get-SPWeb $siteUrl $principal = [Microsoft.SharePoint.Utilities.SPUtility]::ResolvePrincipal($web, $login, [Microsoft.SharePoint.Utilities.SPPrincipalType]::All, [Microsoft.SharePoint.Utilities.SPPrincipalSource]::All, $null, $false) $web.Dispose() return $principal } C#: public SPPrincipalInfo GetUserPrincipalFromUsername(SPWeb web, string userName) {   return SPUtility.ResolvePrincipal(web, login, SPPrincipalType.All, SPPrincipalSource.All, null, false); }

SharePoint 2013: Error updating managed account credentials

I encountered the following message when trying to change a password for a managed account: Error deploying administration application pool credentials. Another deployment may be active. An object of the type Microsoft.SharePoint.Administration.SPAdminAppPoolCredentialDeploymentJobDefinition named "job-admin-apppool-change" already exists under the parent Microsoft.SharePoint.Administration.SPTimerService named "SPTimerV4".  Rename your object or delete the existing object. The error message is self explanatory - Rename your object or delete the existing object.  I choose the latter. Powershell to the rescue. $job = Get-SPTimerJob -Identity "job-admin-apppool-change" $job.Delete() Reset the password and all should be good.

SharePoint 2013: The sandboxed code execution request was refused because the Sandboxed Code Host Service was too busy to handle the request.

This was a nasty problem to resolve. I googled it and went through some basic steps: 1. follow the suggestions from msdn blog ( here ) 2. restart the windows service but no luck. I then restarted the SharePoint Service (Central Administration -> Settings -> Services on Server) and found that the password for my managed account had expired. I ran the powershell script  Set-SPManagedAccount  to correct the problem.

SharePoint: The contents of the feature’s solution requires the Solution Sandbox service to be running

In 'System Settings' -> 'Manage Services on Server', ensure that the service 'Microsoft SharePoint Foundation Sandboxed Code Service' is running. Open a new instance of PowerShell and you are good to go ...

ShaerPoint 2013: How do I change the picture (source) for an image at runtime?

An image can easily be converted into a 'clickable' image with some simple html manipulation - put the image in an anchor tag. I have added two images (First.ico and Second.ico) to the Style Library/images of my site collection. I also have jQuery referenced in my masterpage. Here is the html: <a href="" onclick="changeImage()"><img id="favourite" ></img></a> Changing the image is just as easy: First, lets set an initial source value: jQuery(window).load(function () {    $("#favourite").attr("src", "/Style%20Library/Images/First.ico"); }) Then, implement the changeImage function to switch images: function changeImage() { if ($("#favourite").attr("src") == "/Style%20Library/Images/First.ico") { $("#favourite").attr("src", "/Style%20Library/Images/Second.ico"); } else { $("#favourite").attr(...

SharePoint 2013: How do I reference a html 'source' file from another site collection in a Content Editor Web Part?

Content Editor Web Parts are fantastic for rendering content, but there is small problem if you want to reference a file (through a ContentLink) on another site collection - you are not allowed to! Cross-site scripting is not a good thing. This problem becomes apparent when you have a 'source' site collection that will host all the html/js files and you want all other site collections to reference this (single) source of truth. There are a few options available to resolve the problem. 1. Copy all the JS/Html files to each site collection and reference them locally. (Easy, but it will create a maintenance nightmare if you have lots of site collections). 2. Enable Anonymous access to the 'source' site collection. (Easy, but not a great solution) 3. Install  Content Link Web Part  from Codeplex. (Better, but requires a Farm Solution) 4. Move the link from the ContentLink to the Content in the webpart. The key to resolving the problem is nested CDATA tags. In my ...

Sharepoint 2013: Why is my deployed dll not in the GAC?

I have created a new SharePoint wsp and it has been successfully deployed, but when I searched for the compiled component in the GAC, it was nowhere to be seen. Huh? The simple solution is that the GAC is .net 1.0 - 3.5 is not the same as the GAC in .net 4.0+. The old GAC is the trusted location c:\windows\assembly The new GAC resides in c:\windows\microsoft.net\assembly It was there after all - it helps when you look for the file in the right place.

PowerShell: How do I open a reference without locking it?

I was recently writing a C# dll to the invoked in PowerShell. As I tested the PowerShell script, I found that the dll was being locked and any re-compiles from Visual Studio were being rejected. I used the following code to resolve the problem: $bytesCommon = [System.IO.File]::ReadAllBytes("c:\folder\driver.dll") $loadResultCommon = [System.Reflection.Assembly]::Load($bytesCommon)

PowerShell: How do I append data to an existing file in SharePoint with a new line and quotes?

A recent proejct required the injection of some runtime data in my require js configuration file. The following code allowed me to inject the new values into the file. $site = Get-SPSite "http://mysite" $file = $site.RootWeb.GetFile("/Style Library/myfile.js") if (($file -ne $null) -and ($file.Exists -eq $true)) { $binaryAsIs = $file.OpenBinary() $asciiEncoding = New-Object -TypeName System.Text.UTF8Encoding $asIs = $asciiEncoding.GetString($binaryAsIs)         # This is the text to append to the top.         # `r`n will create a crlf (new line)         # $([char]34) will embed a double quote in the text $new = "// Here is some next text `r`n //and here is text in $([char]34)quotes([char]34)`r`n" $newFile = $new + $asIs $binaryToBe = $asciiEncoding.GetBytes($newFile) $file.CheckOut() $file.SaveBinary($binaryToBe) $file.CheckIn("") $file.Publish("") } $site.Dispose()

SQL Server Express: How do I create an alias for my instance?

Here is a fantastic article that outlines the steps involved. Awesomeness lives here

Powershell: Recusively Check In and Publish files in a SharePoint Document Library

I have combined the scripts from Paul King ( here ) and Brijendra Gautam ( here ) to create my own version of the script. Function CheckInAndPublishFolderItemsRecusively( [Microsoft.SharePoint.SPFolder] $folder ) {     # Create query object     $query = New-Object Microsoft.SharePoint.SPQuery     $query.Folder = $folder     # Get SPWeb object     $web = $folder.ParentWeb     # Get SPList     $list = $web.Lists[$folder.ParentListId]     # Get a collection of items in the specified $folder     $itemCollection = $list.GetItems($query)     # Iterate through each item in the $folder     foreach ($item in $itemCollection)     {         # If the item is a folder         if ($item.Folder -ne $null)         {             # Call the Get-Items function recursively for ...

SharePoint Online: How do I extract list changes with PowerShell?

Import-Module 'C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell' -DisableNameChecking $loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") $loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") $webUrl = "https://mysite.sharepoint.com/" $username = "richard.leeman@mydomain.onmicrosoft.com" $password = Read-Host -Prompt "Password for $username" -AsSecureString $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl) $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password) $web = $ctx.Web $webs = $web.Webs $lists = $web.Lists $ctx.Load($lists) $ctx.Load($webs) $ctx.Load($web) $ctx.ExecuteQuery() $list = $lists| Where-Object { $_.Title -eq "My Documents"} $dt = Get-Date $dtUTC = $dt.ToUniversalTime() $changeQ...

SharePoint Online: How do I configure the Site Collection Audit Settings from CSOM?

My current project requires that the Site Collection Audit Settings be provisioned with every new OneDrive for Business site. The problem is that there is not existing API (in CSOM or PowerShell) to set these values. Problem? Yes. Insurmountable? No. I was pointed in the direction of this  fantastic blog. The basic idea behind the code is to replicate the 'POST' event that is created by using the UI. The code is magnificent but (as is continually stressed in the video) is not supported by Microsoft.  This does not mean that is will not work, it just means that should the name of the underlying fields change, the code will fail unceremoniously. Anyway, back to the solution.  Firstly, enable the 'Reporting' Site Collection feature. The feature Guid is "7094bd89-2cfe-490a-8c7e-fbace37b4a34" and should be activated as a FARM level feature Secondly, here is my add-in code to the set values. using System.Globalization; namespace Contoso.Remote...