Posts

Showing posts with the label SharePoint

SharePoint 2013: Profile Pictures not showing in User Information List

Scenario: Refer to  this post for the scenario. Here there can be other reasons as well for example check out your my sites hosting location. There can be a situation that somebody in the past changed the location of My site as in my case it was changed 3 times. Resolution: If you are facing similar sort of problem then first you should verify the following: Are the profile picture uploaded in the first place? for that you may want to check inside Manage User Profile in User Profile Service Application.  Does the Profile picture appear on the my site of the user? Visit the user profile and also check out User Photos under my sites.  If the photos do exist in User Photos Library then perhaps you can  $web=Get-SPWeb "http://SharePoint/" $list= $web.SiteUserInfoList $user=$web.Ensureuser("User's display name") $listitem=$list.GetItemById($user.Id) $listitem["Picture"]="http://my/User Photos/Profilbilder/cellent_Name_MThumb.jpg...

SharePoint 2010: Error - Restore-SPSite : No content databases are available for this operation....

Image
While restoring Sites using power shell, once can come across such a kind of error as given below: "Restore-SPSite : No content databases are available for this operation but the site collection is scheduled for deletion in at least one content database.  Either wait for the deletion operation to complete or create a content database, and then try the operation again. To create a content database, click "Content databases" on the Application Management page, select the Web application to use, and then click "Add a content database". That actually means that a site is already  exist with this content database. To resolve this issue. Use the command 'Get-SPDeletedSite' to see all the marked sites that are scheduled for deletion. Delete the site collection that you think is hosting the above backed up content databa using Remove-SPDeletedSite  command. From Get-SPDeletedSite you get the SiteID which will be used in Remove-SPDeletedSite.  Ch...

SharePoint: Powershell scripts for reading, deleting and adding Groups from a Site Collection

