Posts

Showing posts with the label SharePoint

Backup-SPSite : You must specify a filename for the backup file.

I followed the backup instructions from  here  to backup my site collection but I encountered the following error: You must specify a filename for the backup file That was strange as I have set the -Path parameter. The resolution is that the path MUST BE VALID . In my case , I was missing an underscore.

SharePoint: Cannot file "Style%2520Library/Js/myfile.js"

I recent SharePoint deployment raised the interesting error about a missing file. When I checked the expected folder, the file was there so the error seemed a little strange. The solution is in the message: The missing file is Style %2520 Library. The cause was an incorrect link reference in the masterpage. The link was set to <SharePoint:ScriptLink Name="~SiteCollection/ Style%20Library /JS/myfile.js" runat="server" ID="ScriptLink2" /> SharePoint is url encoding the value. The encoded value of '%' is '%25', which results in the strange url. I removed the %20 from the link address and the issue was resolved.

SharePoint Online: How do I run a Javascript update with a lookup on a NewForm.aspx or EditForm.aspx?

The requirement I faced with my SharePoint online project was to update fields on the new and edit forms once an item had been selected. The main problem was that the update required a lookup to existing data for each item in a multi select box. The obvious solution was to use  PreSaveAction  in a Script Editor webpart, The script looked something like this: <script type="text/javascript" src="//code.jquery.com/jquery-1.11.2.min.js"></script>          <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices.min.js"></script> <script type="text/javascript"> var $j = jQuery.noConflict();  function PreSaveAction() {  function SetValue(onComplete) { // clear the target item $("textarea[id*='MyTargetField']").val(''); var listTitle = 'MyLookupList'; var ids = [];                 // get the items fr...

SharePoint: Urls in the virtual directories

While looking for the virtual location of the list of SharePoint masterpages (which is /_catalogs/masterpage/Forms/AllItems.aspx), I found  this  blog on MSDN outlining other useful folders. There post is replicated here. Site collection level recycle bin: /_layouts/15/AdminRecycleBin.aspx Site level recycle bin: /_layouts/RecycleBin.aspx Recreate default site sp groups: _layouts/15/permsetup.aspx Load document tab initial: ?InitialTabId=Ribbon.Document Delete user from Site collection (on-premises): /_layouts/15/people.aspx?MembershipGroupId=0 Display list in grid view. ‘True’ is case sensitive: ?ShowInGrid=True Quick Launch settings page: /_layouts/quiklnch.aspx Navigation Settings page: /_layouts/15/AreaNavigationSettings.aspx Sandboxed Solution Gallery: /_catalogs/solutions/Forms/AllItems.aspx Workflow history hidden list: /lists/Workflow History Filter toolbar for Lists and libraries: ?Filter=1 Site...

SharePoint Search: How do I limit a search query to a specific site collection?

The url needs to be as follows (as per this entry ): http://localhost/_api/search/query?querytext='test+path:"http://localhost/subsite/"' The C# code the create the querystring is as follows: string searchRestUrl = "/_api/search/query?querytext='" + text + "+%2b+path:\"" + HttpUtility.UrlEncode(SiteUrl) + "\"'&rowlimit=5"; where SiteUrl is the full url for my site.

Web API: Why am a getting a '500' error when accessing my REST endpoints for javascript?

