SharePoint SPFolder.SubFolders.Add not actually adding a folder

sharepointsharepoint-api

I have a couple of document libraries that are just standard libraries – no associated custom content types or anything. I am trying to add subfolders to them and in some cases it just doesn't work.

SPFolder parent = library.RootFolder;
SPFolder child = parent.SubFolders.Add(subfoldername);
parent.Update();
bool exists = child.Exists;   // This is false

When I try to add a subfolder called M1 Spectrum CRC w-out CMN67 E02_files via code it fails to add the folder, even though the Add method seems to execute successfully. When I try to add a folder of this exact name via the standard browser-based SharePoint list UI, I successfully get a folder added but it has a different name:

M1 Spectrum CRC w-out CMN67 E02_files_

Note the trailing underscore in the folder that SharePoint created. This is a legal Windows folder name and it doesn't contain any html-unfriendly characters. So, what's up with this? Am I missing something obvious?

Best Answer

This is because a folder ending with _files is a special kind created by the MS Office client apps when saving a document as HTML. The Office apps saves all the Web page resource files like images and css files to this folder. But it cannot be manipulated through the SharePoint Object Model - a real mess if you ask me! Only solution for you is to NOT create folders ending with _files.

Related Topic