So I have been working a lot with the SharePoint object model recently to do things like modify lists and add document libraries.
One real oddity I have come across has been adding a new document library and setting it to be displayed in the Quick Launch menu. Pretty much everything in SharePoint is a list (SPList) and a Document Library is no exception. I had no real difficulty adding the new document library, the API “does what it says on the tin”. However, I came a bit unstuck when trying to set the OnQuickLaunch property of the SPList to True. I just could not get it to appear in the Quick Launch! My code was as follows:
Dim swRootWeb As SPWeb = ssSite.RootWeb
swRootWeb.Lists.Add(strName, "description",SPListTemplateType.DocumentLibrary)
swRootWeb.Update()
swRootWeb.Lists(strName).OnQuickLaunch = True
swRootWeb.Lists(strName).Update()
swRootWeb.Update()
I can not explain why the solution I found works. However, I discovered by declaring the newly created list as a local variable and then calling the Update method on this object, rather than on the SPListCollection(i), the Update works as expected and the new Document Library is added into the Quick Launch:
Dim swRootWeb As SPWeb = ssSite.RootWeb
swRootWeb.Lists.Add(strName, "description", SPListTemplateType.DocumentLibrary)swRootWeb.Update()
Dim slNewList As SPList = swRootWeb.Lists(strName)
slNewList.OnQuickLaunch = True
slNewList.Update()
swRootWeb.Update()