Tag | C# Posts

Next week (17th March 2010) I am presenting on EF4 at www.devweek.com in London (and Azure on the 18th). Today I wanted to get all the latest bits on my demo machine and also check if there are any cool new resources I can point people at. Whilst most of the new improvements in Entity Framework come with the Visual Studio 2010 RC (and the RTM), there are a couple of separate items you need to install if you want to explore all the features. To demo EF4 you need: Visual Studio 2010 RC Download and ...
A C# class that makes it easier to download images from the web. Use the following code in your program to download image files such as JPG, GIF, PNG, etc from the internet using WebClient class. using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Net; public class DownloadImage { private string imageUrl; private Bitmap bitmap; public DownloadImage(string imageUrl) { this.imageUrl = imageUrl; } public void Download() { try { WebClient client = new WebClient(); ...
For those out there that are a little curious as to whether SAF is any use to your organisation, please read this FAQ. What is SAF ? SAF is free to use. SAF is the "SharePoint Action Framework", it was built by myself and Hugo (plus a few others along the way). SAF is written entirely in C# code, available from : http://saf.codeplex.com. SAF is a way to automate SharePoint configuration changes. An Action is a command/class/task/script written in C# that performs a unit of execution against SharePoint ...
In my previous example I have demonstrated how to create a simple form that would allow users to insert data to the database using L2S. In this example I’m going to demonstrate how to fetch and filter data from database and fill the fields in the form using L2S. This example is basically a continuation of my previous example here. So I would suggest you to take a look at my previous example first before you proceed reading this example. STEP 1: Setting up the GUI To get started, add a new WebForm ...
Few months ago, I’ve created a simple demo about “Creating a Simple Registration Form using the ADO.NET way”. In this article, I'm going to demonstrate how to create a simple form that would allows users to insert data to the database using L2S. As an overview, LINQ to SQL is a technology that allow you to query sql server. LINQ to SQL is an O/RM (object relational mapping) implementation that ships in the .NET Framework "Orcas" release, and which allows you to model a relational database using .NET ...
[You might want to also read other GuestPosts on my blog – or contribute one?] On the 26th and 27th of March (2010) myself and Edd Morgan of Microsoft will be popping along to the Scottish Ruby Conference. I dabble with Ruby and I am a huge fan whilst Edd is a “proper Ruby developer”. Hence I asked Edd if he was interested in creating a guest post or two for my blog on IronRuby. This is the second of those posts. If you should stumble across this post and happen to be attending the Scottish Ruby ...
[Switch to "Elastic Layout" to see this properly.] I get a lot of mileage using Web Services inside an intranet. I sometimes need to cross operating systems and languages to take advantage of pre-written services. One issue I've run across is the need to find the correct syntax in different languages that will generate a correct result. Some implementations are really easy and others require some delicate, precision work in order for them to respond correctly. Once written, however, they are consistent ...
Chunking a List As I mentioned last time, I'm knee deep in python these days. I come from a statically typed background so it's definitely a mental adjustment. List comprehensions is BIG in Python and having worked with a few of them I can see why. Let's say we need to chunk a list into sublists of a specified size. Here is how we'd do it in C# static class Extensions { public static IEnumerable<List<T>... Chunk<T>(this List<T> l, int chunkSize) { if (chunkSize <0) { throw ...
Surface is magic. Everyone using it seems to think that way. And I have to be honest, after working for almost 2 years with the platform I still get that special feeling the moment I turn on the unit to do some more work. The whole user experience, the rich environment of the SDK, the touch, even the look and feel of the Surface environment is so much different from the stuff I’ve been working on all my career that I am still bewildered by it. But… and this is a big but.. in the end we’re still talking ...
Table of Contents Introduction PE file format and COFF header COFF file header BaseCoffReader Byte4ByteCoffReader UnsafeCoffReader ManagedCoffReader Conclusion History This article is also available on CodeProject Introduction Sometimes, you want to parse well-formed binary data and bring it into your objects to do some dirty stuff with it. In the Windows world most data structures are stored in special binary format. Either we call a WinApi function or we want to read from special files like images, ...
Extension methods are a concise way of binding functions to particular types. In my last post, I showed how Extension methods can be created in the .NET 2.0 environment. In this post, I discuss calling the extensions from other languages. Most of the differences I find between the Dot Net languages are mainly syntax. The declaration of Extensions is no exception. There is, however, a distinct difference with the framework accepting excensions made with C++ that differs from C# and VB. When calling ...
Not that anyone would still need this, but in case you have a situation where the code MUST be .NET 2.0 compliant and you want to use a cool feature like Extension methods, there is a way. I saw this article when looking for ways to create extension methods in C++, C# and VB: http://msdn.microsoft.com/e... The author shows a simple way to declare/define the ExtensionAttribute so it's available to 2.0 .NET code. Please read the article to learn about the when and why and use ...

