Thursday, 31 July 2014

Get all users using SharePoint Power Shell script


 


 [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null
    $site = new-object Microsoft.SharePoint.SPSite($SiteCollectionURL)
    $web = $site.openweb()
    $siteUsers = $web.SiteUsers

    foreach($user in $siteUsers)
    {      
        Write-Host " ------------------------------------- "
        Write-Host "Site Collection URL:", $SiteCollectionURL
        if($user.IsSiteAdmin -eq $true)
        {
            Write-Host "ADMIN: ", $user.LoginName
        }
        else
        {
            Write-Host "USER: ", $user.LoginName
        }
        Write-Host " ------------------------------------- "
    }  
    $web.Dispose()
    $site.Dispose()

Wednesday, 2 July 2014

Create SharePoint 2013 basic hosted application



  • A computer that is configured for app isolation with SharePoint 2013 installed on it. If you're using an Office 365 Developer Site, you already have a SharePoint 2013 environment that supports OAuth. SeeSign up for an Office 365 Developer Site for instructions on how to set up an Office 365 Developer Site. See Get started developing apps for SharePoint for guidance on how to set up a development environment that fits your needs.
  • Visual Studio 2012
  • Office Developer Tools for Visual Studio 2012

By using Office Developer Tools for Visual Studio 2012, you can create and deploy both SharePoint-hosted and ISV-hosted apps. A SharePoint-hosted app is the easiest to create and deploy because its contents are deployed to a single SharePoint site.
  1. Start Visual Studio 2012 by using the Run as administrator option.
  2. In Visual Studio 2012, on the File menu, choose New, and then choose New Project.
  3. In the New Project dialog box, expand the Visual C# node, expand the Office/SharePoint node, and then choose the Apps node. Choose App for SharePoint 2013.
  4. Name the project, and then choose the OK button.
  5. In the first Specify the App for SharePoint Settings dialog box, name your app and provide the URL of the SharePoint 2013 site that you want to use to debug your app. Under How do you want to host your app for SharePoint, choose SharePoint-hosted. Choose Finish.
  6. Open the AppManifest.xml file. Visual Studio 2012 displays the file in an editor that shows you the properties and values you'll assign to your app for SharePoint. In the Permission requests section, selectWeb from the list of permission scopes and Read from the list of permissions.
  7. Add a custom list to the project by using the following steps:
    1. In Solution Explorer, right-click the app project node to open the shortcut menu for the app for SharePoint, and then choose Add New Item.
    2. Expand the Office/SharePoint node under Visual C#.
    3. In the Templates pane, choose List, and then choose Add.
    4. In the Choose List Settings dialog box, name the new list TestCustomList, click the Create a customizable list based on radio button, select Default (Blank), and then click Finish.
  8. Add a host web menu item custom action to the project by using the following steps. This adds an Edit Control Block (ECB) custom action that launches your app for SharePoint to items in the Shared Documents library on the parent SharePoint site.
    1. In Solution Explorer, right-click the app project node to open the shortcut menu for the app for SharePoint, and then choose Add New Item.
    2. Expand the Office/SharePoint node.
    3. In the Templates pane, choose Menu Item Custom Action, type HelloWorldCustomAction in the Name field, and then click Add.
    4. In the Create Custom Action for Menu Item dialog box, select the Host Web radio button. Select List Instance in the Where is the custom action scoped to? drop-down box. Select Documents in the Which particular item is the custom action scoped to? drop-down box. Click Next.
    5. Keep the default options and click Finish.
  9. Add a ribbon custom action for the Shared Documents library by using the following steps.
    1. In Solution Explorer, right-click the app project node to open the shortcut menu for the app for SharePoint, and then choose Add New Item.
    2. Expand the Office/SharePoint node.
    3. In the Templates pane, choose Ribbon Custom Action, type HelloWorldRibbonCustomAction in the Name field, and then click Add.
    4. In the Create Custom Action for Ribbon dialog box, select the Host Web radio button. Select List Instance in the Where is the custom action scoped to? drop-down box. Select Documents in theWhich particular item is the custom action scoped to? drop-down box. Click Next.
    5. Keep the default options and click Finish.
  10. In Visual Studio 2012, on the Build menu, choose Deployyour app name.
    After the app is deployed, Visual Studio 2012 will launch the Site Contents page. Your app should appear in the list of apps on that page.

  1. Replace the contents of the Scripts\Apps.js file with the following JavaScript. This code retrieves a count of the number of lists on the current SPWeb object and the current user. It also populates elements in the Default.aspx file with the information that it retrieves.
    // Replace the following with your custom JavaScript. 
    var ctx;
    var web;
    var user;
    
    function sharePointReady() {
        ctx = new SP.ClientContext.get_current();
    
        $("#getListCount").click(function (event) {
            getWebProperties();
            event.preventDefault();
        });
        welcome();
    }
    
    
    function welcome() {
        web = ctx.get_web();
        user = web.get_currentUser();
        ctx.load(user);
    
        ctx.executeQueryAsync(onUserReqSuccess, onUserReqFail);
    }
    
    function onUserReqSuccess() {
        var welcomeText = document.getElementById("starter");
        var userWelcome = document.createElement("p");
        userWelcome.style.fontSize = "14pt";
        userWelcome.innerText = "Welcome " + user.get_loginName() + ".";
        welcomeText.appendChild(userWelcome);
    }
    
    function onUserReqFail(sender, args) {
        alert('Failed to find current user. ' + args.get_message());
    }
    
    
    function getWebProperties() {
        web = ctx.get_web();
        lists = this.web.get_lists();
        ctx.load(this.lists);
        ctx.executeQueryAsync(Function.createDelegate(this, this.onSuccess), Function.createDelegate(this, this.onFail));
    }
    
    function onSuccess(sender, args) {
        alert('Number of lists in web:' + this.lists.get_count());
    }
    
    function onFail(sender, args) {
        alert('failed to get list. Error:' + args.get_message());
    }
    
  2. In the Default.aspx file, inside the <PlaceHolderMain> tag, add the following HTML.
     
    <div>
       <button id="getListCount">Get count of lists in web</button>
    </div>
    <div id="starter">
    </div>
    
  3. You can display the contents of another webpage in an Iframe by adding the SharePoint:SPAppIFrame control to the Default.aspx file, as shown in the following code.
    <SharePoint:SPAppIFrame   ID="SPAppIFrame1" runat="server" Src="http://www.bing.com" Width="100%" Height="100%"></SharePoint:SPAppIFrame>
    
  4. You can add a list view that displays the contents of the custom list that you created by adding the WebPartPages:XsltListViewWebPart control to the Default.aspx file, as shown in the following code.
    <WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly" 
    ID="full" Title="loc:full" >
    <WebPartPages:XsltListViewWebPart ID="XsltListViewWebPart2" 
    runat="server" ListUrl="Lists/TestCustomList" IsIncluded="True" 
    NoDefaultStyle="TRUE" Title="TestCustomList" PageType="PAGE_NORMALVIEW" 
    Default="False" ViewContentTypeId="0x"> 
    </WebPartPages:XsltListViewWebPart>
    </WebPartPages:WebPartZone>
    
  5. Use the F5 key to deploy and run your app. Choose Trust It on the consent page to grant permissions to the app. When the app launches, you’ll see a page like the one shown in Figure 1. Click the Get count of lists in web button to see the number of lists that have been deployed to the appweb.

SharePoint 2013 Apps life cycle


Figure 1. Lifecycle for app for SharePoint development

Start, design, develop, and publish apps

Start developing apps for SharePoint

In Start, we tell you all the basics—about getting set up with Office 365 for developers, about the app model in general, and about discovering the technologies that you'll need to learn or those you might already know and can apply right away to your app for SharePoint development. We've provided links to deeper info, code samples, and how-to tasks to help you get started building great apps. If we succeeded with providing what you need to know in Start, you should have all the info you need to navigate the rest of the docs. If we didn't, we want to hear from you about where we can make the docs better! This set of docs is just a preview–we are constantly updating topics based on customer feedback and questions, offering new articles. 

Design apps for SharePoint

Let's say you have a killer idea for an app. In this section, we'll guide you through the design decisions you need to make and offer best practices to build your app. For example, what makes a good user interface? What are the app "shapes" available? When should I use one instead of another? What options do I have for data access? You get the picture.

Develop apps for SharePoint

Develop is the meat of the docs. We've got in-depth overviews, how-to articles, and code snippets to help explain all the different things you can do in an app for SharePoint. You'll find articles about performing CRUD operations on lists, how to build REST queries and interact with the new APIs, how and when to configure OAuth for security, and how to bring the richness of SharePoint into your app. SharePoint has enterprise social features like activity feeds and user profiles, along with enterprise content management features, LOB interoperability features, and website design features that can really make your apps stand out. Learn more about them in Add SharePoint 2013 capabilities.
And, code is key, so take a look at the "Samples" menu in the Dev Center. It's a direct link to our code samples for apps. As soon as you've set up your development environment, you should check out a few of our samples. Take advantage of a community feature that lets you request a code sample if we don't have one you'd like to see. We take those requests, along with other doc feedback and use them in our continuous updates to the content and samples. So please, let us know if you'd like to see something!

Publish apps for SharePoint

So now you've built your app, and you're ready to share it. Publish teaches you how to make your app available to your users. You can do this by publishing the app to one of two places:
  • The public Office Store. Publish your app to the Office Store to make the app publically available, so that it can be acquired by users of any SharePoint deployment.
  • An internal organization app catalog. Publish your apps to an internal organization app catalog, hosted on your SharePoint deployment, to make them available to users with access to that SharePoint deployment.