Monday, 3 April 2017

SharePoint Online/ SharePoint 2013 - Calling Sync Function Through Javascript


Sharepoint enables users to take the document library offline and sync the documents on personal devices leveraging OneDrive for Business feature

  1. Sync option is available in Sharepoint Online as well Sharepoint 2013 on premise (Provided we have Onedrive installed on our local machine
  2. In case we have customized our masterpage and we are not using  OOB document library views we can’t use sync feature
  3. In this scenario we need to hook some client script to call the sync functionality on custom event.
  4. To call the sync functionality on click of control/using javascript below method can be used 

EnsureScriptFunc('offline.js', 'TakeOfflineToClientReal', function() { TakeOfflineToClientReal(2, 1, 'https://mydomain.sharepoint.com/sites/sc/webname', 1, 101,'989F78C3-FB40-46DE-ABF5-60380B44D201', '');});

989F78C3-FB40-46DE-ABF5-60380B44D201 – Is the GUID of the document library

Tuesday, 5 March 2013

Using Modules to Include Files in the Solution

I have seen lots of people struggle with Modules. Sometimes modules are getting deployed successfully but files are not reflecting in Document library.


First of all the Element.xml file should have below structure.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

  <Module Name="MyCustomModule" Url="SitePages" Path="MyCustomModule">
    <File Url="Sample.aspx" Type="GhostableInLibrary"/>
  </Module>
</Elements>

In above XML few things need to be taken care.

Url ( In Module element): Url in module element indicates the URL of the library where files need be created.

Url (In File element) : The location where the file will be deployed on the SharePoint server

Type: It indicates that whether file is available in Document library as a Item. If this attribute is missing, file would be available under list/libraries but it won’t show up in any of the Views.

Tuesday, 26 February 2013

Populating current logged in user in people picker

Sometimes there are requirement to populate the current logged in user in People picker field.
I had tried to populate using PickerEntity class, but it use to fail on click of "Check Names" button. So changed the approch to se the comma seprated names and it worked.

1. Take the curent Logged user

loginName = SPContext.Current.Web.CurrentUser.LoginName

2. Assign the login to picker control. 
pkrControlName.CommaSeparatedAccounts =loginName

Note: You can have multiple comma serpated login names to populate multiple users in people picker field.

Wednesday, 5 September 2012

Retrieve existing base permission using powershell

Below script can be used to retrieve the existing Base Permission for the given permission level.
param(

[Parameter(Position=0, Mandatory=$true)]
[string]
$siteURL
)
$snapin = Get-PSSnapin
Where-Object { $_.Name -eq "Microsoft.SharePoint.Powershell" }
if ($snapin -eq $null) {
Add-PSSnapin "Microsoft.SharePoint.Powershell"
}

$site=Get-SPSite $siteURL
$web=$site.RootWeb
$permissionLevel=$web.RoleDefinitions["PermissionName"]
Write-Host $permissionLevel.BasePermissions
$web.Dispose()
$site.Dispose()

Thursday, 24 November 2011

Save ViewState at server side to reduce Page Size

Some time we have lots of heavy controls (like GridView,DataGrid) which emits lots of ViewState information on the page. This results to increase in Page size and apparently it would reduce the page performance.
So to reduce the page size ViewState can be stored on Server side which would reduce the page size.
We need to override SavePageStateToPersistenceMedium method to save the ViewState at server side and LoadPageStateFromPersistenceMedium method to retrieve the ViewState.

Note: These two methods needs to be overridden in code behind file of ASP.Net page.

Sample Code snippet.

protected override void SavePageStateToPersistenceMedium(object state)
{
try
{
string VSKey = "VIEWSTATE_" + base.Session.SessionID + "_" +
Request.RawUrl + "_" + DateTime.Now.Ticks.ToString();
Cache.Add(VSKey, state, null, DateTime.Now.AddMinutes(Session.Timeout),
Cache.NoSlidingExpiration, CacheItemPriority.Default, null);
ClientScript.RegisterHiddenField("__VIEWSTATE_KEY", VSKey);
}
catch
{
base.SavePageStateToPersistenceMedium(state);
}
}

protected override object LoadPageStateFromPersistenceMedium()
{
string VSKey = Request.Form["__VIEWSTATE_KEY"];
return Cache[VSKey];
}

Wednesday, 3 August 2011

Admin SVC must be running in order to create deployment timer job

Issue : Recently, while using a PowerShell command (Update-SPSolution) I encountered below error.

Admin SVC must be running in order to create deployment timer job

Solution : You would encounter above error if “ SharePoint 2010 Administration” services is nor running. So to resolve above issue goto run -> type “services.msc” and start “SharePoint 2010 Administration” service.

Friday, 1 July 2011

Multiple list instances of list definition

Problem:

Recently, I observed one weird thing in my SharePoint application.I was creating a list definition which had multiple views. I wanted to create one instance of the site definition but I could see multiple list instances of the same list in my site.

Reason:

I figured out the reason behind this issue.

In schema.xml under the views node I had multiple views definitions.
I had created one view and replicated the same for rest of the views.

<View DisplayName="By Customer Name" DefaultView="TRUE" BaseViewID="1" Type="HTML" MobileView="TRUE" MobileDefaultView="TRUE" ImageUrl="/_layouts/images/generic.png" XslLink="main.xsl" WebPartZoneID="Main" Url="By Customer Name.aspx" SetupPath="pages\viewpage.aspx">
<Toolbar Type="Standard" />
<XslLink>main.xsl</XslLink>
<Query>
</Query>
<ViewFields>
</ViewFields>
<RowLimit Paged="TRUE">100</RowLimit>
</View>


I was modifying the query and fieldrefs. Erroneously DefaultView="TRUE" attribute was present in all the views, which was resposible for creating multiple instances of the list and keeping that particular view as the default view.

Query List/Document Library in Specific Folder

To query SharePoint List or Document Library in specific Folder “ FolderServerRelativeUrl ” as part of the CAML Query Code Snippet ...