Archive for the ‘General’ Category

Building Windows Service using visual studio-C#

December 5, 2013 Leave a comment

Hi All,
Here I come back again and this time with Windows Service and related things. 🙂
In my carrier I had came across this stuff several times and always thought of writing something on this but unfortunately it always got skipped and went out side of the bucket.
Anyways here I start with:
Windows Service is an windows utility which keeps running behind the screens silently but sometime violently. As this utility runs behind the screen hence its obvious this has nothing to do with the UI, forms or any other cosmetic works.

  • So, how to build it?

Well building an win.service basically one needs to have 2 things:
1. Windows Service Class: Accommodates the code for which the service is written
2. Installer Class: For installing the service

Open visual studio 2010 (the steps are almost same since from ages!) & create an project , while doing so choose the WindowsService Template under the winodws header of your intended programming language.
More details can be retrieved from MSDN, CodeProject

Installing / Unistalling Window Service

      1. Windows service can be installed by firing installutil from the visual studio command prompt – Details on MSDN
      2. Alternative for the installutil is to make use of System.Configuration.Install assembly

using System;
using System.Collections.Generic;
using System.ServiceProcess;
using System.Configuration.Install;
using System.Reflection;
namespace WinService
static class Program
static void Main(string[] args)
if (Environment.UserInteractive)
string parameter = string.Concat(args);
switch (parameter)
case "--install":
ManagedInstallerClass.InstallHelper(new[] { Assembly.GetExecutingAssembly().Location });
case "--uninstall":
ManagedInstallerClass.InstallHelper(new[] { "/u", Assembly.GetExecutingAssembly().Location });
ServiceBase[] servicesToRun = new ServiceBase[]
new Service11()
#region Commented Code -- default code
//static void Main()
// ServiceBase[] ServicesToRun;
// ServicesToRun = new ServiceBase[]
// {
// new Service11()
// };
// ServiceBase.Run(ServicesToRun);

    1. For Deployment purpose we can make use of the installer package as mentioned in these articles MSDN, Torben M. Philippsen
Categories: .NET, General Tags:

Add properties to visual webparts sharepoint 2010

November 7, 2013 Leave a comment

This post talks on how one can add custom properties to their SharePoint 2010 visual webparts. Microsoft has brought visual webparts for easing the developer life with SharePoint 2010 development. But when it comes to adding some custom properties for these webparts then there is bit of trouble hidden.
To troubleshoot this issue lets us dive in entities inside webpart project.

  • Inside the webparts folder of the project one can see following files (considering webpart name as “VisualWebPart1”):
  1. Webpart class “VisualWebPart1.cs” that is derived from webpart class
  2. User control file “VisualWebPart1UserControl.ascx” and its associated designer and .cs files

Since we think that merely writing the property and setting its attributes to WebBrowsable=true & Personalizable inside the usercontrol class (VisualWebPart1UserControl.ascx.cs) file will go ahead and add properties into webpart, but in reality this will not work.
So how we gonna do this?
Even though the above assumption of ours is true but its partially true. The fact is, before adding this property to user control class we should

Invoke SSRS reports from ASP.NET and or sharepoint webpart application by passing parameters

October 22, 2013 Leave a comment

Hi All,

After a good long break getting back to what like to 🙂
In this post I’m planning to take you through the execution of SSRS reports from an ASP.NET application, now what is so great about this (simple its my first post after long break 🙂 ) because we will see how to pass parameters to the report. And these reports are bit special/unique because they are driven by an SSAS cube.
Ok so not to waste more time…
Here is the code for doing so:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;

