Monday, 25 November 2013

WebPart Page - SP2013


Creating a web part page in SharePoint 2013 is not like a SP2010. Few steps....

 Create a web part page by navigating to “Site Actions”->”Site Settings”



Select “Site Libraries and Lists” from “Site Administration” section



Select “Create new Content” from the page as shown below

                              

Select “Page” from the left panel, select “Web Part Page” option from the right pane and click “Create” button




On the web part creation page, provide page name, select the layout, the library to store the webpart page and click “Create” button.

 


Tip:
    Just enter the Url  http://[server_name]/_layouts/15/mcontent.aspx  
    [server_name] replace server name.


Friday, 27 September 2013

Open PDF documents in Browser Itself - SharePoint Document Library

         Open SharePoint 2010 documents library to open pdf documents in local drive, then how to open those pdf
in browser itself. Lets join a journey with me.................
  SharePoint UI                                 
  •  Central Admin.             
  •   Select WebApplication under Application Management.                      
  •    General Settings.
  •   Default Browser File Handling is Strict. Look like this
 

  •   Change the option Browser File Handling to Permissive.
  •     Perform iisreset and open pdf files in document library.       
    PowerShell

           Using powershell comment to set BrowserFileHandling property.

                Getting library from site.
                                       $web= Get-SPWeb -Identity “SiteUrl”
                                       $library= $web.Lists["LibraryName"]

                Check the BrowserFileHandling.
                            $library.BrowserFileHandling

                Set the value to Permissive
                           $library.BrowserFileHandling = "Permissive"
                           $library.Update()

  Perform iisreset and open pdf files in document library. 

  MIME Type:

            One more option is available to set MIME type, if the above techniques is went wrong,  go ahead this way.............
             
               Getting web application.
                             $curWebApp = Get-SPWebApplication "webappurl"    
  

                Add pdf in MIME type.   
                  $curWebApp.AllowedInlineDownloadedMimeTypes -contains "application/pdf"
                  $curWebApp.Update()

                 Check the PDF type.
                  $curWebApp.AllowedInlineDownloadedMimeTypes -contains "application/pdf"
                  Result : true

  Perform iisreset and open pdf files in document library. 

Thursday, 11 July 2013

Getting list of running services on SharePoint Farm

                   

 Using SharePoint Object Model  to get list of all running services

                Getting what are the services are running in the current SPFarm...........

using System;
using System.Web.UI;
using System.Collections.Generic;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

protected void Page_Load(object sender,EventArgs e)
{
try
            {            
              
                List<string> onLineService = new List<string>();
                List<string> offLineService = new List<string>();
                
               SPFarm farm = SPContext.Current.Site.WebApplication.Farm;             

              // Getting all services in the current Farm
                foreach (SPService service in farm.Services)                   
                {
                   // Getting all  running services using online
                    if (service.Status.Equals(SPObjectStatus.Online))
                    {
                        ListBoxOnLine.Items.Add(service.Name);
                        
                    }
                   // Getting all  running services using offline
                    else if (service.Status.Equals(SPObjectStatus.Offline))
                    {
                        ListBoxOffLine.Add(service.Name);
                    }
                }
            }
            catch (Exception)
            {                
                throw;

            }
}


Thursday, 18 April 2013

SharePoint 2010 List "Add new item" link control appear on the top of the page


SharePoint 2010  List "Add new item" link control  appear on the top of the page


Hi,
     SharePoint list has a large amount of list items, to add a new item  it take time to scroll down the page
     Avoid this try to add Add new item button in top of the page as follows......

     In a sharepoint list page to want to add a button in top                                                                              



 Add a Content Editor Web Part in the List Page

      => To edit the page in site action to add content editor webpart as ......


  => Add a new contents in the content editor web part as......

       Content editor webpart click "Click add new content" link it show the ribbon bar, click  Format text and  HTML to click Edit Html source as.....


 Add a code in the Edit Html Source

 To add piece of code in the edit html source as.....

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">

$(document).ready(function() {
    var mainTable = $("td.ms-addnew").parent().parent().parent().prev();
    var newTable = $("td.ms-addnew").parent().parent().parent();
    newTable.insertBefore(mainTable);
});
</script>




then click ok now add new item button look like this.............



Another Approach:

 sharepoint list page to click on edit page button and edit webpart as...........



To change Tool bar type as Show tool bar as.............

 Then the Tool bar look like this..........


Wednesday, 23 May 2012

Save User Inputs into the List using Client Side Object Model (Ecma Script)


      
 Save User Inputs into the List using Client Side Object Model (Ecma Script)
 

