Getting lists definition a SharePoint site - sharepoint

I can see all the lists in a project site using <sharepoint site URL>/_vti_bin/ListData.svc/, but how can I get to see all the lists AND their columns? Is there a way of achieving this?

You can't do it in one query. You will need to go through one by one to get the list definition. For example, if you have a list called Calendar you can get the items and the fields by going to <sharepoint site URL>/_vti_bin/listdata.svc/Calendar. It will output the list items and for each entry is a tag called content within which is another tag called m:properties. This includes all the fields for the content type and their values.
<content type="application/xml">
<m:properties>
<d:ContentTypeID>0x010200FD20E8386D889748BDD9444F29251083</d:ContentTypeID>
<d:Title>Meeting with Bob</d:Title>
<d:Location>WebEx</d:Location>
<d:StartTime m:type="Edm.DateTime">2014-11-26T10:00:00</d:StartTime>
<d:EndTime m:type="Edm.DateTime">2014-11-26T10:30:00</d:EndTime>
<d:Description><div>Meeting with Bob</div></d:Description>
<d:AllDayEvent m:type="Edm.Boolean">false</d:AllDayEvent>
<d:Recurrence m:type="Edm.Boolean">false</d:Recurrence>
<d:Workspace m:type="Edm.Boolean">false</d:Workspace>
<d:CategoryValue>Meeting</d:CategoryValue>
<d:TeamMemberNameId m:type="Edm.Int32">138</d:TeamMemberNameId>
<d:Id m:type="Edm.Int32">1</d:Id>
<d:ContentType>Event</d:ContentType>
<d:Modified m:type="Edm.DateTime">2014-11-26T09:35:12</d:Modified>
<d:Created m:type="Edm.DateTime">2014-11-26T09:35:12</d:Created>
<d:CreatedById m:type="Edm.Int32">2990</d:CreatedById>
<d:ModifiedById m:type="Edm.Int32">2990</d:ModifiedById>
<d:Owshiddenversion m:type="Edm.Int32">1</d:Owshiddenversion>
<d:Version>1.0</d:Version>
<d:Path>/Lists/Calendar</d:Path>
</m:properties>
</content>

Related

Crafter CMS Search Attachment With External Metadata Post Processor in repeating Group

I have the following data model.
A Page type with a repeating group names files. Inside the repeating group, there is a node-selector to select files name file
Then I need to index the metadata of the page with the metadata of the file in order to do a search by files.
To accomplish this I'm using org.craftercms.cstudio.publishing.processor.SearchAttachmentWithExternalMetadataPostProcessor
The first document I attached works fine but any other File is not being indexed with the metadata of the page.
This is the Reference list I'm using
<property name="referenceXpathList">
<list>
<value>//file/item/value</value>
</list>
</property>
Even though my XPath expression should match all file.item.value I'm just getting the first match.
SearchAttachmentWithExternalMetadataPostProcessor expects each XML document to just have one associated binary file. In most cases it makes sense because the XML document contains metadata that's just specific to that file. So if the XPath returns a list it will select the first one. You can always extend the processor and make it so that the same XML metadata is associated to different files.

Setting created and modified dates for Sharepoint 2010 list items

I'm working on a Powershell script to migrate data from an existing SQL Server database into Sharepoint 2010 lists. Some of the records in the existing database have created and modified dates which the client would like to carry over into Sharepoint.
My migration script uses the UpdateListItems method on Sharepoint Lists web service to upload batches of CAML to create the new items. I have updated my CAML to set the "Created" column however the value seems to get ignored and is just set to the current date.
Is it possibly to manually set these dates either through the web services or through the ProcessBatchData method on the SPWeb object? I've seen examples online which imply that it can be done for individual items by disabling system update and tweaking versioning settings. However working with individual items is not an option since we have about 800,000 list items to import.
Solution was to change from using web services to using SPWeb.ProcessBatchData to import my data (thanks Andreas).
The XML passed into this method looks like:
<ows:Batch OnError="Continue">
<Method ID="1">
<SetList />
<SetVar Name="ID">New</SetVar>
<SetVar Name="Cmd">Save</SetVar>
<SetVar Name="urn:schemas-microsoft-com:office:office#ColumnName1">Value</SetVar>
<SetVar Name="urn:schemas-microsoft-com:office:office#Modified">2009-09-03T15:05:00Z</SetVar>
<SetVar Name="urn:schemas-microsoft-com:office:office#Created">2004-01-15T13:48:00Z</SetVar>
</Method>
<Method ID="2">
...
</Method>
...
</ows:Batch>
The "SetList" element should contain the Guid for the list to add the data too. In my example XML above this is empty because the XML is pre-generated before importing the data into SharePoint and we can't guarantee that the Sharepoint list Guid on the target server would be the same so we fill this in just before importing.
I also had to ensure that the dates being passed in where in the correct format by passing them into the SPUtility.CreateISO8601DateTimeFromSystemDateTime method.

Default Content Type and Content type order using Folders in a Sharepoint List