Thanks to everyone who attended my C# 4 presentation last night at Philly.NET.  Both the code and the PowerPoint can be downloaded here:  C# 4 New Features.

Download the Complete Battery Monitor Source Code I recently completed a series of articles on monitoring batteries in Windows XP. The link above allows you to download the complete project which includes six folders. The purpose of this article is to associate the folders with the articles. The folders that you will receive are: BatteryMonitor is the C# application and C# Win32_Battery class discussed in Windows XP: Displaying Battery Status in C Sharp and Windows XP: Monitoring Batteries in C Sharp. ...
Before I noticed how many other people had blogged about this same thing, I wrote an implementation of a "times" (integer extension) method -- the kind you'd find when coding in Ruby that is passed a block of code that it executes (n) times. Consider the following (in Ruby): ###########################... # prints: # Ruby was here # Ruby was here 2.times { printf("Ruby was here\n") } ###########################... # prints: # Ruby was here 0 # Ruby was here 1 2.times {|i| printf("Ruby ...
Download the Complete Battery Monitor Source Code See Windows XP: Overview of Battery Monitor Series for a description of the folder in the source code. This is article number 5 in a series of articles about monitoring batteries in Windows XP. In Windows XP: Monitoring Batteries in C Sharp I presented a C# class that can be used to get information about the system batteries. In Windows XP: Monitoring Batteries in C++ I presented a similar C++ class. Then in Windows XP: Displaying Battery Status in ...
Download the Complete Battery Monitor Source Code See Windows XP: Overview of Battery Monitor Series for a description of the folder in the source code. This is article number 4 in a series of articles about monitoring batteries in Windows XP. So far, I have presented a C# class (Windows XP: Monitoring Batteries in C Sharp), a C++ class (Windows XP: Monitoring Batteries in C++) and a C# (Windows XP: Displaying Battery Status in C Sharp) application. In this article, I will present three different ...
When Windows Azure was first released in 2008 the only programming languages you could use were .NET languages such as Visual Basic and C# and the applications you built had to run in Partial Trust (Similar to ASP.NET Medium Trust). In the interim we have made a number of changes including allowing applications to run in full trust, native code is now supported (no longer had to be managed code such as C#) and we support FastCGI applications. Which means: Windows Azure supports the Internet Information ...
[UPDATED 10th March 2010: Edd produced a 2nd post on using IronRuby with WPF/.NET ] [You might want to also read other GuestPosts on my blog – or contribute one?] On the 26th and 27th of March (2010) myself and Edd Morgan of Microsoft will be popping along to the Scottish Ruby Conference. I dabble with Ruby and I am a huge fan whilst Edd is a “proper Ruby developer”. Hence I asked Edd if he was interested in creating a guest post for my blog on IronRuby. If you should stumble across this post and ...
I am pleased to announce the next release of Axiom, v0.8.0.0 Beta 2. Get it here.
Come on that is easy: bool Equals(object other) compares all member variables of another object instance to the current instance. bool Equals(T other) does the same thing but expects an object of the same type than our self. This method is defined by the IEquatable<T> interface. int GetHashCode() calculates of the internal state of the current object a mostly unique identifier. Mostly because if you have more than 2^32 object states some values must collide. Most of the time you do not need ...
One of my major points of interest as a software developer is in the various tools that are available to make a developer’s life easier (or at least more interesting…). This is also a very important aspect for me in professional terms, because one part of my job lies in recommending suitable tools to my customers, implementing them and make them part of a developer team’s workflow. Thus, a well organized link collection is an important part of my assets and has a considerable business value for me ...
For those of you who like/use Facebook, I have created a Facebook Fan Page for the book. I’ll try and keep this page updated with information about what’s going on with the book. Technorati Tags: Books,Sams Teach Yourself C# 2010 ...
Probably my fault for not actually checking this sooner, but my upcoming Sams Teach Yourself Visual C# 2010 in 24 Hours book is available for pre-order on Amazon.com. Technorati Tags: Books,Sams Teach Yourself C# 2010 ...
Technorati Tags: ASP.NET,General I often see questions at forums(http://forums.asp.net) asking stuffs like: Where to begin? Where Do I start? How to Get Started? So I decided to write this "boring" post to express my opinion and hopefully this can help beginners find their way to get started with ASP.NET. Based on my experience learning ASP.NET is just like learning how to play a guitar.. (oh really? why could I say that? ).(1) First you must have this what we call "interest" because if you don't, ...
Last week, I needed to call the SQL Reporting Services Web Service to export reports as Excel, PDF, and Word formats. I could have used the [Add Web Reference...] as the MSDN Documentation Accessing the Report Server Web Service Using Visual Basic or Visual C#, but I decided to use [Add Service Reference...]. If you are wondering what the difference is between Web Reference and Service Reference, please read this blog post by Andrew Tokeley. Goal Create a common library project which I could reuse ...
I am very happy to announce that the core content for my upcoming Sams Teach Yourself Visual C# 2010 in 24 Hours book is done! I still need to incorporate comments from Claudio and Eric (my technical editors) and then incorporate edits from the Sams editors, but all of the really hard work is now done. Even though I knew before starting that it would not be easy I don’t think I was really prepared for just how difficult it is to actually write a book. I started actually writing around mid-July 2009, ...
Download the Complete Battery Monitor Source Code See Windows XP: Overview of Battery Monitor Series for a description of the folder in the source code. Earlier I promised applications that use the WMI Win32_Battery class to display battery status. I started this series of articles with C# (Windows XP: Monitoring Batteries in C Sharp) so I will start with a C# application. For those of you who know me, I am not a user interface developer and will leave fancy GUIs to those of you who are better than ...
Enumerated constants in C# can be represented 3 different ways: as a C# program constant as a number (typically int) as a string spelled identically to the C# constant Here a sample program demonstrating how to convert between any of these formats. using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication2 { public enum Color { red, white, blue } class Program { static void Main(string[] args) { string toString, fromString = "red"; int toInt, fromInt = 1; Color ...
Recently I was working on a project that had a large amount of roles that were going to be utilized on many different controllers and even on individual controller actions. Originally it was given to me utilizing the standard out-of-the-box way of Authorizing with MVC 1.0: //MVC’s standard authorize attribute [Authorize(Roles=”Administr... User”)] public class HomeController : BaseController { ... } I was told that role changes may occur in the future. This caused fear of the amount of work that ...
In this Issue: Tim Greenfield, Rene Schulte, Jianqiang Bao(-2-, -3-), Alex Knight, Shawn Wildermuth, John Papa and Adam Kinney, Josh Twist, Ning Zhang, John Stockton, and David Anson. Shoutout: Mike Taulty has added to his list of Silverlight 4 Beta Networking Videos, bringing the total to 11. I've got something like 50 posts to review, but some of you have figured out if you submit, you bump up in the queue. I'll get to everything, just thought I'd mention that :) From SilverlightCream.com: SuperStackPanel ...
LINQ as we all know provides intrinsic data querying capabilities to the framework languages supporting LINQ. Going forward its an obvious way to code clean, and with growing number of LINQ providers (LINQ to SQL, LINQ to Entities, LINQ to XML, LINQ for Maps, and not to forget DryadLinq and pLinq for us Cloudy folks’ Parallel Computing needs, and so on) it looks to be the de facto standard for querying within dotnet framework languages. Let us get acquainted to LINQ by taking a close look at the ...
Yesterday I picked up a nice package from TinyCLR.com. Yes, it is yet another robot (third in fact), but this time it runs .NET! How freaking cool is that! This robot is controlled by FEZ Mini board that runs .NET Micro Framework. What’s interesting is that this board has pin-out compatible with Basic Stamp from Parallax. You can also uses it easily on a breadboard for prototyping (just like Boarduino). TinyCLR.com also offers a larger board called FEZ Domino that has pin-out compatible with Arduino ...
After working with FluentNHibernate and seeing examples of registries in StructureMap, I started craving the same thing for my registrations with Windsor. Our registrations often look like the following: public static void Register(IWindsorContainer container) { container.Register(Componen... container.AddComponent<I... Foo>(); ... } There are a few things I don’t like about this approach: Passing a container around through static methods is a hack. ...
Download the Complete Battery Monitor Source Code See Windows XP: Overview of Battery Monitor Series for a description of the folder in the source code. This is the second in series of articles about monitoring batteries in Windows XP. In the first article, Windows XP: Monitoring Batteries in C Sharp, I showed how to use the Windows Management Instrumentation (WMI) to get battery status for multiple batteries using C#. Now what I didn’t tell you was that we found a potential bug in the .NET Framework ...
Since everyone else is getting in their final thoughts…I thought I’d jump on the bandwagon. For anyone who hasn’t been following me on Twitter or Facebook over the last week, I was fortunate enough to get the opportunity to spend a week in Redmond, Washington at Microsoft’s yearly MVP Summit. While “Twitterverse” (i.e. #mvp10) sometimes makes things sound like one big party it was actually a very fascinating week I was very proud to be involved with. I had never before had the opportunity to visit ...
I've been meaning to post this for a little while, and a recent post on the SSAS forum at ssas-info.com prompted me to finally get around to it. Basically the small Powershell script below will attach to the specified SSAS server and script all of the databases out to an XMLA file. In this example I also add a timestamp in the form of YYYYMMDD to the end of the file. $serverName = "localhost\sql08" $outputFolder = "C:\data\" ## load the AMO and XML assemblies into the current runspace [System.Reflection.Assembly... ...
Part 2 This is the first in a many-part series in which I will be writing about using YAML in the .Net space – particularly within C#. I will cover the whys, the hows, and show some tricks using the dynamic capabilities of C# when using YAML. I might even explore IronRuby a bit. Why YAML? I got the chance to sit in on four days of Ruby on Rails (RoR) training from Joe Obrien a few weeks ago. I hadn’t played with RoR in a few months, and this training was amazingly useful. I always like to see what ...
Last week, the Microsoft Visual Studio team released a new Visual Studio 2010 & .NET Framework 4 Training Kit that works with the Visual Studio 2010 Release Candidate. The training kit This includes 17 presentations, 22 Demos and 32 Hands-on Labs. I am also particularly excited to see content added for Visual Basic, as well as Office, SharePoint and Application Lifecycle Management! This kit is designed to help you learn how to utilize the Visual Studio 2010 features and a variety of framework ...
So you want to read a string (say, from a file or just passed in as a variable) into a .NET class. Here's a quick example of how to do this. Let's start with our sample JSON: {"FirstName":"Joe","LastNam... So to keep this simple, let's say we want to populate a class with this data. our class: public class Person { private string _FirstName; private string _LastName; private string _MiddleName; public string FirstName { get { return this._FirstName; } set { this._FirstName= ...
I ran into a situation where I was trying out WS-Discovery. you know the new WCF capability that allows you dynamically find services on your local network. Which would come in handy if say some company created software that ran on windows and hosted some services that could automatically link up with co-workers clients like windows phone and maybe even the plasma screen or microsoft surface computer? Well i ran into a little hiccup today where enabling the virtual network interface for Hyper-V on ...
If you like C# at all then you know that Jon Skeet (writings, blog, StackOverflow) is the man when it comes to this language. Just look at his StackOverflow flair!!! He is the top dude by a long shot in C# and has been for a long time. His latest book “C# in Depth 2nd edition” is currently available in the Manning Early Access Program (MEAP) and ready for you to get your hands on! $15 off C# in Depth 2nd edition: use code dotd0217 at checkout. http://manning.com/skeet2/ ...
One of the great new features in Visual Studio 2010 is the ability to now use code snippets inside of ASP.NET, HTML, and JavaScript files. Snippets have long been a productivity boost for regular C# code but have been sorely missing for mark up. In fact, frameworks like MVC 2 actually ship with their own snippets. There are only about 10-15 snippets that are currently shipping with MVC (and many of those are just duplicated because there are both VB and C# versions). That doesn’t seem like very many. ...
The main purpose of this post is to show what's required in the main 3 .net languages for filtering and sorting. I decided to put these two problems together because they presented themselves to me simultaneously . There are many instances where I need to Sort custom objects and many instances where I need to filter out duplicates from a list of custom objects. For filtering (Distinct), the effect happens with the framework finds unique values for the object. For the Sort, the default comparer will ...
These days, I’m doing a bit of end-to-end acceptance web testing using the Selenium framework. Selenium has a nice and handy add-on for the Firefox browser – the Selenium IDE. It automatically records your actions and produces the required C# code for you, as you click around in the browser window. But when I started the Selenium server and tried to run my first test (copied from the Selenium docs), it didn’t work (Sigh. It never works on the first try…) and I got a timeout and an exception. This ...
There are many times where I need to convert an array of data into a Dictionary or Hash table. If the key to be used in the new Dictionary is not unique, it is necessary to manage duplicates. I previously went through a lot of gyrations, but eventually setteled on the ILookup. ILookup is not perfect, but it beats some alternatives. Note this example (given the following structure): public static List<string[]> lst_arr_strData = new List<string[]>() { new string[] {"fred", "1"}, new string[] ...
After speaking in both Boulder and Fort Collins on parallel computing in the past couple weeks, I’m going to have the privilege of speaking in quite a few other places the rest of this month. Next Monday (Feb 15th), myself and 4 other MVPs will be presenting at the .NET Developers Association in Redmond, WA – we’re in town for the MVP Summit. Four rock star presenters and moi. It will be a touch group to live up to. Ted Neward has also promised to be in the back to heckle, so it ought to be quite ...
In this Issue: András Velvárt, Michael Washington, Frodeh, Damon Serji, Andy Beaulieu, Timmy Kokke, Jeff Wilcox, Jesse Liberty, and Michael Ceranski. Shoutout: John Papa and Glenn Block on Silverlight TV 7: When and Where to Use MEF Have you seen this at SilverlightShow? SilverlightShow with Brand New Book Shelf ... very nice job on that! Matthias Shapiro blogged an Introduction to User Experience (UX) Design Spinning out a new Show format and a new show, Erik Mork hosts This Week in Silverlight ...
Manipulating app.config attributes at run time in C# appears to be simple. However most of the samples I've looked at don't work or are impenetrable. Simply in app.config file at design time add some userSettings either manually or through the design window <userSettings> <WindowsFormsApplication... <setting name="MyMachine" serializeAs="String"> <value>zaxcc1Machine&... </setting> <setting name="MyMessage" serializeAs="String"> <value>Helpme</val... ...
I come from a C++ (and now C#) background. In both languages the index of the first item in a list is zero, so I like to stay consistent to that when working with other list (including blog post). In this series of blog post I'll be walking through different solutions for deployment scenarios for Windows Phones. This first solution is the "Hello World" of deployments. It will get your files copied to the programs folder and will create an icon in your start menu. I'll be ignoring all of the other ...