<script type="text/javascript">

     function callscript() {

        var currentuser = null;

        ExecuteOrDelayUntilScriptLoaded(addlist, "sp.js");

    }

    function addlist() {

//To get the User Inputs from Form..

        var Name = document.getElementById("Name");

        var mail = document.getElementById("Mail");

        var company = document.getElementById("Company");

        saveitem(Name.value, mail.value, company.value); 

    }

    function saveitem(cname, cmail, ccompany) { 

        var spcontext = null;

        var spweb = null;

        var splist = null;


      //To get Current context..

        spcontext = new SP.ClientContext.get_current();

        spweb = spcontext.get_web();


     //To get “Contact” list

        splist = spweb.get_lists().getByTitle("Contact");

        var listcreation = null;

        listcreation = new SP.ListItemCreationInformation();

        var items = null;


       //To add list creation information to list.

        items = splist.addItem(listcreation);


      //To set items to the List “Contact”

        items.set_item('Name', cname);

        items.set_item('Mail', cmail);

        items.set_item('Company', ccompany);

        items.update();

        spcontext.load(splist);

        spcontext.executeQueryAsync(success, fail);

    }

    function success() {

        alert('Data saved Successfully');

    }

    function fail(sender, args) {

        alert('error' + args.get_Message() + '\n' + args.get_stackTrace());

    }       

</script>


      <asp:Label ID="lblname" Text="Name" runat="server"></asp:Label> &nbsp;&nbsp
      <input type="text" id="Name" /><br /><br />   

       <asp:Label ID="lblmail" Text="Mail Id" runat="server"></asp:Label>& nbsp;&nbsp  
       <input type="text" id="Mail" /><br /><br />

        <asp:Label ID="lblcompany" Text="Company" runat="server"></asp:Label>& nbsp;&nbsp 
        <input type="text" id="Company" /><br /><br /> &nbsp;&nbsp;&nbsp;&nbsp;

      <input type="button" id="submit" value="Save" onclick="javascript:callscript();" />    


     ......................................................................................................................................................












Saturday, 19 May 2012

Client Side Object Model (Ecma) Script Overview


Client Side Object Model(CSOM) ECMA Script :

  SharePoint 2007 to access List Items or other objects from within a SharePoint environment the only choice available was to use the server object model, perhaps from the code behind in a web part or application page, or in a Service running on the SharePoint machine. Outside of a SharePoint environment, the only option was to use Web Services with all of the inherent limitations and inefficiencies.

SharePoint 2007 and don’t want to write the server side code then we call SharePoint Web Services.
Architecture:




  

Client Side Object Model has include Three object Model

Three Object Models:

1 .Net CLR

The .NET CLR version is used to create applications such as WinForms, Windows Presentation Foundation (WPF), and console applications, as well as PowerShell scripts

Microsoft.SharePoint.Client.dll   Microsoft.SharePoint.Client.Runtime.dll

2. Silverlight:

The Silverlight version works with both in-browser and out-of-browser Silverlight applications.

Microsoft.SharePoint.Client.Silverlight.dll,  Microsoft.SharePoint.Client.Silverlight.Runtime.dll

3. Javascript:

The JavaScript version enables your Ajax and jQuery code to call back to SharePoint

SP.js

  

Client Side Object  Model  Mechanism:



SharePoint Client Managed Object Model is a SharePoint API that runs on the client side. It converts the API calls made by the application, into XML request and sends it to the SharePoint server. On the server, the XML request is handled by a service called Client.svc where it translates the XML request in to appropriate Object Model calls (SharePoint Server Object Model) and gets the results. After getting the results, Client.svc translates them into JavaScript Object Notation (JSON) and sends back to the Client Managed Object Model. On the client side the JSON response is translated into ECMAScript objects for ECMAScript.


Advantages:

   1.Design client applications that access SharePoint content without installing code on the server that runs Microsoft SharePoint Foundation 2010.

 2.The SharePoint Foundation 2010 managed client object model lets you write client-side code to work with all the common objects in SharePoint sites. Through the object model, you can add and remove lists, add, update, and delete list items, change documents in document libraries, create sites, manage permissions of items, and add and remove Web Parts from a page.


Examples:

 1. A software company that sells a traditional rich client application wants to integrate SharePoint document libraries and lists into their application, and they want this integration to be seamless, or even invisible to their users.

2.A team leader creates a SharePoint site that has many lists that are required to manage her team’s mission. She wants to change these lists in an ad-hoc manner—perhaps updating assignments and estimates based on an Open XML spreadsheet, or moving items from one SharePoint list to another. She wants to write a small custom application to help her manage this.

Difference in Object Model Vs CSOM:

The bundling of multiple method calls into a single call to the server is dictated by the realities of network speed, network latency, and desired performance characteristics. If the SharePoint Foundation 2010 managed client object model interacted with the server at every method call, the performance of the system, and the increased network traffic would make the system unworkable.

As I mentioned, you explicitly control when the SharePoint Foundation 2010 managed client object model bundles method calls and sends a request to the server. As part of this process, before you start the interaction with the server, you must explicitly specify what content that you want to retrieve from the server. This is the biggest difference between the SharePoint Foundation 2010 managed client object model and the SharePoint Foundation 2010 object model.

Ecma Script Supporting Areas in Sharepoint:

*      Site Collections and Sites

*      Lists, List Items, Views, and List Schemas

*      Files and Folders

*      Web, List, and List Item Property Bags

*      Web Parts

*      Security

*      Content Types

*      Site Templates and Site Collection Operations