Debugging in SharePoint Online – Part1

Debugging in SharePoint Online – Part1
9 votes, 4.67 avg. rating (93% score)


Many of the general debugging techniques we use will not work in an online development environment. For example, you cannot enable the Developer Dashboard in the online environment. Also, Sandbox Solutions cannot write to the file system or over the network. For SharePoint online debugging purposes, one better way is to write debugging information as screen alerts or storing it within SharePoint lists. With this approach in mind, we can keep a SharePoint site just for development and then deploy solutions to online production site. I will present various techniques, refereed articles as series for debugging in SharePoint Online.

Logging to SharePoint List for debugging

The following code snippet is an example how to get debugging information into SharePoint List used for SharePoint Online.
Sometimes we can tweak the same to log information only when excpeption comes, i.e logging information to list code will be available only in catch block.

using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace SharePointOnlineLogging.WebPart1
    public class WebPart1 : WebPart

        private Button logResultsButton = new Button() { Text = “Log Results” };
    private Label lbl = new Label();

    public WebPart1()

    protected override void CreateChildControls()
            logResultsButton.Click += (object sender, EventArgs e) =>

            SPContext context = SPContext.Current;

        SPWeb web = context.Web;

        SPList list = web.GetList("/Lists/MyLoggingList");  // Creating 'MyLoggingList' object
        string logResults = DateTime.Now.ToShortDateString() + “ ” + DateTime.Now.ToShortTimeString() + ": Logged from Sandbox Web Part!";

                SPListItem newItem = list.AddItem();

        newItem["Title"] = "New Log Result - " + DateTime.Now.ToShortTimeString();
        newItem["LoggingResult"] = logResults;


        lbl.Text = "Logged Result: " + logResults;



     protected override void RenderContents(HtmlTextWriter writer)


When it comes to Silverlight or client-side code, choices for debugging are better, since we can use the tools built into Internet Explorer or Firefox to debug solution. Options in SharePoint online are not the same for debugging and hope this technique will help people looking for debugging approach

May 1, 2014 · Adi · No Comments
Tags: , , , ,  · Posted in: Debugging and Testing, SharePoint 2013, SharePoint Online

Leave a Reply

What is 14 + 10 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)