Saturday, December 29, 2012

CPU Usage Monitoring Tool

This tool displays CPU usage of each core of the computer separately. You can change settings by double click on the tool area.

.Net Framework 4.0 Required.
Download Link

Saturday, December 8, 2012

Allowing Only One Instance of an Application in Windows Forms C#

Standard Windows Forms applications can be launched multiple times and each instance used completely independently of the others. However, sometimes it is important to restrict the user in launching a single instance of a program.

The Process Class
The System.Diagnostics namespace contains a class namedProcess. This class contains functionality that allows interrogation of the processes that are currently executing in Microsoft Windows. The class can be used to determine if any other instances of an application are running and, if one is, a decision can be made to stop the current program.

Detecting Other Instances
To determine if another instance of a program is executing, twostatic methods of the Process class are used. Firstly, a call to the GetCurrentProcess method is made. This returns the current program's process details including its name within the returned object's ProcessName property.
Once the process name is known, the GetProcessesByName method can be used to return an array of Process objects with one representing each instance of the named software. This list includes the current program so if there is more than one element in the array there must be other running instances of the software.

Adding Detection to an Application
Using the two methods described, a simple test can be made within the Main method of an application. The following C# code demonstrates this by checking the number of matching processes and showing an error message if another instance is active. The method is then simply returned from to close the application. This is done before the main form of the application is loaded.

static void Main()
     // Detect existing instances
     string processName = Process.GetCurrentProcess().ProcessName;      
     Process[] instances = Process.GetProcessesByName(processName);
    if (instances.Length > 1)
             MessageBox.Show("This application is already running.");
    // End of detection Application.EnableVisualStyles();                
    Application.Run(new Form1());

Thursday, November 8, 2012

Add and Customize Pages permission not granted for SharePoint 2010 Contributors

SharePoint 2010 Contributor group doesn't have permission ''Add and Customize Pages". This permission is granted from designers and the above. This causes to error when try to adding webpart to the webpart page and customize webpart as a Contributor.

but the confusing part is OOTB webparts can be added and modified by the user who has contributor permission. When I search for that I found out that SafeAgainstScript=True in all the OOTB safe control entries. When we deploy WebPart using Visual Studio this SafeAgainstScript=False

Setting 'Safe Against Script' to false

This value is false by default which means SharePoint will not allow editing and configuration by site contributors.
If you want to continue to let a Web Part remain configurable, even bysite contributors, you can change the SafeAgainstScript attribute of the SafeControl declaration for that Web Part.


1. Add "Add and Customize page" to the contributor group or Create custom contributor group with    this permission
2. Make SafeAgainstScript=True in Safe controls of the WebPart

Saturday, August 4, 2012

Feed Reader Using C#

Feed Reader Using C#

.NET framework provides class called SyndicationFeed which is in defined in the System.ServiceModel.Syndication namespace. . The class is found in the System.ServiceModel.Web.dll assembly when using the .NET framework version 3.5 and in System.ServiceModel.dll for .NET 4.0 For both framework versions.

Add DLL to you application according to .NET Framework version.

Add Following declarative to your application

using System.ServiceModel.Syndication;
using System.Xml;

In order to read the feed, the XmlTextReader should be created and linked to the URL of the RSS or Atom feed. This can be achieved using a constructor that accepts the URL as a string parameter. The reader is then passed to the static Load method of the SyndicationFeed class. 

The following sample code loads the RSS feed for this web site:

XmlTextReader reader = new XmlTextReader( "feedurl");
SyndicationFeed feed = SyndicationFeed.Load(reader);

Once downloaded, you can extract the required information from the generated object. For example, the following outputs the title of the feed.


Use below link to find about class details

Using below code you can read each feed item.

foreach (SyndicationItem item in feed.Items)
    Console.ForegroundColor = ConsoleColor.White;
    Console.ForegroundColor = ConsoleColor.Gray;
    Console.ForegroundColor = ConsoleColor.Green;

Friday, July 13, 2012

SharePoint Property Bag

How to Add new item to property bag

                using (SPSite site = new SPSite("siteUrl"))
                    using (SPWeb web = site.OpenWeb())
                        web.AllowUnsafeUpdates = true;
                        web.AllProperties.Add("key", "value");
                        web.AllowUnsafeUpdates = false;

How to Read  property from property bag

                using (SPSite site = new SPSite("siteUrl"))
                    using (SPWeb web = site.OpenWeb())
                        if (web.AllProperties.ContainsKey("key"))