Tuesday, 17 September 2013

Sharepoint 2010 Webpart Options


Sharepoint 2010 Out of box Webpart Options

When you add a Web Part from the List and Libraries category (that basically shows you every List and Document Library you have on the SharePoint site) behind the scenes the Data View Web Part is being used to display the List or Document Library data.


When you edit such a Web Part once it has been added to a page, you’ll notice there is a new AJAX Options section in the Web Part properties. The AJAX Options are disabled by default, but by enabling you can get some pretty cool results:





  • Enable Asynchronous Update: enabling this option will make paging, sorting, filtering work without full page refreshes.
  • Show Manual Refresh Button: enabling this option will show an icon to allow the user the refresh the data manually, once again without refreshing the rest of the page.
  • Enable Asynchronous Automatic Refresh: when enabled, the Web Part will dynamically refresh the date it’s showing, without completely reloading the page. The interval can be specified in the textbox below.
  • Automatic Refreshing Interval: specifies the interval used in the previous option.
  • Enable Asynchronous Load: when enabled, the Web Part will initially be displayed without any data in it. But once the page is loaded, the Web Part will asynchronously fetch the data afterwards. When the data is being loaded, the Web Part will display an animation. This option will speed up the initial page load.
  • using of Ajax with webservices for SharePoint data.




    $(document).ready(function() {
    var webserviceurl =  "https://mysiteurl/_vti_bin/lists.asmx";
        var soapEnv =
            "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
                <soapenv:Body> \
                    <GetListCollection xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                    </GetListCollection> \
                </soapenv:Body> \
            </soapenv:Envelope>";

        $.ajax({
            url: webserviceurl ,
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            complete: processResult,
            contentType: "text/xml; charset=\"utf-8\""
        });
    function processResult(xData, status) {
    var res = '';
    //alert(xData.responseText)
        $(xData.responseXML).find("List").each(function() {
         res +=   $(this).attr("Title")+'\n';
        });
    //returns all list in the current site.
    alert(res );
    }



    });

    Thursday, 12 September 2013

    Power Shell Script to copy a File to all sub webs to the Folder location:


     cls

    if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null)
    {
    Add-PSSnapin Microsoft.SharePoint.PowerShell;
    }
    get-PSSnapin Microsoft.SharePoint.PowerShell

    Start-SPAssignment -Global
    #-------------------------------------------

    #static parameters
    $site = Get-SPSite "http://sp2013:90/sites/test/"

    $Web = Get-SPWeb "http://sp2013:90/sites/test/"

    $Sourcefile = $Web.GetFile("http://sp2013:90/sites/test/DocSlide/youfilename.txt");

    $TargetFolderName = "Site Assets"

    #end of Static parameters

    foreach($subsite in $Web.Webs)
    {
    Write-output("Web Title: "+ $subsite.Title)

    $list = $subsite.Lists.TryGetList($TargetFolderName)

    if($list -ne $null)
    {
    if($list.Folders.Count >0)
    {
    foreach($folder in $list.Folders)
    {
    if($folder.Name -eq $TargetFolderName)
    {
    CopyToFolder( $folder.Url,$subsite)
    }
    }
    }
    else
    {
    write-output("Folder is not available ")
    }
    }
    }
    function CopyToFolder()
    {
    param($folderUrl)
    param($subsite)

    $DesFolder = $subsite.GetFolder($TargetFolderName);

    $content = $Sourcefile.OpenBinary()

    $Destiantion = $subsite.GetFolder($folderUrl)

    write-output(" Destination Folder Name: "+$folder.url)

    $newFile = $Destiantion.Files.Add($Sourcefile.Name, $content ,$false)

    $DesFolder.Update();
    }
    $site.Dispose();
    Stop-SPAssignment-Global 


    Gets custom data that is used in creating the Web site. 

    SPWebProvisioningProperties.Data

    Wednesday, 11 September 2013

    SharePoint 2013 Apps Hosting Models


    1) SharePoint-hosted This model relies on a sub web of the parent site (also called an app web)
    and enables you to use all the common SharePoint artifacts for implementing the UI and the
    behavior of the SharePoint app. You can take advantage of all the features of SharePoint, such
    as lists, Web Parts, pages, workflows, and so on.( Normally used for office 365 apps and Sharepoint development )

    2)  Autohosted Apps following this model are hosted on Microsoft Windows Azure, which can
    access a Microsoft SQL Azure database for managing data, too. The apps are automatically
    deployed on Windows Azure on your behalf and can communicate with SharePoint through
    events and the Client Object Model. Secure communication with SharePoint is enforced
    using OAuth.

    3) Provider-hosted From a functional perspective, apps that follow this model are almost
    the same as autohosted apps. The only difference is that a provider-hosted app has to be
    deployed on your own hosting environment and does not necessarily use the Windows Azure
    environment.

    Wednesday, 4 September 2013

    Reusable sharepoint javascript functions

    
    
    //First we must call the EnsureSetup method
    JSRequest.EnsureSetup(); 
    
    
    itemId = JSRequest.QueryString["ItemId"];
    var pagename = JSRequest.FileName;
    
    
     var pagepath = JSRequest.PathName;
    LoginAsAnother(url, bUseSource);
    
    
    
    
    url(string): the url of the page to which the new user has to be sent after login.
    bUseSource(boolean): A boolean that indicates that the source will be added to the url, otherwise the source will be the window.location.href. This parameter is optional, default is false.

    Tuesday, 3 September 2013

    Delete Sharepoint group using Jsom


    function DeleteWebGroup(GRPtitle) {
        var clientContext = new SP.ClientContext.get_current();
        var collGroup = clientContext.get_web().get_siteGroups();
         oGroup = collGroup.getByName(GRPtitle);
       collGroup.remove(oGroup);
        clientContext.executeQueryAsync(Function.createDelegate(this, this.onSetQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));}

    function onSetQuerySucceeded() {  
        alert("Group deleted.");
    }
    function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }
     var oGroup;
    DeleteWebGroup("test");