Having difficulty creating new subfolder in document library

Jul 29, 2014 at 3:28 PM
Edited Jul 29, 2014 at 7:31 PM
I'm trying to use SPServices to create a new folder in a specific library. I'm using examples from other discussions here, but it's not working - the folder never shows up in the destination library. I also noticed the XML response is coming back as "Undefined", so I assume that would indicate an issue with my service call? Here's the code I'm using:
function createFolder(fldr) {
 var folderName = "/0_Inbox/" + fldr;
 console.log('Attempting to create folder ' + folderName);
    
 $().SPServices({
  operation: "UpdateListItems",
  async: false,
  listName: "{CF82AEBF-8083-4FBA-9CBD-2F6A1F5A47C4}",
  updates: "<Batch OnError='Continue' PreCalc='TRUE' ListVersion='0' >" +
   "<Method ID='1' Cmd='New'>" +
    "<Field Name='FSObjType'>1</Field>" +
    "<Field Name='BaseName'>" + folderName + "</Field>" +
   "</Method>" +
  "</Batch>",
  completefunc: function(xData, Status) {
  console.log("Status: " + Status + " | XML: " + xData.responseXML.xml);
  }
 });
 return true;
}
So, if I pass a folder name of "Test", what I want is a new folder located at ~sitecollection/site/library/0_Inbox/Test. I've tried using both the library name and the GUID as seen here - same issue. I get a Status of 'Success' and an XML response of 'Undefined'.

Thanks in advance for any help you can give.

UPDATE: After further googling, I replaced xData.responseXML.xml with xData.responseText and now I'm getting results back instead of just 'Undefined'.

XML Response with the parent folder included in folderName variable ("/0_Inbox/Test"):
RESOLVED (You can't have the leading slash on the folder path)
<?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><UpdateListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"><UpdateListItemsResult><Results><Result ID="1,New"><ErrorCode>0x81020073</ErrorCode><ErrorText>The file or folder name contains characters that are not permitted.  Please use a different name.</ErrorText></Result></Results></UpdateListItemsResult></UpdateListItemsResponse></soap:Body></soap:Envelope>
XML Response withOUT the parent folder included in folderName variable ("Test"):
RESOLVED (The folder cannot already exist)
<?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><UpdateListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"><UpdateListItemsResult><Results><Result ID="1,New"><ErrorCode>0x8107090d</ErrorCode><ErrorText>The operation failed because an unexpected error occurred. (Result Code: 0x8107090d)</ErrorText></Result></Results></UpdateListItemsResult></UpdateListItemsResponse></soap:Body></soap:Envelope>
Jul 29, 2014 at 5:58 PM
You may need to include the "Title" argument in the xml string you're sending such as...
var strFolderTitle = "New Item Title";
var strFolderBaseName = "SomeFolder/A Sub-Folder/" + strFolderTitle;

$().SPServices({
    operation: "UpdateListItems",
    async: false,
    listName: "The List",
    updates: "<Batch OnError='Continue' PreCalc='TRUE'>" +
            "<Method ID='1' Cmd='New'>" +
            "<Field Name='FSObjType'>1</Field>" +
            "<Field Name='BaseName'>" + strFolderBaseName + "</Field>" +
            "<Field Name='Title'>" + strFolderTitle + "</Field>" +
            "</Method>" +
            "</Batch>",
    completefunc: function(xData, status) {
        //Do something with the return here.
    }
});
This woks for me

Geoff
Jul 29, 2014 at 7:32 PM
I figured out both issues eventually. It's working as advertised now. I updated each issue with the fix, just in case anyone else needs the info.