namespace MyWebApp
public partial class DummyReportViewer : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
if (!Page.IsPostBack)
_reportViewer.ProcessingMode = ProcessingMode.Remote;
// Report Server URL
_reportViewer.ServerReport.ReportServerUrl = new Uri(“http://%5Bservername:portnumber%5D/ReportServer/”);
// Report Name
_reportViewer.ServerReport.ReportPath = “/[reportpath]/[rdl_file_name]”;
// set true to show report parameters else false
_reportViewer.ShowParameterPrompts = true;
_reportViewer.ShowPrintButton = true;
// Below code demonstrate the Parameter passing method. User only if you have parameters into the reports.
Microsoft.Reporting.WebForms.ReportParameter[] reportParameterCollection = new Microsoft.Reporting.WebForms.ReportParameter[4];
reportParameterCollection[0] = new ReportParameter(“prmUniversityZone”, @”[DIM Zone].[Zone Hierarchy].[Zone NM].&[All]”);
reportParameterCollection[1] = new ReportParameter(“prmEducationStream”, @”[DIM Education].[Education Hierarchy].[Stream DSC].&[Engineering]”);
reportParameterCollection[2] = new ReportParameter(“prmPeriod”, @”[DIM Time PERIOD].[Period Hierarchy].[Year DSC].&[2009]”);
reportParameterCollection[3] = new ReportParameter(“prmResult”, @”[DIM Result].[Result Hierarchy].[Result NM].&[All]”);


Ok so what in case of multiple values for a single parameter. So in that case instead of sending string of parameter value pass an string array of multiple values.

//instead of single parameter as:
reportParameterCollection[2] = new ReportParameter("prmPeriod", @"[DIM Time PERIOD].[Period Hierarchy].[Year DSC].&[2009]");

//create an string array of Year and pass it:
string[] years = new string[] { “2008”, “2009”, “2010”, “2011”, “2012” };
reportParameterCollection[2] = new ReportParameter(“prmPeriod”, years);

You may ask how do I extract this information of parameters. The simple is open the report goto parameters, open its property and check for Default Values in it. You will know what is required to be passed to the report parameter.

One more thing this is applicable to ASP.NET as well as SharePoint web part application

Following could be helpful resource for reports related stuff:


Categories: General Tags: , , ,

Packt’s Microsoft Carnival!

May 15, 2012 Leave a comment

Brighten your May at Packt’s Microsoft Carnival! Exciting discounts on Microsoft books/e-books throughout May 2012!

Categories: General Tags:

Sharepoint 2010 powershell references

February 2, 2012 Leave a comment
Categories: General Tags:

Log files and TextWriterTraceListener

February 1, 2012 2 comments

Writing a log file using TraceListner classes its just one more way of writing logs..  🙂

private int Logger(Exception exObj)
using (Stream myFile = File.Exists(“TestFile.txt”) ? File.Open(“TestFile.txt”, FileMode.Append) : File.Create(“TestFile.txt”))
/* Create a new text writer using the output stream, and add it to * the trace listeners. */
TextWriterTraceListener myTextListener = new TextWriterTraceListener(myFile);
// Write output to the file.
Trace.Write(“\r\n Test output \r\n”);
Trace.Write(“\r\n Test output \r\n”);

// Flush the output.

Trace.Listeners.Remove(myTextListener); // this is very important else you may encounter error wrt file/stream/trace object
return 0;

Categories: General Tags: , ,

Get dataset from xml document using XmlNodeReader

February 1, 2012 1 comment

Hi, many times we need to read an xml file and get it in either dataset or datatable. This is ok till we directly use dataset.readXML method, but what when we just need to read specific nodes (infact elements) and then create dataset/datatable out-of it? (quite tricky right)

The answer is create an XmlNodeReader object and get the required element (node) into it either by traversing the xml document or by firing a simple (yet powerful) XPath Query on to the document.  The below sample explains the same by making use of Xpath Query.

private void btnGetData_Click(object sender, EventArgs e)
//Create xmlnode and xmlElement for xpath
XmlNode xmlNode;
XmlElement root = doc.DocumentElement;

// xpath expression //List[@Name=’Lotus Machines’]
xmlNode = root.SelectSingleNode(txtExpression.Text);

DataSet dataSet = new DataSet();
if (xmlNode.HasChildNodes)
for (int indexNode = 0; indexNode < xmlNode.ChildNodes[0].ChildNodes.Count; indexNode++)
XmlNode innerNode = xmlNode.ChildNodes[0].ChildNodes[indexNode];
using (XmlNodeReader reader = new XmlNodeReader(innerNode))
{// fill dataset from reader object as below 🙂

I would definitely like to hear from ur side if there is any other better way for so… till the bye bye  🙂