I am using SharePoint webservice to retrieve content type from the site. The output looks like this:
<ContentTypes ContentTypeOrder="0x010300971A94A609AC5F4390A1FF87A26CD05D" xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<ContentType Name="Issue" ID="0x010300971A94A609AC5F4390A1FF87A26CD05D"
Description="Track an issue or problem."
Scope="https://practiv1.sharepoint.com/devtest/Lists/issueTracking"
Version="0"
BestMatch="TRUE">
<XmlDocuments>
<XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
<FormTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
<Display>ListForm</Display>
<Edit>ListForm</Edit>
<New>ListForm</New>
</FormTemplates>
</XmlDocument>
</XmlDocuments>
</ContentType>
<ContentType Name="Folder"
ID="0x01200049A00CD1A9F3944A9AE7BCCAC15B02D4"
Description="Create a new folder."
Scope="https://practiv1.sharepoint.com/devtest/Lists/issueTracking"
Version="0">
<XmlDocuments>
<XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
<FormTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
<Display>ListForm</Display>
<Edit>ListForm</Edit>
<New>ListForm</New>
</FormTemplates>
</XmlDocument>
</XmlDocuments>
</ContentType>
I want to use xpath to retrieve items. But I used the path like "//ContentType" or "/ContentTypes/ContentType", I couldn't find anything :
var listService = new ListWebService.Lists();
listService.Url = "xxx.sharepoint.com/xxx/_vti_bin/Lists.asmx";
var contents = listService.GetListContentTypes("issueTracking", "0x01");
Can someone help me what wrong with my xpath?
This is a common problem when dealing with XML having default namespace (xmlns="..."). The node where the prefix declared and all it's descendants, if not explicitly specified otherwise, are considered in the default namespace.
You need to register a prefix that points to the namespace URI and use that prefix in your XPath, for example :
var nsManager = new XmlNamespaceManager(new NameTable());
nsManager.AddNamespace("d", "http://schemas.microsoft.com/sharepoint/soap/");
var result = contents.SelectNodes("//d:ContentType", nsManager);
//or using the other XPath : "/d:ContentTypes/d:ContentType"
Related
In my first outing with csom and the document library, I encountered a difficult error when attempting to access a document library object property as file.File.Title using the following code.
The error is
Object reference not set to an instance of an object on server.
The code shown is what "works" for my exercise.
What step am I missing to be able to use file.File.Title instead of file.FieldValues["Title"].
The code snippet is a very primitive attempt to get a list of files in the default Document library folder. In a following iteration, I need to update the caml to retrieve a specific file.
var lib = ctx.Web.DefaultDocumentLibrary();
ctx.Load(lib);
ctx.ExecuteQuery();
var files = lib.GetItems(CreateAllFilesQuery());
ctx.Load(files);
ctx.Load(files, items => items.Include( item => item.File.Title ));
ctx.ExecuteQuery();
foreach(var file in files )
{
if(!(file.FieldValues["Title"] == null) )
{
string FileName = file.FieldValues["Title"].ToString();
if (FileName == DocumentName)
return true;
}
}
public static CamlQuery CreateAllFilesQuery()
{
var qry = new CamlQuery();
qry.ViewXml = #"<View Scope=\'FilesOnly\'>
<Query></Query>
<ViewFields>
<FieldRef Name='Title' />
<FieldRef Name='ContentType' />
<FieldRef Name='DocIcon' />
</ViewFields>
</View>";
return qry;
}
After further research, I discovered that my caml query was at fault. The syntax error was placing slashes around the Scope value. The corrected query allows me to reference file.File.Title as expected. The additional benefit is that I am only getting back files rather than files and folders.
qry.ViewXml = #"<View Scope='FilesOnly'>
<Query></Query>
<ViewFields>
<FieldRef Name='Title' />
<FieldRef Name='ContentType' />
<FieldRef Name='DocIcon' />
</ViewFields>
</View>";
In Groovy given a GPath I want to find that the path exists in XML document. So that I can set a value for the node. I can use xmlslurper for parsing the document. GPath is a string path represented in slashes format.
Look at example:
def xml = '''
<?xml version="1.0" encoding="UTF-8"?>
<data>
<level0 id="1" t="0">
<level1 id="lev1id01" att1="2015-05-12" val="12" status="0" year="2015" month="05" />
</level0>
</data>
'''
// find all nodes named 'level1'
def level1Nodes = new XmlSlurper().parseText(xml).level0.level1
// display found nodes names
level1Nodes.each { node ->
println "node: ${node.name()}"
}
// Get 'year' attribute value for 'level1' node
def level1YearValue = level1Nodes.each { node ->
println "${node.#year}"
}
Could you be more specific in your question?
Hi I am trying to get the user profile properties from sharepoint on client side with javascript.But I am not getting the value of nodes in xml.
How to get them. the xml will look like as:
How to get attribute value of node in xml using xpath
Here I want to get the value which is between <name> tags <Name>AccountName</Name> and between Name tags
want to get the value = abc what will be the xpath expression
Please help
<?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>
<GetUserProfileByNameResponse xmlns="http://microsoft.com/webservices/SharePointPortalServer/UserProfileService">
<GetUserProfileByNameResult>
<Pro pertyData>
<IsPrivacyChanged>false</IsPrivacyChanged>
<IsValueChanged>false</IsValueChanged>
<Name>UserProfile_GUID</N ame>
<Privacy>NotSet</Privacy>
<Values>
<ValueData>
<Value xmlns:q1="http://microsoft.com/wsdl/types/" xsi:type="q1:guid">8ed84415-7330-4857-a7d2- d797d71c439f
</Value>
</ValueData>
</Values>
</PropertyData>
<PropertyData>
<IsPrivacyChanged>false</IsPrivacyChanged>
<Is ValueChanged>false</IsValueChanged>
<Name>AccountName</Name>
<Privacy>NotSet</Privacy>
<Values>
<ValueData>
<Value xsi:type="xsd:string">abc
</Value>
</ValueData>
</Values>
</PropertyData>
</GetUserProfileByNameResult>
</GetUserProfileByNameResponse>
</ soap:Body>
</soap:Envelope>
Please help me in this.
var propertyData = $(responseXML).find("PropertyData").filter(function(e){
return $(this).find("Name").text() == "AccountName";
});
var value = propertyData.length > 0 ? propertyData.find('Value').text() : '';
Since you are trying to retrieve user profile via SharePoint Web Services I would recommend to utilize SPServices library, it hides (almost)all the intricacies when working with SharePoint Web Services from JavaScript. The following example demonstrates how to retrieve user profile using GetUserProfileByName method and process the results:
function getUserProfile(accountName,completeFn) {
var userInfo = {};
$().SPServices({
AccountName: accountName,
operation: 'GetUserProfileByName',
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("PropertyData").each(function() {
userInfo[$(this).find("Name").text()] = $(this).find("Value").text();
});
completeFn(userInfo);
}
});
}
var loginName = 'i:0#.f|membership|username#contoso.onmicrosoft.com';
getUserProfile(loginName,function(info){
console.log(info);
});
You have to traverse through the xml nodes returned from the SPServices. I have written a function for getting the desired user profile property.
function getUPValue(x, p) {
var thisValue = $(x).SPFilterNode("PropertyData").filter(function() {
return $(this).find("Name").text() == p;
}).find("Values").text();
return thisValue;
}
Further to query the user property you just need to call like below,
getUPValue(xData.responseXML, "WorkEmail");
These article provides a detail overview of it over here
I am currently exporting a lotus notes database using the C# Interop Domino assembly from NuGet,
I haven't found a way to identify objects or elements in a NotesRichTextItem in the order they were entered, for example, maybe I enter a paragraph first, then a table , then an attachment.
Is there a way to loop through the elements in their respect order ?
I have found a way to find elements with FindFirstElement, but you have to pass what element type you are looking for, this is very difficult as extracting all elements without order would make the content to lose its context.
thanks
There is a way to analyze Notes document's RichText items using DXL - a special XML format for Notes. Use DxlExporter to export a Notes document to DXL format. You can "walk" then through XML and get the content of RichText item with elements in right order.
For this RichText item e.g.
you'd get this DXL
<item name='Body'>
<richtext>
<pardef id='1'/>
<par def='1'>aaaaaaa</par>
<table widthtype='fixedleft' refwidth='1.0667in'>
<tablecolumn width='0.6729in'/>
<tablecolumn width='0.3938in'/>
<tablerow>
<tablecell>
<pardef id='3' keepwithnext='true' keeptogether='true'/>
<par def='3'>111</par></tablecell>
<tablecell>
<pardef id='4' keepwithnext='true' keeptogether='true'/>
<par def='4'>222</par></tablecell>
</tablerow>
<tablerow>
<tablecell><par def='3'>333</par></tablecell>
<tablecell><par def='4'>444</par></tablecell>
</tablerow>
</table>
<pardef id='5' leftmargin='1.2500in' list='bullet'/>
<par def='5'>xxx</par>
<par def='5'>yyy</par>
<par def='5'>zzz</par>
<pardef id='6' leftmargin='1in'/>
<par def='6'>
<attachmentref name='icon16.gif' displayname='icon16.gif'>
<picture height='34px' width='61px'>
<notesbitmap>lQAmAAAAAAAAAAAAA...</notesbitmap>
<caption>icon16.gif</caption>
</picture>
</attachmentref>
</par>
</richtext>
</item>
Here is a Java agent which exports selected documents to a file.
import lotus.domino.*;
public class JavaAgent extends AgentBase {
#Override
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
DocumentCollection dc = agentContext.getUnprocessedDocuments();
String filename = "c:/temp/exportDocs.dxl";
Stream stream = session.createStream();
if (stream.open(filename)) {
stream.truncate();
DxlExporter exporter = session.createDxlExporter();
exporter.setRichTextOption(0);
exporter.setMIMEOption(0);
stream.writeText(exporter.exportDxl(dc));
} else {
System.out.println("Cannot open " + filename);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Unfortunately the API gives you no way to do this:
Navigation is within elements of the same type. You can find or get
the first element of a type, the next element of a type, and the nth
element of a type. You cannot find or get an element regardless of
type.
http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/topic/com.ibm.designer.domino.main.doc/H_NOTESRICHTEXTNAVIGATOR_CLASS.html
UPDATE: I forgot to mention that you may want to check out a third-party tool from Genii Software called MidasLSX that possibly could help you. http://www.geniisoft.com/showcase.nsf/MidasLSX
I need to add a custom menu action to a custom content type programmatically in c#. This is because I will not know the URL I need to link to beforehand. The URL to link to will be pulled from configuration when the feature is activated.
I have tried the following:
Added the CustomAction in my Element.xml file as:
<CustomAction
Id="MyID"
RegistrationType="ContentType"
RegistrationId="0x010100ef19b15f43e64355b39431399657766e"
Location="EditControlBlock"
Sequence="1000"
Title="My Menu Item">
<UrlAction Url="" />
</CustomAction>
In my feature receiver FeatureActivated method, I have:
SPElementDefinitionCollection eleCollection =
properties.Feature.Definition.GetElementDefinitions(
new System.Globalization.CultureInfo(1));
foreach (SPElementDefinition ele in eleCollection)
{
if (ele.Id == "MyID")
{
System.Xml.XmlNode node = ele.XmlDefinition.FirstChild;
node.Attributes[0].Value = "MY URL";
ele.FeatureDefinition.Update(true);
}
}
I would expect this code to update the UrlAction Url with "MY URL" but it does not. If I hard code a URL in the XML it works but I must be able to do it programmatically.
You can use the SPUserCustomActionCollection on the SPWeb object:
using (SPSite site = new SPSite("http://moss.dev.com"))
using (SPWeb web = site.OpenWeb())
{
SPContentType contentType = web.ContentTypes["Curriculum Vitae"];
SPUserCustomAction action = web.UserCustomActions.Add();
action.RegistrationType = SPUserCustomActionRegistrationType.ContentType;
action.RegistrationId = contentType.Id.ToString();
action.Location = "EditControlBlock";
action.Sequence = 450;
action.Title = "Test";
action.Rights = SPBasePermissions.EditListItems;
action.Url = "http://www.google.com";
action.Update();
}
This way, you can set the URL to whatever you want. If you are updating an existing custom action, you can iterate through the collection and update the one you are looking for. Updating the element XML definition after you've installed the custom action doesn't do anything.
Depending on what you want to achieve, you can use some javascript;
<UrlAction Url="JavaScript:window.location='{SiteUrl}/_layouts/CustomListAction.aspx?ID={ListId}'"/>
the ~site and ~siteCollection also works:
<UrlAction Url="~site/_layouts/Page.aspx?ID={ListId}"/>
I don't think the WSS schema definition allows for an empty Url attribute in the UrlAction element. Maybe try putting a "default" url in the xml that you overwrite later?