Return A Document Library GUID In C#

Answering another development question that was posted in the newsgroups, someone wanted to know assuming that they were aware of the path of an SPFolder object (a subfolder that existed in a SharePoint document library), how to return the GUID of the SharePoint document library that was housing the relevant SPFolder object. This is accomplished through the use of the SPFolder.ContainingDocumentLibrary property out of the Microsoft.SharePoint namespace, which has a return type of GUID, so should work correctly. Here is a quick atomic method that you can adapt to you needs (it’s pretty simple right now :) ) to achieve this:


private readonly SPWeb m_oWeb;

public Guid GetSPFolderDocLibGuid(string strPath)
return m_oWeb.GetFolder(strPath).ContainingDocumentLibrary;