Skip to main content

Debugging SharePoint Code With a Console Application

 

Here is my SharePoint tip of the day. This is a helpful technique for debugging/testing SharePoint methods without having to fire up IIS. In my SharePoint code, I write my methods as public static methods that take an SPList or SPWeb object as a parameter. This may seem weird since you could just get these from SPContext.Current.Web. The reason for this is that this is a functional style programming technique where we don’t have class level variables. Instead the method takes in everything they need via parameters. The advantage of this is that I can write a console application and reference my SharePoint project and test my EventReceiver method (or Feature Receiver or WebPart or whatever) without having to deploy my SharePoint solutions, fire up IIS, etc. etc. It makes debugging and setting through code much quicker.  Of course once I have tested it in my console app, then I need to test it in the browser.

Sample Console Application. Note that I create my SPWeb object and list object using the non-SPContext way and pass them into my method which is contained in the referenced SharePoint project.

 

static void Main(string[] args)

{

try

{

   SPSite site = new SPSite("http://localdev/en-US/egs/contact/requestinformation");

   SPWeb currentWeb = site.OpenWeb();

   SPList ciList = currentWeb.Lists["CustomerInquiry"];

   SPList cirList = currentWeb.Lists["Customer Inquiry Routing"];

   SPList ciSettingsList = currentWeb.Lists["CustomerInquirySettings"];

   CustomerInquiryBL.Execute(cirList, ciList.Items[0], ciSettingsList, currentWeb);

}

catch (Exception ex)

{

   Console.WriteLine(ex);

}

Console.WriteLine("Press Any Key to Continue.");

Console.ReadKey();

}

Comments

Anonymous said…
Why not just use PowerShell?
Good point, using Powershell would be a great solution, which wouldn't require creating a new project etc.

I like your suggestion.
gaelynzalenski said…
Titanium Watch Review - The Titanium Master
This titanium trim reviews watch is a classic case from titanium necklace mens which you can wear titanium aftershokz your own face. The watch can be worn to watch a lot of sports and a lot columbia titanium boots of sports. camillus titanium Rating: 8.6/10 · ‎Review by TheTitaniumSports

Popular posts from this blog

How to Create and Run Tableau Bridge on Linux Containers

Tableau Bridge is now availble on Linux Containers. Yay! Now what does this mean and how do I build and run Linux Containers? We will discuss the advantages of running Bridge on Linux Containers the steps to build them, and finally, we will provide some automation script ideas for monitoring and scaling Linux Bridge agents. Tableau Bridge Today Until recently, Tableau Bridge was only available as a Windows application running on a Windows VM. It supported only one bridge agent per Virtual or Physical Machine. Advantages of Bridge in Containers Better Hardware Utilization: Linux containers are more efficient than Windows VMs, requiring only about 1/50th of the disk space. Ability to Spin Up Multiple Bridge Agents: With Linux Containers, it becomes easier to spin up multiple bridge agents on a single machine, improving scalability and resource utilization. Infrastructure Automation: Linux Containers enable easier automation of provisioning bridge agents and upgrading Tableau Bridge, the...

Unleashing Tableau’s Semantic Layer with AI Agents

⚡ TL;DR I helped built a tool that lets you query Tableau’s semantic layer  using natural language and AI. By integrating a LangChain agent with Tableau’s VizQL Data Service (VDS), we can repurpose Tableau’s trusted data model for conversational analytics . This means you can ask questions in plain English and get answers backed by the same definitions and security that your Tableau dashboards use. In this post, I’ll introduce this open-source agentic tool ( tableau_langchain ), why it’s transformative for analytics, and how it works under the hood. Why Connect LangChain Agents to Tableau? As a user of Tableau, I’ve seen how powerful Tableau’s semantic layer is. It encapsulates our organization’s business logic: things like predefined metrics, calculations, data relationships, and even row-level security rules. Traditionally, that semantic layer is only accessible through Tableau’s interface – you drag and drop fields to build a viz, and Tableau generates the query for you. Rece...

RAM Disks do not speed up Visual Studio

  The limiting factor for Visual Studio is disk IO. I got a tip to speed up Visual Studio from Channel 9 by creating a RAM disk which sounded like a great idea. However, when I ran a thorough set of tests, I found that the performance difference between the Ram disk and the hard disk were not appreciably different. This was a big surprise since RAM is 240,000 times faster than disk (see my previous blog post). But the reason is because Visual Studio and Vista do a lot of caching. So compile times for the same project in RAM disk and on hard disk were pretty similar. I also tested the time it took to search the entire solution for a word, and times to open a solution. There was no discernable difference!   If you still want to try it out and create your own RAM disk, you can download a simple RAMDISK.EXE utility to create a RAM disk in just a few minutes. What is a RAM Disk ?   Ramdisk is a virtual drive created in RAM.   Performance Analysis Creating f...