Posts

SharePoint PowerShell: Upload multiple documents to sharepoint document library

Image
Hi, I was creating a script to replicate document library structure similar to Prod just in order to test the ShareGate Migration. Let me take a brief description about my scenario: Description: There is a document library present on Prod, which contains bulk document (~3000). Now I need to update metadata for all those documents using Excel sheet and ShareGate. I don't have access to the Production library and not even replicate the Library to my Dev environment as it contains some very confidential documents. Solution: I have decided to create a script which will take one template document from file system and read name of document from one of columns of excel. The script will take some time(~hours in case of thousand documents) to upload the template with the new file name. The inputs to the script will be Path of the excel which contains name of documents in one column Path of the file where the template is placed on file system Url of the sharepoint web site Name of th...

Upload a file in SharePoint using REST and c# console application

Image
Hi, In my last post , I have explained how to create a sub site using REST from and Console application. In this blog  will explain how we can upload a file, which is located in file system, will be uploaded to sharepoint Document library. So if I brief about requirement here: Need to upload a file to already created SharePoint site. Use REST(not even CSOM) will be used in order to create. API call will be send from some other machine(not SharePoint machine) which is in same domain and can access the SharePoint site. Follow the given steps to achieve the same: 1) Create a simple console application with c# selected language. 2) Next is to install the Newtonsoft.Json. Navigate to Visual studio menu: "View" > "Other Windows" > "Package Manager Console" and Then type the following: "Install-Package Newtonsoft.Json" 3) Now install RestSharp using the package manager. Type the following: "Install-Package RestSharp" 4) Now open th...

Get SharePoint search results using REST ajax call from Html

Image
Hi, We all aware the SharePoint exposed REST Api in order to perform various action at client side. There are some other ways also which a developer can adopt instead of REST(like CSOM) but that requires again client context. So it is recommenced that if we are using SharePoint Apps then use CSOM to get and update the data. Where as REST can be used in apps as well as some external applications. This blog is intended to show how user can utilize the REST api and get the SharePoint Search results. There are few pre-requisites or conditions which must be fulfilled before proceeding further. The machine where this code will be executed must have access to sharepoint site which means machine must be either in same domain or cross domain accessibility is there. Search must be configured at SharePoint server. Data must be properly crawled and you must get some results when searched for some keyword. Steps: 1) Open the Explorer or any desired location and create a text file with ant des...

Create Sub Site in SharePoint using REST and c# console application

Image
Hi, Recently, I got an requirement to create a SharePoint sub site from the some .Net application which is hosted somewhere hosted outside the SharePoint environment. It is provided that the .Net application can be added in same domain. So if I brief about requirement here: Need to create a sub site in SharePoint site collection based on some default template(later on custom template) Use REST(not even CSOM) will be used in order to create. API call will be send from some other machine(not SharePoint machine) which is in same domain and can access the SharePoint site. There are few challenges which I faces if we try to work with such kind of requirements. The authentication tokens and RequestDigest data are the crucial things to retrieve. I have explored some way to execute REST API and create a sub site without navigating to SharePoint site. Follow the given steps to achieve the same: 1) Create a simple console application with c# selected language. 2) Next is to install the New...

Enable SP.JS in publishing sites for SP 2013

Hi, In my previous post , I have explained the way to add CSOM on master page of any kind of site. But later on when testing same code with publishing site, I realized that sp.js is not loaded on publishing site by default. So in this post I will discuss how to enable sp.js in Publishing Pages in SharePoint 2013. As the SharePoint uses minimal download strategy it prevents the page to have sp.js when published but the point to note is when you open your ribbon bar (edit or unpublished state) sp.js  script gets loaded in your page . Note : SharePoint loads scripts on Demand So to solve this we can do like this : Add a script editor webpart in your page and in script tags just add the following code snippet: SP.SOD.executeFunc('sp.js', 'SP.ClientContext', alert('I have loaded the sp.js script.')); Where instead of alert method you can use any JS method and will be executed after sp.js is loaded. Happy SharePointing :).

SharePoint CSOM for beginners: Get Current User details

Image
Hi Guys, This blog is targeted to developers who are novice to the client side object model in SharePoint. SharePoint apps by default provides a basic stub for getting user details inside app. But sometimes it is required to add client side code in simple script file to get user information. I hope this information will also be helpful starters of client side object model. Pre-requisites: 1) Any version of SharePoint installed: SP 2013, SP 2010 or SP Online 2) A web application and a root site collection inside it. It does not matter whether site is team site or any other type of site.(Note: In case of publishing site you need to enable sp.js file loading ). 3) SharePoint Designer installed. Step I : Create a custom script file A script file is required in order to place CSOM code to be executed. Well, here depending upon usability user can chooses any one of these two locations to create this file: - List or Style library : It will be hard to update script file if it is placed under s...

SharePoint get followed sites using REST Api

Image
Recently I was tasked with a project requirement that the user should be able to see list of content he/she followed. To me this sounds much like using the following feature of SharePoint 2013 which allows you to follow documents, sites, people and tags. Also, we don’t want the user to navigate to his/her mySite and have a look on to the content followed. We can use the SharePoint 2013 Representational State Transfer (REST) service to do the same tasks you can do when you use the .NetCSOM, JSOM. Here I explain how to retrieve the site name and URL followed by the current user in SharePoint 2013 using a client object model (REST API and JavaScript) and displaying it in the SharePoint page. 1. Create a new page and a Content Editor Webpart (CEWP). 2. Edit the web part that was added to the page. 3. Upload your text file script into the site assests and copy the path of the text file and paste it into the Content link in CEWP. 4. Output Code The following example shows how to retrieve a...