background preloader

C#

Facebook Twitter

Regular Expression Language - Quick Reference. Dot Net Perls: C# String Enumerations in C# Introduction The idea of string enumerations in C# (and the lack thereof), has bothered me for a while.

String Enumerations in C#

Enum's are useful things but only allow the storage of numeric types. What if you want to use strings? Background It struck me that I had a number of requirements when using string 'constants'. I wanted the ability to define the values in-line and reference them like an enum value - e.g. Options Constants The first thing I naturally gravitated towards was constants defined in a specific class. Public sealed class MyConsts { private MyConsts() {} public const string Val1 = "MyVal1"; public const string Val2 = "MyVal2"; public const string Val3 = "MyVal3"; } The constants can be easily accessed as MyConsts.Val1 etc. Constants do have an interesting side effect in that the values are actually copied to any client code that uses the class.

Static readonly readonly values can be initialized with a value and changed only within a class's constructor. Enums StringEnum Using the code Points of interest. How-To Program with Microsoft Office Excel and C# using a Ribbon and Interop. In the previous example (How-To program with Excel and C#), I demonstrated how to program in Excel 2007 using a Workbook Project in Visual Studio 2008.

How-To Program with Microsoft Office Excel and C# using a Ribbon and Interop

This example will use the Addin Project in Visual Studio 2008 to create a ribbon that can be inserted into any Excel file automatically. Getting Started If you are familiar with VS2008, start by creating a Microsoft Office 2007 Excel Addin Project. If you don't have the 2007 Office VSTO templates, you can download them from the Microsoft Download site. NetOffice - MS Office in .NET. Garbage collection  .Net is the much hyped revolutionary technology gifted to the programmer’s community by Microsoft.

Garbage collection 

Manyfactors make it a must use for most developers. In this article we would like to discuss one of the primary advantages of .NET framework -the ease in memory and resource management. Every program uses resources of one sort or another-memory buffers, network connections, database resources, and soon. C# - Calling null on a class vs Dispose() Joe Duffy's Weblog.

Smart Card Tools

WMI Code Creator v1.0. <a id="b7777d05-f9ee-bedd-c9b9-9572b26f11d1" target="_self" class="mscom-link download-button dl" href="confirmation.aspx? Id=8572" bi:track="false"><span class="loc" locid="46b21a80-a483-c4a8-33c6-eb40c48bcd9d" srcid="46b21a80-a483-c4a8-33c6-eb40c48bcd9d">Download</span></a> The WMI Code Creator tool allows you to generate VBScript, C#, and VB .NET code that uses WMI to complete a management task such as querying for management data, executing a method from a WMI class, or receiving event notifications using WMI. Details The WMI Code Creator tool generates code that uses WMI to obtain management information or perform management tasks.

You can use the tool to learn how to manage computers using WMI scripting and WMI .NET. The tool generates code that runs on the local computer, a remote computer, or a group of remote computers based on your selection from the Target Computer menu on the tool. NLog – Advanced .NET Logging. System.Data.SQLite: About. User Account Control. User Account Control dialog in Windows 7 when loading unsigned code User Account Control dialog in Windows 7 when loading signed code User Account Control (UAC) is a technology and security infrastructure introduced with Microsoft's Windows Vista and Windows Server 2008 operating systems, with a more relaxed[1] version also present in Windows 7, Windows Server 2008 R2, Windows 8, and Windows Server 2012.

User Account Control

It aims to improve the security of Microsoft Windows by limiting application software to standard user privileges until an administrator authorizes an increase or elevation. In this way, only applications trusted by the user may receive administrative privileges, and malware should be kept from compromising the operating system. In other words, a user account may have administrator privileges assigned to it, but applications that the user runs do not inherit those privileges unless they are approved beforehand or the user explicitly authorizes it.

History[edit] Features[edit] See also[edit] Using UAC with C# – Part 1. User Account Control (UAC) is a new technology introduced by Microsoft in Windows Vista and most of the time it is misunderstood by users and developers.

Using UAC with C# – Part 1

It’s main purpose is to protect the operating system by running applications with reduced privileges. Why should we use this? Most applications DO NOT require full privileges. Think to the applications you have written and ask yourself if most of the job can be done without full writes (if you write to disk think if you could write in the user’s folder or an isolated storage, if writing in registry to HKLM think if you could write to HKLU, etc). The answer is mostly sure “Yes”. So why run applications with full privileges when they can be run with limited?

There are two mistakes developers tend to do: By design UAC can only elevate code at process level and only at process’ startup (means that a running process cannot be elevated). There are two types on UAC dialogs: blue and yellow. Using UAC with C# – Part 2. In part 1 of this tutorial I have presented how to run an application with and without elevation by specifying this from another process.

Using UAC with C# – Part 2

However there are some situations when an application cannot be run without administrative rights. For example a system configuration utility requires administrative rights to change some global policies. In order to force an application to run only if the current user is administrator or can provide administrative credentials you must add a manifest to the C# project. The manifest is an XML file named <application_name>.exe.manifest with the following content: What is important is the requestedExecutionLevel element.

The default value of requestedExecutionLevel if it is not specified in the manifest or the manifest does not exist is asInvoker. In order to embed the manifest in the aplication’s executable you can choose one of the following options: Using UAC with C# – Part 3. After a long period since I wrote part 2 of this article I decided to add some extra information.

Using UAC with C# – Part 3

There is one thing that was missed by the previous two articles: the design of UAC enabled applications. If you use Windows Vista/7 then you know that buttons and links which elevate privileges are preceded by a shield icon. This is the way Microsoft decided to inform the user about the effect of clicking that control. The first idea that might pop up is the reinvention of the wheel (or shield). In other words you could draw the shield on a button. Is not easyWill require you to recompile the interface if Microsoft decides to change the iconYou need the icon in many sizes 16×16, 24×24, 32×32, etc. The second method is easier, safer and recommended by MS. ClickOnce.

Installation of a ClickOnce application ClickOnce is a Microsoft technology that enables the user to install and run a Windows-based smart client application by clicking a link in a web page.

ClickOnce

ClickOnce is a component of Microsoft .NET Framework 2.0 and later, and supports deploying applications made with Windows Forms or Windows Presentation Foundation. It is similar to Java Web Start for the Java Platform or Zero Install for Linux. Description[edit] The core principle of ClickOnce is to ease the deployment of Windows applications. System.Deployment.Application Namespace () Check for updates programatically. ClickOnce provides two ways to update an application once it is deployed.

Check for updates programatically

In the first method, you can configure the ClickOnce deployment to check automatically for updates at certain intervals. In the second method, you can write code that uses the ApplicationDeployment class to check for updates based on an event, such as a user request. The following procedures show some code for performing a programmatic update and also describe how to configure your ClickOnce deployment to enable programmatic update checks. Managed Windows API. .NET OpenPGP.