by tondam at 2013-02-15 13:50:15
I'm just starting out with Powershell and have been trying to create a custom folder as opposed to the standard out of the box folder that SharePoint provides. I can create the OOTB folders with my eyes closed but I can't figure out how to create folders based on my own content type. Is this something that can be done with Powershell?
Simply replacing "Folder" with my own folder content type doesn't do the job
$spFolder = $list.AddItem(â€œâ€,[Microsoft.SharePoint.SPFileSystemObjectType]::Folder,'MyNewFolder')
Am I missing something?
by AlexBrassington at 2013-02-17 23:38:54
The short version is: I don't think you can using OOB.
The only way I know of to create a custom library based on a content type is to use an unholy blend of exporting a user solution from SharePoint, importing it into Visual Studio and deploying the resulting code as a feature. It works but it's, generally, not a time saver.
Having said that it's a relatively straight forward proposition;
Create a new library
Allow management of content types
Add your new Content Type
Remove the default content type
*Disable management of content types
Create a new default view with fields based on the content type
*Optional and possibly a bad idea, i haven't tried this using GUI or PS. WIll need some experimentation
The views bit is a little niche but the rest is standard fare.
by AlexBrassington at 2013-02-18 02:38:01
Scratch my previous reply.
If i understand you correctly you wish to create a folder within a doc lib that only holds a specific content type? If so then it's not something that SharePoint supports. You define the allowed content types at the library level, any folder within that library can contain any content type that the library allows. Restricting below the library level is not possible.
You could use document sets to achieve the desired effect but that might not meet your requirements.
Alternatively you can use custom views to only show set content types or metadata filtering. Neither is straght forward to put in place but both can be done.
Finally you might need to look at the structure you're using. Folders are evil in SharePoint and should be avoided where possible.
by tondam at 2013-02-18 12:34:12
Thanks for your response Alex. I suspect you may have misunderstood my question. I have created a library and created by own folder content type called "MyFolderContentType" which has numerous column defined and this content type has been attached to a library I have created. In actual fact I have numerous custom folder content types attached to the library.
Essentially all I want to do is read in some folder names from a CSV file and create folders based on "MyFolderContentType" or any other specified custom folder content type instead of the standard
SharePoint Folder content. I have been googling for days trying to find how one specifies anything other than the standard folder content type without luck.
It seems to the whole world is happy to just use standard folder content type with its single column of name. The snippet below is what I have found but it clearly specifies the standard folder and that's all it creates.
$spFolder = $list.AddItem(â€œâ€,[Microsoft.SharePoint.SPFileSystemObjectType]::Folder,'MyFolderContentType')
If I replace "Folder" in the code with a variable containing the name of my custom content type it doesn't work. There must be a trick that I am missing. I've tried everything incuding adding an ID for my custom folder but it still does work. Incidentally I hate folders as much as you do but unfortunately our users scream for them.
by tondam at 2013-02-18 20:12:55
OK I worked it out....it's not elegant but it works. There are bound to be better ways of achieving the same thing but for what it's worth here is the code I used. If anyone can come up with something better I'd be interested in hearing from you.
$spAssignment = Start-SPAssignment
$web = Get-SPWeb -Identity http://path
$list = $web.GetList("http://libpath"😉
$listCT = $list.ContentTypes["SP SysAdmin Folder"]
#first ADD NORMAL FOLDER
$spFolder = $list.AddItem(â€œâ€,[Microsoft.SharePoint.SPFileSystemObjectType]::folder,'MyNewFolder8')
#Get path of folder
$spFolder = $web.GetFolder("SharePointTestLib/MyNewFolder8")
#identify item to change which is a folder
$item = $spFolder.Item
#Apply content type ID
$item["Content Type ID"] = $listCT.ID