Thursday, 29 January 2015

Configure audit settings for a site collection

You can use the audit feature of Microsoft SharePoint Server 2013 to track which users have taken what actions on the sites, content types, lists, libraries, list items, and library files within your site collections. Knowing who has done what with which information is critical for many business requirements, such as regulatory compliance and records management.














You manage the size of the audit log in the Audit Log Trimming section and specify which events to audit in the Documents and Items and Lists, Libraries, and Sites sections. You can also specify the maximum number of days that items will be retained. By default all items are removed at the end of the month. NOTE When multiple users are co‐editing a document, auditing events from multiple authors or editors can be difficult to interpret. If this is a concern, consider limiting editing permission to a minimum number of users. As a site collection administrator, you can retrieve the history of actions taken by a particular user and can also retrieve the history of actions taken during a particular date range. For example, you can determine which users edited a specific document and when they did this. 

Configure audit log report trimming
1. Select Settings > Site settings.

2. If you are not at the root of your site collection, under Site Collection Administration, select Go to top level site settings. NOTE The Site Collection Administration section will not be available if you do not have the necessary permissions.

3. On the Site Settings page, under Site Collection Administration, select Site collection audit settings.

4. On the Configure Audit Settings page, in the Audit Log Trimming section, set Automatically trim the audit log for this site? to Yes.

5. Optionally, specify the number of days of audit log data to retain. NOTE We recommend that you do not set this option unless business needs dictate otherwise. If this option
is not set, it will use the Farm setting, which removes items that are more than 30 days old at the end of the month by default. A business need could be that your organization has a requirement to maintain your audit log in a non‐archived format for a different time period. The archived format is the audit log report.

6. You can also specify the document library to save audit reports to before the audit log is trimmed. Set this option if you need access to audit log data, using audit log reports, after the audit log has been trimmed.

7. Select OK.

Configure events to audit
1. Select Settings > Site settings.
2. If you are not at the root of your site collection, under Site Collection Administration, select Go to top level
site settings.
NOTE The Site Collection Administration section will not be available if you do not have the necessary
permissions.
3. On the Site Settings page, under Site Collection Administration, select Site collection audit settings.
4. On the Configure Audit Settings page, in the Documents and Items and List, Libraries, and Site sections,
select the events you want to audit, and then select OK.
Which events you audit depends on your auditing needs. For example, regulatory compliance usually has specific
requirements that will dictate which events you need to audit. We recommend that you only audit the events
required to meet your needs. Additional unnecessary auditing can affect the performance and other aspects of your
site collection﴾s﴿.
IMPORTANT We recommend that you only select Opening or downloading documents, viewing items in lists,
or viewing item properties for SharePoint Server 2013 sites when absolutely necessary. This option is likely to
generate a large number of events that will potentially degrading the performance and other aspects of your site
collection﴾s﴿.


What shows up in the audit log report ?
The events that you select to audit are captured in audit reports that are based on Microsoft Excel 2013 and are available from the Auditing Reports page. You can also create a custom report that includes a number of these events over a specified date range, within a specific area of the site collection, or filtered to an individual user. You cannot modify events once they are logged, but site collection administrators can delete items from the audit log and configure automatic trimming of the audit log data. The audit log captures the following information for the events that are selected to be audited. Site from which an event originated Item ID, type, name, and location User ID associated with the event Event type, date, time, and source Action taken on the item Following is an example of the data in a Deletion audit log report. With this report, you can determine who deleted and restored data across the site collection. You can use the features of Excel to filter, sort, and analyze the data.

Trimming the audit log reports. When you select an event to be audited for a site collection, such as delete and restore, it will be audited for every item in the site collection each time the event occurs. Auditing can potentially generate a large number of audit events, creating a large audit log. This could fill the hard drive, affecting performance and other aspects of a site collection.
IMPORTANT To prevent the audit log from filling the hard drive and potentially degrading the performance of the site collection, we recommended that you enable audit log trimming for site collections with extensive auditing. To manage the size of the audit log report you can configure it to automatically trim and optionally archive the current audit log data in a document library before the data is trimmed. The schedule for audit log trimming is configured by your server administrator in Central Administration. The default is the end of the month.






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.

Thursday, 30 January 2014

Why it is Important to Dispose of Objects


