Custom ASPX page in SharePoint 2013
Hi All,
We might be having a scenario to create custom ASPX Wiki page in SharePoint without inheriting SharePoint branding.In this case sp.js reference to be added explicitly in order to connect to SharePoint Lists etc. Below are the files to be referred in the HEAD section of ASPX page,so that you can make use of clientcontext and other SP.JS functionalities.
Configuration Values in SharePoint 2010 Timer Job
Hi All,
1. When we develop custom timer job in SharePoint 2010 most of the time we might need to store some config
values which can be utilized while activating the feature or during the execution of the timer job.
2. Some of us may think about the use of config list and fetch the data from there when we move the package
from dev. environment to other environment we should also carry over the configuration list along with site url where the
config list resides.
3. In order to remove from these kind of pain SharePoint is having an awesome feature called Property bag .
MSDN reference contains Property bag implementation in details
http://msdn.microsoft.com/en-us/library/ee855123(v=office.12).aspx
Below is Powershell script which can be used to create property bag values
-----------------------------------------------------------------------------------------------------------------------------
$snapin = Get-PSSnapin | Where-Object {$_.Name -eq ‘Microsoft.SharePoint.Powershell’}
if ($snapin -eq $null) {
Write-Output “Loading SharePoint Powershell Snapin”
Add-PSSnapin “Microsoft.SharePoint.Powershell”
}
# —————————————————–
Write-Output “Task initialized…”
$weburl= “http://../sites/test/Implemetnation”
$url= [System.Web.HttpUtility]::UrlDecode($weburl)
$site = New-Object Microsoft.SharePoint.SPSite($url)
$rootWeb = $site.RootWeb
Write-Host -foregroundcolor Green “The current Site”$rootWeb
$PropertyKey = “siteUrl”
$webvalue= “/Implemetnation”
$PropertyValue = [System.Web.HttpUtility]::UrlDecode($webvalue)
$rootWeb.AllowUnsafeUpdates = $true;
$Currentvalue = $rootWeb.Properties[$PropertyKey]
Write-Host -foregroundcolor Green “The current value of the property bag is “$Currentvalue
if (!$rootWeb.Properties.ContainsKey($PropertyKey))
{
$rootWeb.Properties.Add($PropertyKey, $PropertyValue);
}
else
{
$rootWeb.Properties[$PropertyKey] = $PropertyValue;
}
$rootWeb.Properties.Update();
$rootWeb.Update();
$rootWeb.AllowUnsafeUpdates = $false;
$UpdatedValue = $rootWeb.Properties[$PropertyKey]
Write-Host -foregroundcolor Green “Value of the property bag is updated with ” $UpdatedValue
if ($rootWeb -ne $null)
{
$rootWeb.Dispose()
}
If ($site -ne $null)
{
$site.Dispose();
}
Write-Host -foregroundcolor Green “Script has finished executing ”
Write-Output “Task completed…”
———————————————————————————————————————————————————————-
Xenu sleuth for capturing hard-coded url
Recently when i was working in a SharePoint migration 2007 to 2010 project faced a challenging scenario as given.
Our Sharepoint 2007 application contains hard-coded url in many entities like Lists,WebPart Pages etc. During the course of migration we need to update all the hard-coded url with the updated relative url based on the new environment.
1) Just to kick start we have decided to find out the pages contains the Content Editor WebPart which have
reference to the old url. There is a powershell script we have customized based on our requirement to get the list of pages with
CEWP which meets our criteria.
2) Then we have developed a custom utility to replace the hard coded url with the updated url based on the result
obtained from step 1.
3)After all find & replace stuff we decided to ensure that there will be no reference to the hard coded urls in anywhere in the SharePoint application.
For this task there is a utility called “Xenu sleuth” http://home.snafu.de/tilman/xenulink.html
It’s open tool that can be downloaded and installed in order to use the same. The instruction on how to use the tool also available in the above url. One drawback what we have faced is we are not able to get the Referrer of the hard coded url (i.e. the page in which the hard coded url is referred.)
But it’s a noteworthy tool in order to verify hard coded Url during the course of migration.
Add Webpart in sharepoint wiki page
Recently one of my friend asked about adding a sharepoint document library webpart in to
a Wiki page. Wiki page still allows you to add a webpart by Edit page but the list of webparts are limited
when compared with Webpart Page. As a workaround we have created a new webpart page and added the
document library wbpart.Then using Sharepoint designer opened the webpart page and copy the Webpart
content and pasted into Wiki Page.
While doing so you need to make sure there are pre-requisite sharepoint specific javascript file
should be loaded for the webpart to function properly.
<script type=”text/javascript” src=”//ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js”>
</script>
<script type=”text/javascript” src=”_layouts/sp.runtime.js”></script>
<script type=”text/javascript” src=”_layouts/sp.js”></script>
<script type=”text/javascript”>
// Continue your program flow here.
</script>
Sharepoint 2010 Discussion Board using REST service
This post address about accessing sharepoint 2010 discussion board using listdata.svc
i)Creating new discussion
<?xml version=”1.0″ encoding=”utf-8″ standalone=”yes”?>
<entry xmlns:d=”http://schemas.microsoft.com/ado/2007/08/dataservices” xmlns:m=”http://schemas.microsoft.com/ado/2007/08/dataservices/metadata” xmlns=”http://www.w3.org/2005/Atom“>
<category scheme=”http://schemas.microsoft.com/ado/2007/08/dataservices/scheme” term=”Microsoft.SharePoint.DataService.TeamDiscussionItem” />
<title type=”text”>Hello REST</title>
<updated>0001-01-01T00:00:00Z</updated>
<author>
<name />
</author>
<id />
<content type=”application/xml”>
<m:properties>
<d:Body m:null=”true” />
<d:ContentType>Discussion</d:ContentType>
<d:ContentTypeID>0x0120</d:ContentTypeID>
<d:Created m:type=”Edm.DateTime”>2012-07-18T20:42:56.7959323-07:00</d:Created>
<d:CreatedById m:type=”Edm.Int32″ m:null=”true” />
<d:EMailSender m:null=”true” />
<d:Id m:type=”Edm.Int32″>0</d:Id>
<d:LastUpdated m:type=”Edm.DateTime” m:null=”true” />
<d:Modified m:type=”Edm.DateTime” m:null=”true” />
<d:ModifiedById m:type=”Edm.Int32″ m:null=”true” />
<d:ModifiedById0 m:type=”Edm.Int32″ m:null=”true” />
<d:Owshiddenversion m:type=”Edm.Int32″ m:null=”true” />
<d:Path m:null=”true” />
<d:Subject>REST request for new thread</d:Subject>
<d:Version m:null=”true” />
</m:properties>
</content>
</entry>
ii)Reply to discussion
While replying to the existing thread need to make sure the Path consist of the title of the discussion
to which we are responding. Also the content type attribute should be given as Message
<?xml version=”1.0″ encoding=”utf-8″ standalone=”yes”?>
<entry xmlns:d=”http://schemas.microsoft.com/ado/2007/08/dataservices” xmlns:m=”http://schemas.microsoft.com/ado/2007/08/dataservices/metadata” xmlns=”http://www.w3.org/2005/Atom“>
<category scheme=”http://schemas.microsoft.com/ado/2007/08/dataservices/scheme” term=”Microsoft.SharePoint.DataService.TeamDiscussionItem” />
<title type=”text”>Reply for REST request for new thread</title>
<updated>0001-01-01T00:00:00Z</updated>
<author>
<name />
</author>
<id />
<content type=”application/xml”>
<m:properties>
<d:Body>Reply for REST request for new thread</d:Body>>
<d:ContentType>Message</d:ContentType>
<d:ContentTypeID>0x0107</d:ContentTypeID>
<d:Created m:type=”Edm.DateTime”>2012-07-18T20:42:56.7959323-07:00</d:Created>
<d:CreatedById m:type=”Edm.Int32″ m:null=”true” />
<d:EMailSender m:null=”true” />
<d:Id m:type=”Edm.Int32″>0</d:Id>
<d:LastUpdated m:type=”Edm.DateTime” m:null=”true” />
<d:Modified m:type=”Edm.DateTime” m:null=”true” />
<d:ModifiedById m:type=”Edm.Int32″ m:null=”true” />
<d:ModifiedById0 m:type=”Edm.Int32″ m:null=”true” />
<d:Owshiddenversion m:type=”Edm.Int32″ m:null=”true” />
<d:Path>/<SITE>/Lists/Team Discussion/REST request for new thread</d:Path>
<d:Subject>REST request for new thread</d:Subject>
<d:Version m:null=”true” />
</m:properties>
</content>
</entry>
Sharepoint 2010 Discussion Board using SOAP service
Accessing Read/Reply to the thread in Sharepoint Discussion board.
1) Using SOAP:
Folowing the soap request format to get read all the threads from discussion board
based on requested user permission.
<?xml version=”1.0″ encoding=”utf-8″?>
<soap:Envelope xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=”http://www.w3.org/2001/XMLSchema“>
<soap:Body>
<GetListItems xmlns=”http://schemas.microsoft.com/sharepoint/soap/“>
<listName>{46622757-67AC-4C9B-A715-69C46A8E6D96}</listName>
</GetListItems>
</soap:Body>
</soap:Envelope>
where,
– <listName> is a GUID for the list extracted from list settings url.
To create a new discussion
<?xml version=”1.0″ encoding=”utf-8″?>
<soap:Envelope xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=”http://www.w3.org/2001/XMLSchema“>
<soap:Body>
<AddDiscussionBoardItem xmlns=”http://schemas.microsoft.com/sharepoint/soap/“>
<listName>{46622757-67AC-4C9B-A715-69C46A8E6D96</listName>
<message>TWVzc2FnZS1JRDogZmMxMjY1YzMtNzcxYi00MjkyLTg3ZDUtNjY2NGU3MTkyZTVhClRocmVhZEluZGV4OiA0NGFkYTZmOS0zNmFiLTQzNjAtOTM3ZC1hNDA0ODc4MmFkYTYKU3ViamVjdDogU09BUCBEaXNjdXNzaW9uCk1pbWUtVmVyc2lvbjogMS4wCkNvbnRlbnQtdHlwZTogdGV4dC9wbGFpbjsgY2hhcnNldD1VVEYtOA==</message>
</AddDiscussionBoardItem>
</soap:Body>
</soap:Envelope>
where,
<message>is base 64 encoded string for below mime type,
Message-ID: gc1265c3-772x-4292-87d5-6664e7192e5a
ThreadIndex: 43ada6f9-35bc-4360-937d-a4048782ada2
Subject: SOAP New Discussion
Mime-Version: 1.0
Content-type: text/plain; charset=UTF-8
Reply to existing discussion
<?xml version=”1.0″ encoding=”utf-8″?>
<soap:Envelope xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=”http://www.w3.org/2001/XMLSchema“>
<soap:Body>
<UpdateListItems xmlns=”http://schemas.microsoft.com/sharepoint/soap/“>
<listName>{46622757-67AC-4C9B-A715-69C46A8E6D96}</listName>
<updates>
<Batch RootFolder=”/<SITE>/Lists/Team Discussion/Soap Discussion” OnError=”Continue” xmlns=””>
<Method ID=”0″ Cmd=”New”>
<Field Name=”Body”>SOAP Reply</Field>
<Field Name=”ContentType”>Message</Field>
<Field Name=”DiscussionTitleLookup”>22;#Soap Discussion</Field>
</Method>
</Batch>
</updates>
</UpdateListItems>
</soap:Body>
</soap:Envelope>
where,
– <listName> is a GUID for the list extracted from list settings url.
Sharepoint 2010 REST service limitations
Sharepoint 2010 listdata.svc exposes REST implementation to client in order to access list items.
Below are some of short comings of using REST
i) Access sharepoint survey using listdata.svc
Recently i had a requirement to expose the sharepoint survey questions and choices to the client
via REST Service.While exposing we found that the survey questions and choices are in REST format
in the response.
http://<Server_Name>/_vti_bin/listdata.svc/<SURVEYNAME>+”Item”
Limitations:
a) i.e. Do you like to play cricket? becomes DoYouLikeToPlayCricket?
By this way client have no clues to display the readable format of the questions.
in order to retain the format.
Moreover if the survey doesn’t contain any response then there is no way to retrive the questions
from the listadata.svc.
Workaround:
In order to overcome the above restrictions,i have decided to create a new list with columns contains
survey questions with below format such as,
i)Do you like to play cricket? – (Readable format)
ii)DoYouLikeToPlayCricket -(REST format)
ii)Name of the Survey
Now client can able to get the survey questions even if the survey doesn’t contains any response. But we need to make sure
whenever the survey questions are added/edited the same should be updated in a new list created by us.we can also achive this by
using ECMA client object model.
Note: The above mentioned limitation can also be resolved by using SOAP service.But in
our case we have chosen the service layer as REST in our design.
jQuery loading issue in sharepoint pages
Recently i have faced a issue with some pages in my sharepoint application jQuery is not getting loaded.
Even though i’ve cross verified path and did all checks. finally got resolution in the given post.
The reason javascript generated by sharepoint framework also contains a $ synbol for denoting variables.
By converting $ into jQuery i my script makes the issue resolved.