Tag | Csharp Posts

I was recently combing through my code and adding HTMLEncode()s where necessary. By the way, don't leave this to the end - you have no excuse since you're reading this post. The first thought that comes to mind to add this is simple, add a central function, perhaps a shared (vb) or static (c#) function to handle this. It'd likely look something like: Public Function HTMLEncode(ByVal s As String) As String Return If(Not String.IsNullOrEmpty(s), System.Web.HttpUtility.Html... s) End Function ...
Presentation by Anders Hejlsberg. It is 10 years later since they started C# C# 1.0 was about introducing the general concept of managed code. C# 2.0 was about finishing C# 1.0 but didn't have time to do. C# 3.0 is really about radical new thinking in the language - LINQ. They learned a lot about functional programming through this exercise. Today is about C# 4.0. Some of the trends that have shaped their thinking on C# 4.0. Declarative Dynamic - resurgence of dynamic programming languages Concurrent ...
In a new article on CIO.com Anders Hejlsberg tells next to a lot of other things how C# get's his name. Below a quote of the article: [CIO] Why was the language originally named Cool, and what promoted the change to C#? [AH] The code name was Cool, which stood for 'C like Object Oriented Language'. We kind of liked that name: all of our files were called .cool and that was kind of cool! We looked seriously at keeping the name for the final product but it was just not feasible from a trademark perspective, ...
This is part 1 of what I intend to be something of a recurring theme: how to avoid the use of dynamic controls in ASP.NET. Whilst dynamic controls have their uses in a small number of cases, they come with a significant amount of extra baggage. For example: * Dynamic controls need to be created early in the page lifecycle to participate in viewstate * Dynamic controls need to be re-created on each postback, and assigned the same control IDs to maintain viewstate * Extracting values from dynamic controls ...
Aha! New blog... I think I will start by posting the solution (or, rather, a solution), to a problem which has been troubling me for the best part of a day. To replicate the problem, simply download and run the AJAX Control Toolkit sample website, and navigate to the Reorder List sample page using IE7. You can drag and drop the list items, and all works as expected. Now go to the site's master page, and comment out the HTML DocType declaration at the top of the template markup, and run the ReorderList ...
The situation I have is this - I have a class defined as such: public class MyClass { public int TheInt { get; set; } public string TheString { get; set; } public MyEnum TheEnum { get; set; } } with 'MyEnum' defined as: public enum MyEnum { A, B, C, D } I have a Window that displays the data in such a way: <Window.Resources> <CollectionViewSource x:Key="SortedEnumView"> <CollectionViewSource.So... <ComponentModel:SortDesc... </CollectionViewSource.S... ...
With the aid of the Microsoft.BizTalk.ExplorerOM library found in "C:\Program Files\Microsoft BizTalk Server 2006\Developer Tools" you can write your own tool for administration of your Biztalk applications. With this API you can have a look at the installed applications, add applications and configure sendports and receivelocations and all other parts of the application. Start with declaring an object of type BtsCatalogExplorer and giving it the connectionstring to the Biztalk Management database. ...
The Goal Simulate a class using the Record type How we'll do this Create a tool that can translate a number into another format. In particular, we'll convert a number into Roman Numerals or multiply it by 10 Why are you doing this? No particular reason. I was just curious. I was just thinking that if F# did not support OOP, how can I still achieve the same things I was used to doing in C#? Ok so here we go.. F# record types are simple named types. We can pattern match over it and it is also constructed ...
Summary Extract your zip file in aspspider.net using OpenSource Zip Library in asp.net (SharpZipLib) .NET Classes used : using System; using System.IO; using ICSharpCode.SharpZipLib.Zip; I have used open source zip library. Which you have to download from http://www.icsharpcode.net/... Put ICSharpCode.SharpZipLib.DLL into your bin folder of asp.net application. Use Following function to extract zip file. Assign your zipfilename in ZipFileName variable. You Need Folder ...
When .NET 2.0 was released, a TryParse() method was added to many value types such as Int32, DataTime, etc. This was a huge improvement because there was no longer a need to catch expensive exceptions and drag down performance. However, one drawback of the TryParse() method is that the syntax is a little clunky. The most common example looks like this: 1: Person person = new Person(); 2: string value = "21"; 3: int num; 4: int.TryParse(value, out num); 5: person.Age = num; So it's great that we can ...
Several weeks ago (before the release of the CTP5 of MVC) I posted a way to leverage the EntLib Validation Application Block with MVC. Since then CTP5 has been released and this finally includes a mechanism for reporting validations. It is important to note that it does not include the mechanism for *how* to do validation but rather how to *report* validations. This is actually a great thing because, first off, it allows the flexibility to utilize whatever validation framework you please rather than ...
So I’ve been trying to do some custom build numbering for my Team Build project and was confronted with a lot of let’s say “uninformation” and some great information also. I really didn’t want to create a custom task that I would need to maintain so I set on a long search for the Truth… needless to say I didn’t find it. But here is the information I found that should get you you to the right place. There is a great custom task created by the MSBuild team that used to be on GotDotNet but is now MSDN ...
This post deals with 2-way binding of data to a CascadingDropDown. It assumes that the CascadingDropDown is already configured to return data to the list. I had my DropDownList and CascadingDropDown pairs within a FormView and it is bound to a SqlDataSource. < asp : Label ID ="Label1" runat ="server" Text ="Mfr" /> < asp : DropDownList ID ="ddlMfrs" runat ="server" /> < cc1 : CascadingDropDown ID ="cddMfr" runat ="server" TargetControlID ="ddlMfrs" Category ="MfrID" PromptText ="Select ...
I found this really cool library today. #usblib(SharpUSBLib) is a wrapper around the libusb project. If you need access to USB ports in your .NET applications you should check out this library here. I was successfully able to utilize this library to interface with my Motorola ROKR phone. Next step is to figure out how to write a Sync application using this library for my ROKR. Pretty cool library with lots of applications ...
Just in case you didn't know, XBox Live and the Creator's Club website are both down today. You can read the XNA team blog for more details. But all is not lost, you should have plenty to do in your spare time. One thing you could do is head over to XNAResources.com. That's right, they're back! And they're starting a new 2D tutorial series that looks like it's going to be an extremely useful set of tutorials for the community. (Welcome back guys! It feels good to be recommending your site again.) ...
I'm about to set up a new website, powered by DotNetNuke (my favourite CMS at the moment, mainly because it's free), and I want to install a Counter-Strike game server onto the same machine. I also want a little module that will show visitors to my site how many people are logged onto the CS server and some basic stats. Sounds simple right? The problem is that when Counter-Strike server is installed, the database name is generated at random. So I can't create a connection string that points to a ...
The jQuery Javascript library has gotten a significant amount of attention from Microsoft developers this year in large part to its nice fit with the new ASP.NET MVC framework. I myself was totally new to jQuery and I started using it with MVC because I wanted to see what the big deal was. Sure enough, I became a true believer like many others. And I found myself suddenly having "JavaScript envy" because I couldn't do all the cool jQuery stuff in traditional ASP.NET (i.e., non-MVC) web applications. ...
There are lots of times when I want to do a "Clean" of my VS.NET solution. Obviously, the most common way to do this is to right-click your solution in the solution explorer and select "Clean Solution". However, there are 2 drawbacks of this. One is that if you have files sitting in your bin or obj directories that are not in some way linked to your solution, they won't be removed. Additionally, sometimes you just want to do a quick clean of a directory structure without having to fire up VS.NET. ...
When using untyped messages on WCF operations we can take a more generic approach in creating services. The idea behind untyped messages is to create operations which take a parameter of which the type (and datastructure) is not known in the signature of the operation. This parameter is not a class you created and attributed with the DataContract attribute but it is the Message class found in the System.ServiceModel.Channels namespace. using System.ServiceModel.Channels; public interface IServiceInterface ...
I recently heard a question stating something along the lines of: "What is Boxing?" My initial thoughts were the classic example using an ArrayList, whereby storing a value type (int etc) is 'boxed' into an object so the ArrayList can contain it. But the question was followed up with: "Ok, so is this how you think passing a value by ref to a method works?" Personally I hadn't thought about that, I've used 'ref' on numerous occasions, but hadn't really considered how the CLR does this.... So. How ...
Recently I was asked to help out when we had a need to reduce the size of a directory of rolling backups. And when I say size, I am talking around 12GB a day backup sizes. This was already a compressed directory, but I found that if we zip up the folders, we can get even better compression (to the tune of 60+% more room). First note: Windows built-in zipping utility is not so good, it won't even try to compress anything that size. Instead it throws an error. Nice. Basically I started working with ...
A few days ago I posted a comparison of C# vs Ruby. So I thought what about adding some more populair programming languages to the graph. And what to we see below: c# 2.05 ruby 1.00 php 3.65 perl 0.75 java 7.65 The other languages (php, perl, java) has the same drops during the weekends as C#. Ruby on the other hand stays stable during the whole week. So can we say: That Ruby isn't very common language at 9-5 Mon-Fri jobs, so it more used by hobbiest then by professionals. Ruby programmers can't ...
Here was a little issue that caused some frustration. I have an app with an UpdatePanel and inside that are two Textboxes each with their own RequiredFieldValidator. Both Textboxes had AutoPostBack set to True. Also each used an OnTextChanged event to trigger some checks from the code behind. The issue was after entering a valid value in Textbox1 you could not tab directly to Textbox2. When you hit the tab key the cursor would blink once in Textbox2 and then disappear. If you kept hitting tab the ...
Check out my new live search component to the right here -> I came across this on Heather Solomon's blog, thought it was cool so had a play and set one up for my blog. To start with get yourself over to http://search.live.com/site... select the advanced option. I think it only works if you have your blog on a custom domain like blog.steveclements.net as www.geekswithblogs.net/stev... doesn't work. I also created a live search macro for geekwithblogs.net and used and existing one for msdn ...
WCF Durable services are WCF services in which the operations can remember the values of private variables (=the state of the service) inbetween restarts of the serivcehost and/or client. This is new in .NET 3.5 and the concept goes beyond the idea of .NET 3.0 WCF sessions. In WCF sessions the service keeps the content in a session environment which is not persisted by default, this means that the service can only remember the data as long as it is running. When the service is down, the data is lost. ...
After discovering some pretty significant serializaton issues in the code base, and approximately 0% testing of the implementation of ISerializable, I've been spending the last couple of days writing tests for the serialization... I've been using the following code to do the serialization, easy to use: MyObject m = new MyObject("Test"); Assert.IsTrue( m.Equals( Serialization.SerializeAndD... m ) ) ); Of course, this uses the 'Serialization' class, which is defined below! using System.IO; ...
More of a note really, but lets (for example) say we've defined a Contract for our Managed Addin Framework (MAF): [AddInContract] public interface ISimpleCalc : IContract { double Add(double x, double y, params double[] theRest); } if we use the PipeLineBuilder to generate the Pipeline for us, we'll find the contact defined in our 'AddInView' and 'HostView' projects as: public interface ISimpleCalc { double Add(double x, double y, double[] theRest); } Which is obviously a problem as we're expecting ...
There are always a lot of posts about various add-ins, code snippets, macros, and other utilities that are designed to make you, the developer, more productive within Visual Studio as an editing environment. However, there seem to very few posts that talk about how to actually improve the performance of Visual Studio itself. Browsing through some of the questions on Stack Overflow, I came across a thread asking this very question. There were a lot of non-answers, but one that definitively listed ...
Generics are a great way of getting code reuse. However there are a few things that can make them difficult to work with. Generics are similar to C++ Templates in the way you define them, but are very different in the way they work. This series of articles is planned to explore Generics in detail by example. Most of the online references to Generics that I have found are always dealing with collections. We all know that collections are a great way to use generics. However, it's a bit tougher to spot ...
Silverlight makes working with videos pretty straight forward, Microsoft makes Silverlight pretty straight forward with ASP.net and sharepoint is written in ASP.net, so match made in tech heaven!! I wanted a video player web part for sharepoint, that had some simple functionality like play, pause and volume. I started with expression encoder which output a nice media player interface...this is OK, but has a couple of restrictions; 1, its far to rich for what I wanted, animations all over the place ...
So often in the managed world we're able to get away with not worrying about memory management. "But the GC takes care of cleaning my objects for me!" That's true; but if you want your application to be performant, you should at least understand what's going on in all of those circuits and silicon. In Part 2, I talked a bit about how creating object pools can help you to avoid garbage collections by keeping memory allocated for a long time. Here, I'm going to talk a bit more extensively about how ...
I've been using StructureMap for my dependency injection container for a little while now and I wanted to discover all the ways (I could find) to register my dependencies. Here's is what I came up with (If you know of more or see something wrong drop me a comment): I've got a project with a console app, a project for my dependencies (memento and concrete types), and a project that does my dependency registration (when I do it in code). My console app just gets the default concrete type first, then ...
Clearly MS hasn’t caught up with the third party tools that are out there? Which do you guys use? ReSharper Refactor! Pro C# Refactory Visual Assist X I've used Refactor!Pro on a previous project and liked it quite a bit. I assume a lot of these include the same basic features. Perhaps the difference is in the number of refactorings and additional features outside of refactoring. ReSharper seems to be the most widely used. But, does it give the most bang for your buck? Does it meet the needs of a ...
I've been building a handy little requirement importer for Quality Center. It will read a Word doc, and let you specify the paragraph you want to start, and boom! Pumps them in. The API is, of course, is COM-based. I decided to write my app in .Net, and for grins, chose C# as my language. For the most part, it's not been too tough to get it done, and the pain involved using Interop has been worth it given the power .Net puts in your hands. I gutted an old VB6 app I'd written in a hurry during a manual ...
Complexity issues raise from the the nature of properties of objects. Changes to one part of a system’s design may affect multiple other parts in terms of privacy, refer to database developer company. A service and its clients agree on the interface between them, but are otherwise independent. Lock statement of C# is in fact a syntactic shortcut for a call to the methods Monitor.Enter and Monitor.Exit wrapped within a try-finally block. One of the biggest problems with waterfall is that it pushes ...
The question from my previous post was: how do I validate a Product Key from a Wix Setup? The answer has many components. First, you have to create a dialog for your product key in Wix. This dialog should have some sort of formatted input (say, a repetition of six 4-letter groups). It should also have some sort of validation. Next, you need to have a custom action that will validate the key. It’s very important for this custom action not to be obvious to crack. Wix is very easy to modify as is, if ...
QuickCode.Net has a new free 2008 version. UPDATE: in a new release 3.0.6. it's possible to assign any shortcut key. In VS 2008 Customise keyboard I've selected command QuickCode2008.AddIn.Replace... and assigned a shortcut key Alt-Q. It uses <TAB> instead of previously assigned Alt-Q hotkey. <TAB> is consistent with standard VS snippets. If you press the TAB key after your QuickCode, e.g. tc<TAB> the QuickCode will expand. If the same pattern exists in snippets and QuickCode, ...
I just installed Resharper 4 (www.jetbrains.com) on my dev machine, and aside from the usual hints etc, there are some new ones, most notably the way it asks to insert a const string locally, for example: private void ShowMessage() { string msg = "Hello!!"; Console.WriteLine( msg ); } ReSharper suggests should be replaced with: private void ShowMessage() { const string msg = "Hello!!"; Console.WriteLine( msg ); } Now, I've never done that in my code in the past, but, presumably there is some performance ...
Despite "The Cost of Premature Optimization", it's useful to know how things work so you can do basic things to avoid bad performance. In the end, the example below is trivial and doesn't have a significant effect on performance (at least as it applies in my application). However, knowledge of IEnumerable and yield can come in handy when it really counts. As I was writing a bit of code, I wondered if order matters when it comes to query expressions. Specifically, I have an enumerable that I was applying ...
Following on from this. I've noticed that it only gives you to the second accuracy. If your software is capable of making more than one file per second, the sort order will be date/time to the second then alphanumerically on the filename. Not ideal if your filenames are guids, the following class gives date/time sort accuracy of 100 nanosecond intervals then alphanumerically on filename :- 1: Imports System.IO 2: Imports System.Runtime.InteropServices 3: Imports System.Runtime.InteropServi... ...
So there I was -- another day of writing slick AJAXified custom SharePoint web parts. This was a simple one. A series of dropdowns that cause subsequent dropdowns to be re-populated with increasingly restrictive data. Planet Continent Country etc. But, when I changed the planet choice to be "Earth" the continent choice DID populate with the continents on earth but it caused a complete page round trip -- not the smooth AJAXified action I expected. Plus, my UpdateProgress panel wasn't being displayed ...
Badly named Loading Circle PT2 ---------------------------... So, in my last post (http://geekswithblogs.net/... I created a square LoadingCircle UserControl, using old skool WinForms multi-threading in the code behind file, and Xamly fun on the front end.. But there were problems (of course there were), firstly, the animation, whilst it *did* move, was a very 'on/off' affair, i.e. the Ellipse was ...
One of the best things about LINQ to SQL is that is really does have solid support for stored procedures. However, it's not quite as friendly as dynamic LINQ to SQL with scalar values because you can't take advantage of anonymous types. Instead you must return an actual known type. Furthermore, this can't be a primitive so you can't return string or bool directly. You also can't use a class that doesn't have a default (parameterless) constructor so that also rules out nullable types like Nullable<bool>. ...
In response to a comment on one of my previous posts (Safely Overriding Equals), I've decided to post some comments about Extension methods in general. A friend asked me what I gained out of extending string to convert to an enum. He asked, "is it just 'syntactic sugar'?" The simple answer is, "Yes." In fact, this is true of many extensions. Clearly, the major advantage of extensions is changing the syntax of how they are called. In fact, I have written a few extensions that support chaining and ...
This is how to reduce the number of characters displayed in a blog post on the default.aspx page of a blog site created from the OOTB SharePoint blog template. Open up the site in SharePoint Designer Open the default.aspx and switch to Code View Perform a Find & Replace for the following: Find- &lt;Field Name="Body"/&gt; Replace- &lt;Limit Len="99" IgnoreTags="TRUE" MoreText="..."&gt;&... Name=&quot;Body&quo... This would limit the ...
UPDATE: The component controller was removed from the MVC framework before the RTM release. For an updated version of this post, click here. At some point when creating a web app, you're going to want some reusable UI components. This might be because you want the same visual UI snippet repeated more than once on a single page or it might be because you want to use the same component on multiple pages. In a traditional ASP.NET web app, typically you would use a User Control for this type of thing. ...
Overview of to Enterprise Library Logging Application Block and Alternatives Loren Halvorson's comparision of the Enterprise Library Logging & Instrumentation Application Block and Log4Net (Published in 2005) Comments on the EntLib/Log4Net feature and performance comparison (Published in 2005) EntLib v4 has a few performance improvements in Logging Block. Based on quick read I feel that Log4Net and NLog are simple and may be sufficient for small applications. But they seems do not support specifying ...
I’ve been spending the better part of two days doing this same process over and over. It doesn’t feel like I’m testing anything of value. I am not doing it in the C# 3.0ish way, but it is better to explain it that way. I have a class and a façade (MyFacade) that I want to extend and test. class Foo { public string Name { get; set; }}class MyFacade { public IMyDependency Depend { get; set; }}interface IMyDependency { IList<Foo> GetAllFoos();} So I write my test first like a good boy person should. ...
My earlier post on the Null Object pattern led to a few critiques about the fact that I was presenting an extension method to do what is essentially a very simple logical test, and, as a result, doesn’t provide much value. For reference, here is the original extension method from that post public static class NullObjectExtenstions { public static bool IsNull(this object source) { return (source == null); } } Yes, this is an extremely simple method and performs a very basic logical test. However, ...
My post on the Null Object pattern has generated some interesting dialog. One of the trends that I have seen is the idea that defensive programming means your code should fail as early as possible. I couldn’t agree less. According to Wikipedia, Defensive programming is a form of defensive design intended to ensure the continuing function of a piece of software in spite of unforeseeable usage of said software. The idea can be viewed as reducing or eliminating the prospect of Murphy's Law having effect. ...