How to create a sub-folder in doc. library using SPWebServices

Feb 11, 2011 at 3:02 PM

Is there any documentation about this.

Thanks

 

Coordinator
Feb 11, 2011 at 4:21 PM

armino:

There's an example for creating a folder on the UpdateListItems documentation page. Take a look and post back if you have fiurther questions.

M.

Feb 11, 2011 at 5:27 PM

I have this one working, but I need to create a generic sub-folder structure under root folder.

Thanks

sympmarc

 

Coordinator
Feb 11, 2011 at 5:43 PM

Can you explain a bit more about what you're trying to do and show what you have so far?

M.

Feb 11, 2011 at 6:43 PM

I need to create root folder and inside that folder 7 more folders at one event.

<script language="javascript" type="text/javascript" >
function PreSaveAction(folderName) {
  $().SPServices({
  operation: "UpdateListItems",
  async: false,
  listName: "ESAS Projects",
                rootFolder: "Test",
  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) {
   alert("Status=" + Status);  }
 });
 return true;

}
</script>

Coordinator
Feb 11, 2011 at 7:19 PM
Edited Feb 11, 2011 at 7:23 PM

Well, you'll need to add additional Methods for each of the other 6 folders or call SPServices 7 times, whichever you prefer based on your requirements. You can "stack" Methods in the updates with UpdateListItems. For instance:

		$().SPServices({
			operation: "UpdateListItems",
			async: false,
			listName: "Shared Documents",
			updates: "<Batch OnError='Continue'>" +
					"<Method ID='1' Cmd='New'>" +
						"<Field Name='FSObjType'>1</Field>" +
						"<Field Name='BaseName'>folder1</Field>" +
					"</Method>" +
					"<Method ID='2' Cmd='New'>" +
						"<Field Name='FSObjType'>1</Field>" +
						"<Field Name='BaseName'>folder1/folder1A</Field>" +
					"</Method>" +
					"<Method ID='3' Cmd='New'>" +
						"<Field Name='FSObjType'>1</Field>" +
						"<Field Name='BaseName'>folder1/folder1B</Field>" +
					"</Method>" +
				"</Batch>",
			completefunc: function(xData, Status) {
				alert("Status=" + Status + " XML:" + xData.responseText);
			}
		});

M.

Feb 11, 2011 at 7:29 PM

Thank you sympmarc.

Feb 17, 2011 at 4:37 PM

How to update content type

$().SPServices({
operation: "UpdateListItems",
async: false,
listName: "Shared Documents",
updates: "<Batch OnError='Continue'>" +
"<Method ID='1' Cmd='New'>" +
"<Field Name='FSObjType'>1</Field>" +

"<FieldRefName='ContentType'>My FOLDER type</Field>" +

"<Field Name='BaseName'>folder1</Field>" +
"</Method>" +
"</Batch>",
completefunc: function(xData, Status) {
alert("Status=" + Status + " XML:" + xData.responseText);
}
});

CAML:
<Query>
   <Where>
      <Eq>
         <FieldRef Name='ContentType' />
         <Value Type='Choice'>My FOLDER type</Value>
      </Eq>
   </Where>
</Query>

Coordinator
Feb 18, 2011 at 2:17 AM

armino:

Is that a question, an observation, what?

M.

Feb 18, 2011 at 1:08 PM

Hi sympmarc,

I've created a content type based on the folder in Sharepoint , so I can use metadata for the folders in document library, but when I use SP services to create these folders it creates them based on default folder type. So my question is what property I can use in this code to set my Folder Content type.

Thanx.

Coordinator
Feb 19, 2011 at 3:10 PM

armino:

