Can we retrieve the TypeName of a web part using CSOM?
-
What would be the reason I get Access denied during the web service call? I have the highest permissions possible in the environment. If it makes a difference, I'm calling this from an auto-hosted SharePoint 2013 App.– user21884Jan 10, 2014 at 14:43
-
I personally used server-side CSOM instead of Vadim's code so haven't checked the code. However, you could try to call other services. I think there should not be any specific permissions needed for this service in particular.– thomiusJan 11, 2014 at 15:56
Add a comment
|
1 Answer
It doesn't seem possible to retrieve all the web part properties (like TypeName
) via CSOM
But it could be performed via WebPartPagesWebService
SharePoint Web Service as demonstrated below:
function getWebPartProperties(pageUrl,completeFn,errorFn)
{
var soapEnv =
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> \
<soap:Body> \
<GetWebPartProperties2 xmlns="http://microsoft.com/sharepoint/webpartpages"> \
<pageUrl>' + pageUrl + '</pageUrl> \
<storage>Shared</storage> \
<behavior>Version3</behavior> \
</GetWebPartProperties2> \
</soap:Body> \
</soap:Envelope>';
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_vti_bin/WebPartPages.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: completeFn,
error: errorFn,
contentType: "text/xml; charset=\"utf-8\""
});
}
$(function() {
getWebPartProperties('/SitePages/DevHome.aspx',
function(xhr,textStatus){
$(xhr.responseXML).find("WebPart").each(function() {
var wpTypeName = $(this).find('type').attr('name'); //get Web Part TypeName
console.log(wpTypeName);
});
},
function(xhr,textStatus,errorThrown){
console.log(errorThrown);
});
});
-
-
I had a chance to verify it for publishing pages and it works for me Jan 4, 2014 at 14:05
-
1oh, apparently the error was not due to publishing pages but web part types. Tasks web part returns only one property "Cannot import this Web Part" apparently..– thomiusJan 4, 2014 at 14:07