I have a Custom List Definition (schema.xml) i have set up Site Columns (through A feature) and numerous content types also through a feature, this all works fine. I have a list definition (schema.xml) and i have put the content types at the top in the order i want them to appear (assuming that the top content type will be the default for the list - which is what i want)
NOTE: i HAVE set
EnableContentTypes="true"
here is an excerpt from my schema.xml
<ContentTypes>
<!-- Folder based content type -->
<ContentTypeRef ID="0x0120006ad66a4924644ac98d371a0e069c5d99" />
<!-- Item Based Content Type -->
<ContentTypeRef ID="0x0100a18ddd58b9384567bc776a3c5889ea77" />
<!-- ..... more content types ... -->
</ContentTypes>
The problem i have is that when a list is provisioned the folder based content type is always second in the list, and as a result is never the default in the list, the only way i can make it default is to remove all the other content type declarations which sort of defeats the object of having multiple content types. Is this ordering because of the way the list is provisioned or am i missing something tucked away deep in the SDK, any help gratefully accepted
Using a FeatureReceiver you can set the lists RootFolder.UniqueContentTypeOrder to an ordered list of ContentTypes which will then determine to Button order.
You can also leave out ContentTypes which you don't want to be available even though they are defined in the list. It's common to combine this with an event receiver which sets the button order (UniqueContentTypeOrder) of folders added, to guide people into a certain structure like only folders at the top level and no nested folders (or only x levels deep) or what you like.
Check the property bag. The list you're working on probably has a property called "vti_contenttypeorder", with the content type id's in the order they will show up when you go reordering them through the UI.
...building on #Renan answer - set your default Content Type declaratively.
Create a module, name it Property bags and add it to the web scope feature containing your list instance. The Elements.xml should contain the following:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<PropertyBag Url="<!--URL of your list instance here-->" ParentType="Folder" RootWebOnly="FALSE" AlwaysCreateFolder="TRUE" xmlns="http://schemas.microsoft.com/sharepoint/">
<Property Name="vti_contenttypeorder" Value="<!--Your custom Content Type ID here-->" Type="string" />
</PropertyBag>
</Elements>

How do you set the Filter for a SharePoint event receiver?

I've only recently noticed the Filter element in the definition file for a SharePoint event receiver:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers>
<Receiver>
...
<Filter />
</Receiver>
</Receivers>
</Elements>
The MSDN documentation for the SPEventReceiverDefinition.Filter property says that the value: "represents the filter for the SPListItem object". And includes the following remarks:
"Event handlers are registered at the site or site collection level to implement filtering to respond to list item events. Filtering allows multiple rules to be applied in sequence to limit the size of a list or some other dimension of that list. They are specified in persistent storage as name-value pairs in the form of assignment statements."
My question is: how can I set the value of the Filter? Would you use a CAML <Where> element?
I'm just curious at this stage. I don't have a reason to use this, but saw it and starting wondering. I searched through all event receiver definitions in SharePoint 12 'hive' folders and none had a filter applied.
Any filtering that I have done in event receivers, I have done in code.
I found a couple of liks that seem to indicate that the filter element is either reserved, or not implemented.
http://msdn.microsoft.com/en-us/library/dd340827(PROT.13).aspx
Maybe in MOSS 2010.

Add a lookup field to a content type in sharepoint

How can I add a lookup field to a content type in sharepoint using the xml definition? (I'm getting errors).
Things to note:
- The lookup list will exist when the content type is added to the document library.
- The lookup list will always have the same name.
- The lookup list has a space in the name.
This is what I've added to the xml:
<Field ID="{GUID}"
Type="Lookup"
List="$Resources:core,lists_Folder;/List%20Name"
ShowField="Title"
Name="MyLookupFieldName"
DisplayName="MyLookupFieldName"
StaticName="MyLookupFieldName"
Hidden="FALSE"
Required="FALSE"
Sealed="TRUE"
>
When I then programatically add the content type to a document library I get an exception (with no useful information), and the following is logged to the sharepoint log:
08/18/2009 17:13:39.50 w3wp.exe (0x08B8) 0x11B0 Windows SharePoint Services Database 6f8g Unexpected Unexpected query execution failure, error code 8114. Additional error information from SQL Server is included below. "Error converting data type nvarchar to uniqueidentifier." Query text (if available): "{?=call proc_GetListMetaDataAndEventReceivers(?,?,?,?,?,?)}"
Luckily, in SharePoint 2010, you can declaratively do this by setting all required properities as shown in the following working example.
<Field Type="Lookup" DisplayName="Link Type" Description="Represents link type."
Required="TRUE" EnforceUniqueValues="FALSE" List="Lists/Links Types" WebId="~sitecollection"
Overwrite="TRUE" PrependId="TRUE" ShowField="Title" UnlimitedLengthInDocumentLibrary="FALSE"
Group="Research Links Columns" ID="{a15e9fa2-4ea0-41f1-a583-b21d53cf72d3}"
SourceID="{30650f6f-fbb8-4acc-a935-29745f5d3c59}" StaticName="Link_x0020_Type"
Name="Link_x0020_Type" Hidden="FALSE" ReadOnly="FALSE"></Field>
It's important to set WebId to have value of "~sitecollection" and set Overwrite to be TRUE.
More info
The problem is that you need to reference the GUID of the list not its title. As you probably won't know the GUID of the list then you can't do this without executing some custom code afterwards.
Even if you aren't using VSeWSS, the last steps in the post dahlbyk has linked to show you how to do this. Chris O'Brien has gone to the trouble of making a CodePlex project that will help you if you aren't using VSeWSS.
Ok, so I couldn't get the xml definition of a field for a content type to work for me for some reason. I did find out how to do it in code. The solution that worked for me is to not add the Field definition in xml, instead add it in code:
Add the content type to the list (in site definition code, or wherever).
Add a field lookup to the given SPWeb (so the field is a web? field, rather than a site field)
Add a new field link to the list content type.
Update the content type.
For example:
SPContentType myContentType = myWeb.Site.RootWeb.ContentTypes["MyContentType "];
myLib.ContentTypes.Add(myContentType);
myContentType = myLib.ContentTypes["MyContentType "];
myWeb.Fields.AddLookup("MyLookupFieldName", myWeb.Lists["MyLookupListName"].ID, false);
SPFieldLink myFIeldLink = new SPFieldLink(myWeb.Fields["MyLookupFieldName"]);
myContentType.FieldLinks.Add(myFIeldLink);
myContentType.Update();

Resources