It ought to work ,and I've found quite a few posts about doing it successfully. That said, I cannot make it happen, no matter how many variations I try of this:

  $().SPServices({
   operation: "UpdateListItems",
   async: false,
   listName: "Shared Documents",
   updates: "<Batch>" +
     "<Method ID='1' Cmd='New'>" +
      "<Field Name='ID'>New</Field>" +
      "<Field Name='ContentType'>My FOLDER type</Field>" +
      "<Field Name='ContentTypeId'>0x012000AC8B88E2B298E54EB0CD9920A17A74CA</Field>" +
      "<Field Name='FSObjType'>1</Field>" +
      "<Field Name='BaseName'>folder2</Field>" +
     "</Method>" +
    "</Batch>",
   completefunc: function(xData, Status) {
...

See this post, for instance:
http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/0afca725-23eb-4eb4-8429-fe463146a3f3
If
you search for "Updatelistitems 'content type' folder" you'll find others claiming success.

My test environment for this has been WSS 3.0, BTW.

M.

Feb 22, 2011 at 1:00 PM

Thanks Mark.

 

You guys should write some book about these jquery SPservices, definitely would have so many buyers.

Thank you .

Coordinator
Feb 22, 2011 at 1:56 PM

Hmm. A book? Unfortunately, that means months of work for little reward. I'll just keep dropping post on my blogs and such. ;+)

Let me know if you get this to work. It was driving me nuts not being able to get it.

M.

Feb 22, 2011 at 3:03 PM
Nope,
I'll try to work around 
$().SPServices({
		operation: "UpdateListItems",
		async: false,
		listName: "ESAS Projects",
		updates: "<Batch OnError='Continue' PreCalc='TRUE' ListVersion='0' >" +
"<Method ID='1' Cmd='New'>" +
"<Field Name='ContentType'>ESAS_x0020_FOLDER_x0020_STRUCTURE</Field>" +
"<Field Name='ContentTypeId'>0x012000B23FFBA6C7DCF14282DB06B6C2D5FB2700C578A75FA3F4C241B2A0C85945440477</Field>" +
"<Field Name='FSObjType'>1</Field>" +
          "<Field Name='BaseName'>" + folderName + "</Field>" +
          "</Method>" +
        "<Method ID='2' Cmd='New'>" +
	  "<Field Name='FSObjType'>1</Field>" +
	  "<Field Name='BaseName'>"+ folderName + pmo +"</Field>" +
	"</Method>" +

Feb 23, 2011 at 3:08 PM

Mark it works, it looks like that issue was I've removed "Default Folder Content Type" from doc. library, but it has to be there as default. (Just guessing) .

Thanx.

 

 

Coordinator
Feb 23, 2011 at 8:55 PM

Aha! I see what I did wrong. Silly me. I hadn't added the "My FOLDER type" Content Type as allowable on my list. Once I do that, everything works as planned,

  $().SPServices({
   operation: "UpdateListItems",
   async: false,
   listName: "Shared Documents",
   updates: "<Batch>" +
     "<Method ID='1' Cmd='New'>" +
      "<Field Name='ID'>New</Field>" +
      "<Field Name='ContentType'>My FOLDER type</Field>" +
      "<Field Name='BaseName'>folder2</Field>" +
     "</Method>" +
    "</Batch>",
   completefunc: function(xData, Status) {
    alert("Status=" + Status + " XML:" + xData.responseText);
   }
  });

M.

Sep 25, 2012 at 10:54 AM

 

I am trying to create folder in a document library  share point 2010 .

It is working if there is not any custom content types are added to the library. But if any content type is added,  then the folders are not creating.

find my below code

 

$().SPServices({ operation: "UpdateListItems", async: false, listName: "libraryname", updates:"<Batch OnError='Continue' PreCalc='TRUE' ListVersion='0' >" + "<Method ID='1' Cmd='New'>" + "<Field Name='FSObjType'>1</Field>" + "<Field Name='BaseName'>" + assetfoldername + "</Field>" + "</Method>" + "</Batch>"

Any solution for this ???

 

thanks in advance

 

 

Coordinator
Oct 8, 2012 at 3:18 PM

Make sure that the Folder Content Type is allowed on the library. You should probably inspect the returned XML to see if there is a useful error or other information to go on.

M.