Take a look at the SharePoint tool that was written yesterday, and the requirement is this:
Under SharePoint list subfolder, create 1000 folder, which specifies a special contenttype,contenttype that has a taxonomy type field, which assigns a value to this filed, And the newly created folder can only create a file of the specified contenttype.
The code to create the folder is as follows:
Public Static voidCreatfolder (stringSiteURL)//incoming site URL {using(SPSite site =NewSPSite (SiteURL)) { using(SPWeb Web =site. OpenWeb ()) {SPList list= Web. Lists.trygetlist ("your list title"); if(List! =NULL) {spsecurity.runwithelevatedprivileges ()={web. Allowunsafeupdates=true; SPFolder Bafolder= list. Rootfolder.subfolders.cast<spfolder>(). FirstOrDefault (f= F.name.equals ("your folder name or root folder", StringComparison.OrdinalIgnoreCase)); if(bafolder.exists) {Taxonomyfieldvalue Taxonomyfieldvalue /c8>=gettaxonomyfieldvalue (site, list); for(inti =100000; I <101001; i++) { stringGvname ="GV"+i; SPListItem NewItem=list. Items.Add (Bafolder.serverrelativeurl, Spfilesystemobjecttype.folder, gvname); Newitem[spbuiltinfieldid.contenttypeid]= list. contenttypes["your content type name"]. Id; Newitem.update (); newitem["Title"] =Gvname;
Assigns a value to the taxonomy field newitem["Your taxonomy field internal name"] =Taxonomyfieldvalue; Newitem.update (); List. Update ();
Specify Uniquecontenttypeorder for the newly created folder to create only the file or folder of the ContentType type contained in the Uniquecontenttypeorder under the new folder SPFolder Gvfolder=Newitem.folder; Collection<SPContentType> gvfolderorderedcontenttypes =NewCollection<spcontenttype>(); for(intj =0; J < list. Contenttypes.count; J + +) { if(list. CONTENTTYPES[J]. Name = ="your contenttype name") {Gvfolderorderedcontenttypes.add ( List. CONTENTTYPES[J]); }} Gvfolder.uniquecontenttypeorder=gvfolderorderedcontenttypes; Gvfolder.update (); }} web. Allowunsafeupdates=false; }); } } } }
Private Statictaxonomyfieldvalue Gettaxonomyfieldvalue (SPSite site, SPList list) {taxonomysession session=Newtaxonomysession (site); TermStore TermStore= Session. termstores["Managed Metadata Service"]; Group Group= termstore.groups[the group name"]; TermSet TermSet= group. termsets["Termset name"]; term= termset.terms["term name"];
Get Taxonomyfieldvalue Taxonomyfield Taxonomyfield= list. fields["Your taxonomy field name"] asTaxonomyfield; Taxonomyfieldvalue Taxonomyfieldvalue=NewTaxonomyfieldvalue (Taxonomyfield); Taxonomyfieldvalue.termguid=Term . Id.tostring (); Taxonomyfieldvalue.label=Term . Name; returnTaxonomyfieldvalue; }
Hope to help everyone!
SharePoint Create Folder with Conententtype programer