Archive for February, 2012

SharePoint: Get List of Folders and Subfolders


A question on MSN requested for code to populate two drop downs from a document library. “DropDown A” should contain list of all the folders at the root. If we select any folder from “DropDown A”, “DropDown B” should be populated with list of all folders in the selected folder.


To get the list of all the folders at root, following code will help:

using(SPSite oSite = new SPSite(“Site_URL”))


SPWeb oWeb = oSite.OpenWeb();

SPList oList = oWeb.Lists[“DocumentLibraryName”];

SPFolderCollection oFolders = oList.RootFolder.SubFolders;

foreach (SPFolder oFolder in oFolders)


if (!oFolder.Name.Equals(“Forms”))


//use oFolder.Name property to populate DropDown A




Once selected, following code will populate “DropDown B” with list of subfolders:

SPFolder selFolder = oList.RootFolder.SubFolders[oList.Title + “/” + “Selected Folder Name”];

SPFolderCollection selSubFolders = selFolder.SubFolders;

foreach (SPFolder selSubFolder in selSubFolders)


//use subFolder.Name property to populate DropDown B


Comments (7)

SharePoint 2010: Read ULS LOGS

Method I:

The easiest but most difficult way to go to LOGS folder [usually located @ C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS]. Open the log file and try to find the error using correlation ID or error description

Method II:

Download ULS Viewer provided by Microsoft to read from log files

Method III:

Use power shell command Get-SPLogEvent to read from log files.

Method IV:

Use third party tools for reading log files

  1. SharePoint Correlation ID View Webpart
  2. SharePoint ULS Log Viewer
  3. SharePoint Log Reader
  4. SharePoint LogViewer
  5. SPTraceView – Lightweight Tool For Monitoring The SharePoint Diagnostic Logging In Real-Time

Comments (1)

SharePoint 2010: Debugging Visual Studio 2010

Method I:

  1. Go to “Debug” and select “Attach to Process”
  2. Make sure “Show processes in all sessions” checkbox is checked
  3. Select all “w3wp.exe” processes and click on “Attach” button

If it does not work,

  1. Go to “Debug” and select “Attach to Process”
  2. Click on “Select…”.”Select Code Type” window will appear
  3. Select “Debug these codes types” and check “Managed (v2.0, v1.1, v1.0)” only

Method II:

  1. Write “System.Diagnostics.Debugger.Launch()” in the code where you want to attach debugger
  2. When you run the code, a popup window will appear asking for attaching debugger.
  3. Click “Yes” and guide to appropriate instance of Visual Studio

Method III:

Use third party software like:

  1. Visual Studio 2010 extension for helping SharePoint 2010 debugging

Leave a Comment