views:

2171

answers:

3

I have a couple 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

I can see that it seems to be data-dependent, but I'm still stumped. When I try to add a subfolder with this particular name via my code:

M1 Spectrum CRC w-out CMN67 E02_files

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 for me. Why is it doing that? Why is this a particularly problematic case? 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?

+3  A: 

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.

Lars Fastrup
Thanks... yeah, that's a little goofy. Makes it unnecessarily hard to import html-based reports when the reports have folder structures with names that end in _files. Oh, well. At least the reason is clearer now! thanks!
Chris Farmer
+1  A: 

I'm seeing this more generally, just trying to create a folder using the string "web_files" as the folder name either fails completely, or actually creates a folder called "web_files_", depending on the API you use.

Using parent from the question code, this will fail in the same way:

SPFolder newFolder = parent.SubFolders.Add("web_files");

While this will create a folder with a different name:

SPList list = parent.ParentWeb.Lists.GetList(parent.ParentListId, true);
SPListItem newFolder = list.Items.Add(parent.ParentWeb.Url, SPFileSystemObjectType.Folder, "web_files");
newFolder.Update();

I'm trying to migrate SPS 2003 content into a MOSS 2007 site (using the code at https://sourceforge.net/apps/trac/splistcp) and this is causing a problem.

Michael Baltaks
A: 

TRY SPWeb site = new SPSite(sharepointURL).OpenWeb(); site.AllowUnsafeUpdates = true;

AllowUnsafeUpdates