Friday, June 25, 2010

Create folder using SharePoint web service

You can find how to create a folder using SharePoint web service at here http://msdn.microsoft.com/en-us/library/lists.lists.updatelistitems%28v=office.12%29.aspx .
The following XML is how to create a folder under a list directly.
<Batch OnError="Continue" PreCalc="TRUE" ListVersion="0" ViewName="{EF2F5A21-0FD0-4654-84ED-112B4F5A48F8}">
<Method ID="1" Cmd="New">
<Field Name="ID">New</Field>
<Field Name="FSObjType">1</Field>
<Field Name="BaseName">FolderA</Field>
</Method>
</Batch>

But my question is how to create a folder in another folder, you cannot set BaseName to the path, like list/folderA/folderB, as BaseName should be the folder name, cannot contain any special characters. after checking the document above, I found that if you want to update/delete a document, the field FileRef must be provided, like this:
<Batch OnError=“Continue” PreCalc=“TRUE” ListVersion=“0” ViewName=“{EF2F5A21-0FD0-4654-84ED-112B4F5A48F8}”>
<Method ID=“1” Cmd=“Delete”>
<Field Name=“ID”>3</Field>
<Field Name=“FileRef”>http://machinename/sites/siteA/listA/folderA</Field>
</Method>
</Batch>

so FileRef is a much important value for SharePoint to identify a document. then I tried to set FileRef field to the folder path when creating a folder, like this:
<Batch OnError="Continue" PreCalc="TRUE" ListVersion="0" ViewName="{EF2F5A21-0FD0-4654-84ED-112B4F5A48F8}">
<Method ID="1" Cmd="New">
<Field Name="ID">New</Field>
<Field Name="FSObjType">1</Field>
<Field Name="BaseName">FolderB</Field>
<Field Name="FileRef">/listA/FolderA/FolderB</Field>
</Method>
</Batch>
There it is. you can see that folder B is created under folder A.

1 comment:

sukumar said...

How should use that's give code and how to put in place. the sharepoint how can sharing gather . could you give inform. Sharepoint Development