Tuesday, 17 September 2013

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());
}