For me, the solution was found by doing the following: 1. Add a 'Route' annotation above the endpoints    [Authorize]     public class MyAPIController : ApiController     {         [HttpPost]         [Route("api/MyAPI/MyPostEndPoint")]         public void MyPostEndPoint()        {        }        [HttpGet]        [Route("api/MyAPI/MyGetEndPoint")]        public void MyGetEndPoint()        {        }     } 2. When calling the endpoints from the js factory, my POST call we different to my GET command: function executeGet(url, success, failure) {             $http.get(url, {                 headers: { 'Authorization': 'Blah' }       ...

SharePoint: How can I improve the search relevance of a list item? (How do I use RecordPageClick?)

In order to improve the relevance of a list item, I learnt about RecordClick . Thankfully, I found the following code on Technet  to resolve the problem. I have duplicated it here. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Security; using System.Threading.Tasks; using Microsoft.SharePoint.Client; using Microsoft.SharePoint.Client.Search; using Microsoft.SharePoint.Client.Search.Query; using System.IO; namespace SPOnlinePageCallback2 {     class Program     {         static void Main(string[] args)         {             using (ClientContext clientContext = new ClientContext("https://xxxxxxx.sharepoint.com/"))             {                 SecureString passWord = new SecureString();                 foreach ...

SharePoint 2010: Create a folder in Javascript

Here is some simple Javascript to create a folder and a sub folder. CreateFolder($scope, // success function(){ CreateFolder2($scope) } ); function CreateFolder($scope, success){ var clientContext;     var oWebsite;     var oList;     var itemCreateInfo;     clientContext = new SP.ClientContext.get_current();     oWebsite = clientContext.get_web();     oList = oWebsite.get_lists().getByTitle("Report");     itemCreateInfo = new SP.ListItemCreationInformation();     itemCreateInfo.set_underlyingObjectType(SP.FileSystemObjectType.folder);     itemCreateInfo.set_leafName("Top Folder");     this.oListItem = oList.addItem(itemCreateInfo);     this.oListItem.update();     clientContext.load(this.oListItem);     clientContext.executeQueryAsync(         Function.createDelegate(this, successHandler),     ...

AngularJS: Why is my HTML not rendering correctly?

I was recently faced with the problem that my solution required HTML to be rendered. Not a problem - bind it with ng-bind-html and all is good. Or is it? This solution falls on its head when we have embedded 'syle' in the HTML. <div class="ExternalClass2F49307A49BF4FE3B48CB68350A1A9C6"><span style="color:rgb(0, 128, 0)">--My Sample Text in the RichText  Editor in SP2010--</span><div><br /></div> <div><br /></div></div> The solution is to used $sce ( Strict Contextual Escaping ) to format the output. Controller: $scope.trustAsHtml = function(string) {     return $sce.trustAsHtml(string); }; DOM/HTML: <div data-ng-bind-html="trustAsHtml(myHtmlString)"></div>

SharePoint: How do I create a link as a calculated column.

The 'secret' is to set the column type to NUMBER and then create a concatenated string of the anchor. For example, this would be a link to to my side passing in the ID of 1 to the query string The formula could look as follows: =CONCATENATE("<a"," href='","http://richardtestsite?ID=",[ID],"'>click here</a>")

SharePoint: Why does my email template look good in my SharePoint list and so bad in Outlook?

I have recently implemented a simple email solution as part of a project. The project required the emails subject and body to be configurable. That was easy - create a template list and extract the data where required. The problem is that the email body looks great in SharePoint, but less that spectacular in Outlook. I tried several options, including removing all DIVs and removing all of the extra 'goodness' that SharePoint injects. No luck. The solution was to write the html IN A SINGLE LINE. No line breaks. It seems that Outlook still picks up that information and that caused the rendering issue. So <table>  <tr>   <td>My Stuff</td>  </tr> </table> became <table><tr><td>My Stuff</td></tr></table>

SharePoint: How do I get the groups for the current user in Javascript or JQuery?

My current project requires me to identify the persona of the logged in user based on their membership of specific SharePoint groups. The first port of call is to extract all the groups for the current user and then work out what they can do. Sounds easy enough. I tried the following: function getUserGroups(success, failure) { var d = $.Deferred(); var ctx =  SP.ClientContext.get_current(); var collGroup = ctx.get_web().get_siteGroups(); ctx.load(collGroup);                 ctx.load(collGroup, 'Include(Users)'); var currentUser = ctx.get_web().get_currentUser(); ctx.load(currentUser); var o = { d: d, collGroup: collGroup, currentUser: currentUser }; function onQuerySucceeded() { this.d.resolve(this.collGroup); this.d.resolve(this.currentUser); var data = { "collGroup": this.collGroup, "currentUser": this.currentUser }; //return success(this.collGroup); ret...

SharePoint: Why is my WEBDAV connection so slow?

Image
Writing solutions using JQuery/Angular/Javascript is great. I use NotePad++ as my IDE and simply update the files on the SharePoint site directly. Using IE, I use the 'Open in Explorer' option in the ribbon and edit the files directly. However, the upload performance on my home PC really sucked. I was uploading a 500 bytes (yes bytes) a second. Painful. The solution was pretty simple; uncheck 'Automatically detect settings' in the LAN Settings .

SharePoint: The language is not supported on the server

My current requires nested sub webs to have a specific language/regional setting. The problem arose when I started changing the Regional Settings from English (US) to English (Australia). $web = Get-SPWeb $siteCollectionUrl $culture=[System.Globalization.CultureInfo]::CreateSpecificCulture("en-AU") $web.Locale=$culture $web.Update() OR       myWeb.Locale = System.Globalization.CultureInfo.CreateSpecificCulture("en-AU"); However, this started to cause problems when users started to create their nested webs. I was using the following C# code to create the webs: var newWeb = web.Webs.Add("Name","Title", "My Web", site.RootWeb.RegionalSettings.LocaleId , webTemplate, false, false); The locale I was referencing (3081) is not installed on the server - only the default 1033. It was trying to create new the site using the regional settings I had set previously. This was a bit of a problem: I need to create  the site and ens...

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({ ...

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.

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...