Saturday 28 September 2013

Get List Items Using JSOM


 var Title = "Document Sharing";
var CurrentFolderItems;
    function GetListItems() {
 
        var clientContext = new SP.ClientContext.get_current();
        var oWeb = clientContext.get_web();
        var currentTabList = this.oWeb.get_lists().getByTitle("Budgets");
        var query = new SP.CamlQuery();      
        var querytext = '<View><Query><Where><Neq><FieldRef Name="Title" /><Value Type="Text">0</Value></Neq></Where></Query></View>';
        query.set_viewXml(querytext);
        CurrentFolderItems = currentTabList.getItems(query);
        clientContext.load(CurrentFolderItems);
        clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQueryGetFolderItemsSucceded),
        Function.createDelegate(this, this.onQueryGetFolderItemsFailed));

    }

    function onQueryGetFolderItemsSucceded() {

console.log("1");
   var data="";
    var ListEnumerator = this.CurrentFolderItems.getEnumerator();
while(ListEnumerator.moveNext()){
    var item = ListEnumerator.get_current();

   var image = item.get_item("Title");
   var itemimg = item.get_path("Image");

   for(i in itemimg )
   {
   console.log(itemimg[i]);// data += item[i];
   }
  data += "\n"+image+ itemimg;  
    }
alert(data);
}

function onQueryGetFolderItemsFailed(sender,args){
console.log(args.get_message());
}

GetListItems();

Thursday 26 September 2013



 Generally, a SharePoint Administrator can be either: 
  • A Server-centric SharePoint Administrator - This person deals with everything that takes place within the cozy little area that we call the server closet.  None of this person's interaction with SharePoint will be through a web browser with the exception of Central Administration tasks.  This would be more akin to the system administrator or server administrator function.  His necessary skills might also include familiarity with networking, hardware, host OS, SQL admin, etc. -- the difference being that the strength of this individual is the manipulation of the systems that provide the SharePoint services.  Though it is useful for these administrators to be familiar with SharePoint's user interface and functionality, it may not be entirely necessary, depending on the specific nature of their duties. 
  • A User-centric SharePoint Administrator - The man or woman in the trenches -- SharePoint administration on the front line.  This individual would interact with users and interact with SharePoint almost exclusively through a web browser.  He or she might need to use Central Administration occasionally depending on his/her specific duties.  This person would go to a Server-centric administrator for anything involving the mechanics under the hood.  The rights to the SharePoint site or Site Collection may be unlimited or restricted to specific roles.  Any individual that does more than view or add content would probably fall into this category.  Creating a list or library or even setting basic permissions on an item would qualify as a User-centric Administrator function.
 
These lines are obviously not hard, solid, and impermeable.  Depending on the business needs, the gray area of delineation between the two will probably be constantly changing.  So why is this distinction important at all?  That's what prompted this blog post.  With Microsoft's push to provide hosted services, the lines have become a little more necessary when looking for training.  With Office 365 SharePoint, an online SharePoint solution hosted by Microsoft, the Server-centric administration is all handled by Microsoft.  The back end is almost totally off limits to "administrators" with good reason.  This frees up businesses from having to invest in Server-centric expertise.  It then leaves a business with a need for User-centric expertise.  This is the diverging point. 

An individual called the other day and declared that he had been made the Office 365 SharePoint administrator.  Their question was "What course within SharePoint Solutions' offerings should I take for this position?"  In this circumstance, the most beneficial course would be one of our introductory courses.  Since the Office 365 SharePoint environment is almost entirely user-centric, then the best way to get in and administer it would be to learn exactly what users do with SharePoint.  In a sense, one could say that a User-centric SharePoint Administrator is a "super-user".  But this term would downplay the level of skill required for a User-centric administrator to set up lists and libraries, not to mention setting up a structure that would allow users to set up lists and libraries.

The term "SharePoint Administrator" is simply too vague to be useful in and of itself.  The term needs to be clarified by what the Administrator will be administering.  With this clarification, the most appropriate path, and course, may be chosen to take your SharePoint skills to the next level.





1. Create a JavaScript file and put it in directory under the root project’s directory:
2. Open the properties of the JavaScript file. Under “Build Action” select “Embedded Resource”.
3. In the “AssemblyInfo.cs” add this line:
[assembly: System.Web.UI.WebResource("[Assembly Name].[Folder].[JS file]", "text/javascript")]
For Example, in my project:
[assembly:
System.Web.UI.WebResource("XXX.WebPart.ListViewer.Script.ListViewer.js", "text/javascript")]

4. Add this line in the constractor of your control / web-part:this.PreRender += new EventHandler(MyControl_PreRender);

5. Add these 2 lines in the Pre_Render event of your web-part:string jsLocation = Page.ClientScript.GetWebResourceUrl(this.GetType(), "[Assembly Name].[Folder].[JS File]");
Page.ClientScript.RegisterClientScriptInclude("MyScript", jsLocation);

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");

    Sharepoint edit group title using JSOM


    function setSomeUsers(OldTitle,newTitle) {
        var clientContext = new SP.ClientContext.get_current();
        var collGroup = clientContext.get_web().get_siteGroups();
        var oGroup = collGroup.getByName(OldTitle);
    oGroup.set_title(newTitle);
        oGroup.update();
    clientContext.load(oGroup );
        clientContext.executeQueryAsync(Function.createDelegate(this, this.onSetQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));}

    function onSetQuerySucceeded() {   
        alert(this.oGroup .get_title() + " added.");
    }
    function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }