Posts

Showing posts with the label SharePoint 2013

SharePoint 2010/2013 Powershell: Get SP User Properties of all the Site User or a Using Loginname

Image
Here is how you fetch  user properties/info using powershell. Normally to do that we use the following Powershell command but this required a SPUserPipeBind user identity which looks like this i:0#.w|domain\username Get-SPUser [[-Identity] ] -Web [-AssignmentCollection ] [-Group ] [-Limit ] But incase you dont have SPUserPipeBind you can use the following script. Now here comes the compelete script which took me couple of hours to build. For instance you are required to fetch all the users of the site along with their managers, following script is going to do the magic for you. What it does is to Fetch all the User of a specific site collection.   Loop through all the user and fetch each user's Manager  Using $web.EnsureUser fetches Manager's Display name since Login Name is not that user friendly.  At the end it takes all the users along with their respective Managers and sends them to a text file. Since the user names were in german in my case so t...

SharePoint 2010/2013: Deleting Specific Site Collections using Powershell

If you need to delete certain sites collection based on some criteria inside a specific web application then here are couple of simple powershell command which will aid you in doing just that using wild cards characters. Get-SPSite "http://de-oss-102:14435/Sites/00*" -Limit ALL Get-SPSite "http://de-oss-102:14435/Sites/00*" -Limit ALL | Remove-SPSite -Confirm:$false Reference: http://sharepoint.stackexchange.com/questions/111263/powershell-delete-remove-all-site-collection-under-a-spesific-managed-path

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