SharePoint 2007: How to check if a folder exists in a list using web services?
Using SharePoint 2007 webservices or even Webdav, how can I check if a folder exists in a list (not document library) in SharePoint.
I would also like to check for subfolders...
Anyone have any idea on how this is done? I've asked Microsoft, and their official stance is that Microsoft provide no documentation on this. so any help will be most welcome...
开发者_运维知识库Thanks in advance...
I have this code that creates a folder, but not sure how to modify it to check if the folder exists, also not even sure if this will work with sub folders...
private void CreateFolderUsingWebService(string listName, string folderName)
{
//Check Databox Folder Exists
//string folderAddress = siteAddress + @"/lists/" + listAddress + @"/" + folderName;
//wsDws.CreateFolder(folderAddress);
var doc = new XmlDocument();
XmlElement batch = doc.CreateElement("Batch");
string item = "<Method ID=\"1\" Cmd=\"New\">" +
"<Field Name=\"ID\">New</Field>" +
"<Field Name=\"FSObjType\">1</Field>" +
"<Field Name=\"BaseName\">" + folderName + "</Field></Method>";
batch.SetAttribute("ListVersion", "1");
//batch.SetAttribute("ViewName", "{GUID of View, including braces}");
batch.InnerXml = item;
wsLists.UpdateListItems(listName, batch);
}
Ok - this info might help the next SharePoint developer:
The function above works, and will even create a directory structure. BUT you need to pass the list name, not the list URL, this means if you localize your code, you need to pass the localized list name to the function.
I didn't bother adding a check for ifExists, because it seems to NOT create duplicates or fail if the directory already exists. I know this isn't a great solution, but I just don't have 2-3 weeks to research how to do it properly, so if you have any suggestions, comments are welcome.
Lastly any Microsoft representation reading this - might want to consider why there isn't any really good documentation on this with how to's from MS? Mmmmm
I went as far as downloading the MOSS Web Services SDK, and it contains 1 very vague example of how to use 1 function in the Lists web service, this simply is not enough information for those of us trying to put together robust solutions in MOSS. We need way more documentation please...
精彩评论