0

I have created a folder in a SP2010 list using CSOM. When I try to fetch if the folder exists in list, it returns "Undefined" to the SPService that I run.

For all folders created using GUI the name of folder is returned. Also, I have tried setting up the value manually while creating the folder using this.oListItem["ows_Title"]="My Folder"; yet folder does not seem to get this property.

Code for folder creation-

clientContext = new SP.ClientContext.get_current();  
    oWebsite = clientContext.get_web();  
    oList = oWebsite.get_lists().getByTitle("List");  
    itemCreateInfo = new SP.ListItemCreationInformation();  
    itemCreateInfo.set_underlyingObjectType(SP.FileSystemObjectType.folder);  
    itemCreateInfo.set_leafName("My Folder");
    var name=itemCreateInfo.get_leafName();
    alert(name);
    this.oListItem = oList.addItem(itemCreateInfo);
    this.oListItem.update();
    clientContext.load(this.oListItem); 
    this.oListItem["ows_LinkTitle"]="My Folder";
    this.oListItem["ows_Title"]="My Folder";
    alert(this.oListItem["ows_LinkTitle"]);
    alert(this.oListItem["ows_Title"]);
    this.oListItem.update();
    clientContext.load(this.oListItem);  
    clientContext.executeQueryAsync(  
        Function.createDelegate(this, successHandler),  
        Function.createDelegate(this, errorHandler) 
     );  
     function successHandler() {  
        alert("Folder Created"); 
    }  

    function errorHandler() {  
        alert("Folder Creation Errored"); 
    } 
4
  • Do not use the prefix "ows_" Sep 1, 2016 at 17:19
  • @jpussacq It doesnt work changing it, if i check the name using SP service below it still gives me "Undefined", find the code in comment below Sep 2, 2016 at 6:18
  • Sorry, I did not read "SPService" Sep 2, 2016 at 12:22
  • Kind of a work around but i found that if i check folder name using "ows_FileRefName" in SP Service i will get the result as "12;#My Folder" where 12 is ID of folder. So i can store this in a var and get folder name and compare. This property is set for all folders created using GUI or the above script. However the script does not create the proeprty ows_Title or ows_LinkTitle. Sep 3, 2016 at 13:12

1 Answer 1

0

Try below code

clientContext = new SP.ClientContext.get_current();  
oWebsite = clientContext.get_web();  
oList = oWebsite.get_lists().getByTitle("List");  
itemCreateInfo = new SP.ListItemCreationInformation();  
itemCreateInfo.set_underlyingObjectType(SP.FileSystemObjectType.folder);  
itemCreateInfo.set_leafName("My Folder");
this.oListItem = oList.addItem(itemCreateInfo);
this.oListItem["Title"]="My Folder";
this.oListItem.update(); 
clientContext.load(this.oListItem);
clientContext.executeQueryAsync(  
    Function.createDelegate(this, successHandler),  
    Function.createDelegate(this, errorHandler) 
 );  
 function successHandler() {  
    alert("Folder Created"); 
}  

function errorHandler() {  
    alert("Folder Creation Errored"); 
} 
2
  • It doesnt work i have tried this as well already Sep 2, 2016 at 6:11
  • Find my code to find folders in list- function FolderCheck() { var arrFolder=[]; alert("Into Sp Service"); $().SPServices({ operation: "GetListItems", listName: "List", async: false, completefunc: function (xData, Status) { $(xData.responseXML).SPFilterNode("z:row").each(function() { var folderName=$(this).attr("ows_Title"); alert(folderName); }); } }); } Also note if i remover "ows_Title" with "Title" in Service then it will give me undefined for all folders Sep 2, 2016 at 6:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.