Unlike the majority of the objects in the .NET Framework, Objects handles are not automatically disposed when your application no longer holds a reference to them. This, as you may have already guessed, can lead to memory allocations that are never released. Over time (application up-time), this could lead to large consumption of memory usage and ultimately an "Out of Memory" exception.
There is however another consideration, which given the vast amounts of RAM computers use as standard, is probably going to be of greater concern - especially if you’re doing a fair amount of custom drawing.

Windows has a limit on the number of Objects handles that a session (i.e., application) is permitted to hold. This value is determined in the system registry, and by default, is set to 10,000 handles (at least this is the case in XP, Vista and 7). This value can be altered by those of you comfortable editing the registry but the maximum that can be applied is 65,536 (Windows 2000 is 16,384).

How to Dispose of These Objects
Disposing of these Objects can be as simple as a call to the Dispose method of the object as follows:
http://www.codeproject.com/images/minus.gif Collapse | Copy Code
Bitmap bitmap = new Bitmap("mypic.bmp");
bitmap.Dispose();
The important thing to remember here is that once you have called the Dispose function, you should not try to access any of the other properties or methods of the disposed object as this will cause an exception. For example, the following would cause you problems:
http://www.codeproject.com/images/minus.gif Collapse | Copy Code
Bitmap bitmap = new Bitmap("mypic.bmp");
bitmap.Dispose();
bitmap.Save("mypic.bmp");
When to Dispose of These Objects
As you can see, it is simple enough to dispose of the object, but the more important question is, when to dispose of it. Well, this of course depends on how and where you declare and use the objects. Consider the following code sample:
http://www.codeproject.com/images/minus.gif Collapse | Copy Code
void EditPhoto(string filename)
{
         Bitmap bitmap = new Bitmap(filename);
         //do some image manipulation here
         bitmap.Save(filename);
         bitmap.Dispose();
}

Tuesday, 14 January 2014

Document set permissions using power shell script

 $web = Get-SPWeb "http://c4968397007"

 $listName="Employee"

 $groupOne="Engineers"
 $groupTwo="Managers"
 $groupThree="Developers"

 $setOne="EngineersSet"
 $setTwo="ManagersSet"
 $setThree="DevelopersSet"


function GrantGroupPermission($groupName)
{

if($web.SiteGroups[$groupName] -eq $null)
{
 $web.SiteGroups.Add($groupName,$web.Site.Owner, "Use this group to grant people

    Full Control permissions to the $web site")
}

    $PAGroup = $web.SiteGroups[$groupName]
    $sproleass = new-object Microsoft.SharePoint.SPRoleAssignment($PAGroup)

   

    $folder.BreakRoleInheritance("true")
    $sproleass.RoleDefinitionBindings.Add($web.RoleDefinitions["Read"])
    $folder.RoleAssignments.Remove("")
    $web.Update()
    $folder.RoleAssignments.Add($sproleass)
    $web.Update()
   

}

    $doclib=[Microsoft.SharePoint.SPDocumentLibrary]$web.Lists[$listName]
    $foldercoll=$doclib.Folders;


foreach($folder in $foldercoll)
{
     if($folder.Name.Equals($setOne))
     {
        GrantGroupPermission($groupOne)
     }

     if($folder.Name.Equals($setTwo))
     {
        GrantGroupPermission($groupTwo)
     }

     if($folder.Name.Equals($setThree))
     {
        GrantGroupPermission($groupThree)
     }
}




$web.Update()
$web.Dispose()

Tuesday, 24 December 2013

Pie charts using JQuery

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
   
</head>
<body>
    <div id="piechart_3d" style="width: 900px; height: 500px;">
    <script type="text/javascript">      
         google.load("visualization", "1", {packages:["corechart"]});      
         google.setOnLoadCallback(drawChart);      
         function drawChart() {
         var Consumed = 5400;
         var PlannedAvailable = 200;
         var Unplanned = 400;      
         var data = google.visualization.arrayToDataTable([    
         ['Hours', 'Hours per Day'],          
         ['Consumed',      Consumed],          
         ['Planned Available',  PlannedAvailable],          
         ['Unplanned', Unplanned]        
         ]);        
         var options = {          
         title: 'Project Hours',          
         is3D: true,        
         };        
         var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));        
         chart.draw(data, options);      
         }    
    </script>
    </div>
</body>
</html>