Here are couple of Powershell scripts to play around with the SharePoint groups and users. Reading All the Users and Groups in a Site Collection $site = Get-SPSite "SiteCollection URL" $groups = $site.RootWeb.sitegroups foreach ($grp in $groups) {"Group: " + $grp.name; foreach ($user in $grp.users) {" " + $user.loginname + " "} } $site.Dispose() Adding Groups, Permission and Users to the respective groups to a Site Collection: Function AddSnapIn() { #handles exceptions caused by trying to add a snapin Trap [Exception] { continue; } #Check that the required snapins are available , use a comma delimited list. #example # ("Microsoft.SharePoint.PowerShell", "Microsoft.Office.Excel") $RequiredSnapIns = ("Microsoft.SharePoint.PowerShell"); ForEach ($SnapIn in $RequiredSnapIns) { if ( (Get-PSSnapin -Name $SnapIn -ErrorAction SilentlyContinue) -eq $null ) { Add-PsSnapin $SnapIn } else ...

SharePoint: Copy Folder and Files Recursively from Source to Destination Document library

Here is the code snippet that copies the entire content of a folder in from a source list/Document library to the destination FOlder in a source list/Document library. The Destination List can on other Site collection. This is server side code so it does not matter at long as appropriate permissions are in place the permission are elevated. Using this code an entire document library can also be copied to another one. So here goes the code: private void CopyFolderFilesRecursively(SPList objSourceList, SPFolder objSourceFolder, SPFolder objDestinationFolder) { SPListItemCollection objItems = ((SPDocumentLibrary)objSourceList).GetItemsInFolder(objSourceList.DefaultView, objSourceFolder); foreach (SPListItem objItem in objItems) { if (objItem.FileSystemObjectType == SPFileSystemObjectType.File) { byte[] fileBytes = objItem.File.OpenBinary(); string DestinationURL = strin...

SharePoint: Changing the URL of a Site Collection Using Powershell

To my understanding, there is no standard way of changing the URL of the SharePoint Site collection using UI or powershell. So what I normally do to change the URL of a Site Collection is to: Take the back of the site collection,  Delete the site collection  Restore the site collection from the backup to a new URL  So here are the commands that you need to execute in the SharePoint Management Shell to achieve the above objective: Backup-SPSite -Identity 'http://SiteCollectionURL' -Path 'E:\Backups\SieCollectionBackup.bak' -UseSqlSnapshot Remove-SPSite -Identity 'http://SiteCollectionURL' Restore-SPSite -Identity 'http://SiteCollection_NewURL' -Path 'E:\Backups\SieCollectionBackup.bak'

SharePoint 2010/2013: Modifying the Permission Level of a Group Using Powershell

Scenerio:  well I had a SharePoint group with around 50 users given Contribute permission. Then it was required to raise its permission to "Full Control". Here is how I did that using Powershell script: Adding a Permission Level $web = Get-SPWeb "http://SiteCollection" $group = $web.SiteGroups["GroupName"] roleAssignment= New-Object Microsoft.SharePoint.SPRoleAssignment($group) $role = $web.RoleDefinitions["PermissionLevel"] $roleAssignment.RoleDefinitionBindings.Add($role); $web.RoleAssignments.Add($roleAssignment) $web.Dispose() Removing a Permission Level $web = get-spweb "http://SiteCollection" $group = $web.SiteGroups["GroupName"] $roleAssignment = $group.ParentWeb.RoleAssignments.GetAssignmentByPrincipal($group) $role = $group.ParentWeb.RoleDefinitions["PermissionLevel"] $roleAssignment.RoleDefinitionBindings.Remove($role) $roleAssignment.Update() $group.Update() $web.Dispose() References https://...

SharePoint 2013 Apps: Get list of site collections using REST API

Image
Let me clear that it is not possible to fetch a list of site collection neither via REST nor by using JSOM. But there is a workaround i.e. by utilizing SharePoint Search Query REST/JSOM API. For that a basic search site collection should already be configured and crawled. Then in our code, we only need to specify the query contentclass:sts_site to return sites results. Following is the working code snippet that I used to achieve that: function GetAllSiteCollectionsInCurrentWebApp(currentUser) { var queryText = 'contentclass:sts_site'; var url = _spPageContextInfo.webAbsoluteUrl + "/_api/search/query?querytext='" + queryText + "'"; var executor = new SP.RequestExecutor(_spPageContextInfo.webAbsoluteUrl); executor.executeAsync({ url: url, method: "GET", headers: { "Accept": "application/json;odata=verbose" }, success: function (data) { //RetrieveSiteColl...

SharePont 2013: Configuring/Preparing Your SharePoint 2013 Dev Environment for (SharePoint Hosted) App Development

This blog post is not intended to give an A to Z instruction set on how to set up an SharePoint 2013 Environment for SharePoint hosted app development. Since there has been a lot written on this subject.  This post will simply point out the issues and direct the readers towards the right article that explain the solution to the problem.  Following is a brief summary on how to prepare you SharePoint 2013 farm for app development. If you try creating an app using Farm Admin account you will get the following error: "Error occurred in deployment step "Installed app for SharePoint": The System Account cannot perform this action". This error is well justified because if you are using your farm account to develop SharePoint 2013 apps, this is definitly going to kill the purpose of creating Apps on this amazing App Model which is there to replace the Sandbox Model.  Therefore you got to be a Normal Dev user and you got to be in a separate domain and ...

SharePoint 2010 / 2013: Colorizing the event in the SharePoint Calender

Image
Here in the following you can see the SharePoint 2013 calender in a week view. Now this raises many question such as how mulple users are persistantly attached to the calender and how the events are being colorized. Here my objective is to describe how the event are being colorized. If you have googled enough then you must have come across what Mike Smith  has to say on this issue. The "populateCalendarEventLinkIntercept" technique came from Mike Smith this technique handled all calendar view changes including day-week-month; previous/next. How he achieves this is by hooking his method into the existing SharePoint calendar load function. But this solution wont work in SharePoint 2013 since Mike calls the calender object using SP.UI.ApplicationPages.CalendarNotify.$4a which does not exist in SharePoint 2013. During Migration, overall I had a lot of troubles fixing this very solution since it was full of client side scripting specially JSOM but finally I did somethi...

SharePoint: Getting SPFIeldUserValue from SPUser and vice versa

Image
 SPFieldUserValueCollection AssignedTo = (SPFieldUserValueCollection)item["VB"];  SPUser vB = AssignedTo[0].User; Here is a simple trick to get a SPFieldUserValue from SPUser. For example, here I was working with a event receiver SPFieldUserValue strAttendee = new SPFieldUserValue(properties.Web, "-1;#" + properties.Web.CurrentUser.LoginName.ToString()); This trick come in very handy as SPFieldUserValue has a specific format that required a ID as well. Here instead of putting ID, we put -1 and let the system search the right ID for the User. Update 28/05/2014: Recently I was working on an event reciever on SharePoint 2013. I tried accessing  the value of a people picker field from AfterProperties inside item updating and item adding event which actually did not work since the claim based enocoding is somehow different from the one in SP2010. Following code snippet did the trick. Do this and this  for further information. public static SPUser GetUserOb...

SharePoint: Increasing sandbox/solution execution timeout using Powershell

Image
Poor sandbox solutions! They have been great comrad in time of chaos where deploying a farm solution would take months. But these little saviour have be deprecated . This means that the functionality will still be available for use in SharePoint 2013, but primarily for backwards compatibility with existing solutions built using the sandbox solution approach. First of all load the SharePoint powershell snap. To do that  we need to  run this command in the powershell command prompt just once.The command to load the SharePoint powershell snap in is as follows. Add-PSSnapin Microsoft.SharePoint.Powershell Then to check what is current status of the resource porting and time is: Write-Host $uc.ResourceMeasures["CPUExecutionTime"].AbsoluteLimit Write-Host $uc.ResourceMeasures["CPUExecutionTime"].ResourcesPerPoint Now run assign values to these attributes, run the following command: $uc=[Microsoft.SharePoint.Administration.SPUserCodeService]::Local $uc.Reso...

SharePoint 2010: Backup and Restore a List

SharePoint 2010, by all means, offers better ways to perfom Granular backups than it was done in MOSS. For example to take a back of a List Go to the Central Administration  Select Backup and Restore  Under Granular Backup select  "Export a site or list" option. Select the list/site that you want to backup and enter the path where you wnat your backup ".cmp" file,   The required path must point to a space in network drive. Therefore create a folder on a local drive and inside the properties of this folder, under Sharing, select "Share". This will give a network path to this folder.   You can select the addtion options such as  "export all security permissions on that list  and "Export Full Security",  Press "Start Export". This process will result in to a .cmp file which is actually the back up. Now to restore that we will use powershell command as given below: Import-SPWeb "http://Server/sites/SiteCollection...

SharePoint 2010: Creating Term store, term groups, terms programatically using CSV

With SharePoint 2010 Metadata Managment Services, come few frequently used terminologies such as Termstore, Termgroup, Termset and Terms which normally you create them all in this manner. Now without going into the detail of this jargon (because a lot has been written already) and touching the implementational aspect of it, the easiest way of creating a term store consitituing of respective terms, is by importing a CSV file.  Wictor Wilen  gives a very interesting account of how to create a CSV that can easily be imported to the Metadata management service. Not only that but he also hosts a Macros Enabled Excel Sheet which generates the right CSV upon entering the right data. Technically in SharePoint, whatever is doable using out of the box SharePoint features, can be achieved programatically using custom solution. Following this principlem  what I'm trying to achieve is to do the same thing programatically that we do out of the box i,e Creating a TermStore and a ...

SharePoint: Exporting a schema.xml file of a list from a SharePoint site

Image
Sometime we require to add a list definition to our SharePoint deployment package. That can be cumbersome since you need to know the type of fields and their respective attribute. It is easier if the list is made manually on the site and then the schema is exportable and used in the "List definition" code. So here is how we can achieve that: http : //Server/SiteCollection/_vti_bin/owssvr.dll?Cmd=ExportList&List={GUID} Update: For like more than a year now,  I am using SharePoint Manager 2010/2013 to achieve this very conveniently. Reference: http://sharepoint.stackexchange.com/questions/15152/how-can-i-export-a-schema-xml-file-for-a-list-from-a-sharepoint-site Vaqar Hyder E: vaqar.hyder3567@gmail.com A: Siebenbürgen Straße 2/1, Korntal-Münchingen, 70825, PK Hire me on Freelancer.com

SharePoint: Accessing List Items using ECMAScript

Image
Here is a simple, slim down with no frills attached code to access list item using ECMAscript in SharePoint 2010/13 . You can simply use this code in Content Editor Webpart and trigger this function using a HTML button or something and display the results in a HTML. Here I am trying to access all items under all the fields of the list. In the onSuccess function which executed in case the list items are accessed successfully, I further call another method that will make use of the function GetListItems() { try { setNewEventLinkURL(); objContext = new SP.ClientContext.get_current(); objWeb = objContext.get_web(); objList = objWeb.get_lists().getByTitle("My List"); objContext.load(objList); objContext.executeQueryAsync(Function.createDelegate(this, this.onSuccess), Function.createDelegate(this, this.onFail)); } catch (e) { } } function onSuccess(sender, args) { var TextFiled = ""; //var ListEnumerator =...

SharePoint: Error occurred in deployment step 'Activate Features': Cannot complete this action. Please try again.

Image
To one of my customs in my project, I added a new view in list Definition and that resulted in to the following error: Error    1    Error occurred in deployment step 'Activate Features': Cannot complete this action. Please try again. I came across this error a number of times and there can be a number of reasons causing such a sort of problem depending on the type of SharePoint features you are working on. But in my case most of the time the problem lies in the List definitions i.e. schema.xml. Thats how the containing feature is not correctly activated. Reason can be e.g. invalid GUID of the added view/fields creates problem or Falsly defined element in schema.xml. So to sort that out I changed the GUI of the newly added list view. I simply used "Creat GUID" tool inside visual studio to get a new GUID and replace this GUID with the already attached GUID of the list. This sorted out the problem. Hope this helps Cheers Vaqa...

SharePoint: Redirection to a desired page after adding a New item to a list

Image
Context  One of the requirements that we frequently come across setting a return address of the NewForm.aspx page. That precisely means that if you are about to add a new item to a list, first you press the link "Add New Item" (or some other way) and a newform.aspx appears as a pop up. Upon filling the required fields and pressing Save you are redirected to the same list (All item view.) The problem arises if we don't to be redirected to this view rather to some other page. For that reason here is the trick. Solution:  The URL to newform.aspx consists of two query strings i.e. "RootFolder" and "Source". Let leave Rootfolder for now and focus "Source" Setting the Source with your desired URL will redirect the user to this specific desired page that has been point in the Source. Remember that source requires a URL encoding. you can encode your URL using the following link http://www.url-encode-decode.com/ . So what I did is to place an an...

SharePoint 2010/2007: What to do when Jquery inside some CEWP messes up the Page/Removing a Bad WebPart

Image
Context: Let me put in this way. I made a custom webpage for a SharePpoint 2010 team site and placed a lot of webparts including a Content Editor webpart that comprised of JQuery and SPServices. Now something may have gone wrong with the jquery code as it is quite vulnerable and that really blocked my page. Solution: The only solution that I could think of at the point in time was to remove the content editor webpart altogether before situation escalates that means nipping the evil in the bud ;). so here was my page http://mysharepointserver/Custom%20Library/CalendarPage.aspx I simply added a query string i.e. Contents=1 so the URL is http://mysharepointserver/Custom%20Library/CalendarPage.aspx?Contents=1  This URL redirected me to a new page called "Web Part Maintenance Page" so here I had the chance to delete the web part that I did not want. Reference(s): https://www.nothingbutsharepoint.com/sites/eusp/Pages/Remove-a-Bad-Web-Part-in-SharePoint.aspx h...

SharePoint 2010: Programmatically wokring with Calculated, Lookup and Hyperlink fields

While working on event receivers in SharePoint 2010, I was required to access thelook up fields and calculated fields in from a list. So here is how I accessed the value of both the fields. SPFieldLookupValue fieldValue = new SPFieldLookupValue(properties.ListItem["ProjectsList"].ToString()); SPFieldCalculated cf = (SPFieldCalculated)properties.ListItem.Fields.GetField("Auslastung"); properties.ListItem["EventHeading"] = fieldValue.LookupValue + ":" + cf.GetFieldValueAsText(properties.ListItem["Auslastung"]); Where as in case you intent to set value for Hyperlink type field it has it own class that can be used in the following manner. SPFieldUrlValue teamURL = new SPFieldUrlValue(); teamURL.Description = "View Team Calendar"; teamURL.Url = properties.Web.Url.ToString() + "\\" + item.Url + "?groupID=" + groupID.ToString(); ; properties.ListItem["ViewTeamCalender"] = teamURL; As you could se...

SharePoint 2010/2007: Setting value of "Person or Group" Column Using SPService

Image
Context: Well I had a list called employees comprising of  two columns: i.e. Title (Single line of text) and  a Person or Group type column that is to be filled with the user. I was trying to fill this column with the current user. Solution  So here is the code that will aid in achieving just that. Click Me! There are number of aspect in this code that need to be addressed. First this is the format of the string that fill s the person or group type column. In normal cases, the item in Person or Group type column shows up in the following format: ID;#Domain\UserName. Here what I used: "-1;#"+loggedinUser So it means you don't need to find ID to form the aforementioned string, rather direct concatinating -1 to the username can do the magic. If somebody is totally unaware about how to use this code, I used content query webpart (out of the box webpart) to write this code. Update: well later I tried to make use of the same technique in the server side ...