Wednesday, June 29, 2011
Finding Page Layouts and Master Page usages
Recently, I messed up my page layout by manually editing the layout directly from the gallery. It started adding multiple web part instances all of a sudden when a page created with the page layout. So I decided to delete the layout and re-deploy the solution again.
I was getting the below error when I was trying to delete that particular page layout from my site collection's Master page and page layouts collection. (http://spsiteurl/_catalogs/masterpage/Forms/AllItems.aspx)
And I have deleted all the instances where ever the layout was being used. I was sure I was missing some place but how do I find that out??
After a long search I found a place where to get all the usages of page layouts. I went to the Site Content and Structure by selecting "Manage Content and Structure" from the "Site Actions" menu. And navigated to the "Master Page Gallery" list in the root web.
We do have an option in the menu on the right side pane to show the related resources "Show Related Resources" to show/hide the related resources. Turning on this option and selecting the particular page layout or master page would show you the resources using the particular layout/master page.
A preview ...
Isn't this handy & cool??
Monday, June 13, 2011
Check-in & Check-out using ECMA script in SharePoint 2010
Recently, I had to enable editing just the content (not web part zones) of a publishing page by end users without the ribbon. I decided to make use of the ECMA script model to empower end users to update just the content of the page.
Provide buttons for different operations of a publishing page (edit, save and cancel) and handle the events in javascript coding and some jQuery.
I came across Sohel's blog with a pretty good description of how to make use of the ECMA script. It is basically, all the updates need to be set in its corresponding javascript objects and then "executeQueryAsync" must be called on the ClientContext object to save everything on to the server.
One porblem I faced was updating a particular field content in the current list item being edited. After doing some research on MSDN, I came across this function SP.File.listItemAllFields on MSDN (http://msdn.microsoft.com/en-us/library/ee557727.aspx) and started down that path.
I was able to check-out the current PublishingPage, update the corresponding list item and publish the page using current user's permissions.
function checkOut(){
var ctx = SP.ClientContext.get_current();
var page = ctx.get_web().getFileByServerRelativeUrl(window.location.pathname);
page.checkOut();
ctx.load(page);
ctx.executeQueryAsync(Function.createDelegate(this, checkOut_Success),
Function.createDelegate(this, checkOut_Fail));
}
function checkOut_Success(sender, args){
//Do all sort of jquery to insert your own RTE control to edit the page contents
}
function checkOut_Fail(sender, args){
//Do some error checking
}
function checkIn(){
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var page = web.getFileByServerRelativeUrl(window.location.pathname);
if (contentEditorNicInstance != null) {
var listItem = page.get_listItemAllFields();
listItem.set_item("PublishingPageContent", "{Updated content from the UI}");
listItem.update();
}
page.checkIn();
page.publish();
ctx.executeQueryAsync(Function.createDelegate(this, checkIn_Success),
Function.createDelegate(this, checkIn_Fail));
}
function checkIn_Success(sender, args){
//This is to refresh the page after successful publishing with the new updated content.
//If the page is not refreshed, the ECMA script will not support further check-in's and comes back with an error as "version conflict"
window.location = window.location;
}
function checkIn_fail(sender, args){
//Handle the error message
}
I think I am helping myself to remember this in future and also few others with their coding.
Senthil
Provide buttons for different operations of a publishing page (edit, save and cancel) and handle the events in javascript coding and some jQuery.
I came across Sohel's blog with a pretty good description of how to make use of the ECMA script. It is basically, all the updates need to be set in its corresponding javascript objects and then "executeQueryAsync" must be called on the ClientContext object to save everything on to the server.
One porblem I faced was updating a particular field content in the current list item being edited. After doing some research on MSDN, I came across this function SP.File.listItemAllFields on MSDN (http://msdn.microsoft.com/en-us/library/ee557727.aspx) and started down that path.
I was able to check-out the current PublishingPage, update the corresponding list item and publish the page using current user's permissions.
function checkOut(){
var ctx = SP.ClientContext.get_current();
var page = ctx.get_web().getFileByServerRelativeUrl(window.location.pathname);
page.checkOut();
ctx.load(page);
ctx.executeQueryAsync(Function.createDelegate(this, checkOut_Success),
Function.createDelegate(this, checkOut_Fail));
}
function checkOut_Success(sender, args){
//Do all sort of jquery to insert your own RTE control to edit the page contents
}
function checkOut_Fail(sender, args){
//Do some error checking
}
function checkIn(){
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var page = web.getFileByServerRelativeUrl(window.location.pathname);
if (contentEditorNicInstance != null) {
var listItem = page.get_listItemAllFields();
listItem.set_item("PublishingPageContent", "{Updated content from the UI}");
listItem.update();
}
page.checkIn();
page.publish();
ctx.executeQueryAsync(Function.createDelegate(this, checkIn_Success),
Function.createDelegate(this, checkIn_Fail));
}
function checkIn_Success(sender, args){
//This is to refresh the page after successful publishing with the new updated content.
//If the page is not refreshed, the ECMA script will not support further check-in's and comes back with an error as "version conflict"
window.location = window.location;
}
function checkIn_fail(sender, args){
//Handle the error message
}
I think I am helping myself to remember this in future and also few others with their coding.
Senthil
Subscribe to:
Posts (Atom)