Hey Guys,
Today I ran into an really stupid error. I have an Doc Library in a SharePoint Site, I create folders programmatically. Now I had the requirement to add MetaTags to that Library. After I added custom Columns to that Library my Code to Create a Folder in that Library won't work anymore, because the SPFolder.Item Object has been null.
After a while of searching I found this post, and the explanation why this happens!?
So how could I add a Folder to a Library with MetaTags!?
First of all create a new ContentType of Type Folder and insert all required MetaTags (see my post Create Folder with MetaTags)
After you have done this, you must change the code for creation of the Folder.
SPDocumentLibrary doclib = (SPDocumentLibrary)(m_SharePointWeb.GetListsOfType(SPBaseType.DocumentLibrary)[libraryName]);
string url = ((SPFolder)(doclib.RootFolder)).ServerRelativeUrl.ToString();
SPFolder folder = web.GetFolder(url);
web.AllowUnsafeUpdates = true;
SPListItem newItem = doclib.Items.Add(
doclib.RootFolder.ServerRelativeUrl,
SPFileSystemObjectType.Folder,
null);
newItem["Title"] = folderName;
newItem["Name"] = folderName;
newItem["ContentType"] = folderType;
newItem.Update();
doclib.RootFolder.Update();
web.Update();
Posted
May 05 2009, 12:07 PM
by
Nadine Storandt