Tag | Csharp Posts

When designing a Windows 8 app, you need a way to preserve the state of various items as you navigate from page to page. Windows allows this using the pageState dictionary - a dictionary that can contain any serializable object. If you're a web programmer, you can think of this as similar to using a session variable. Today I'll add this to the cascading ListBoxes shown earlier. You can download the code for that project at ListBoxDrillDown.zip. First, we'll add a navigation button to the page. Put ...
When you're dealing with hierarchical data (a tree-like data format such as folders that have sub-folders that have subfolders, etc.) you have to come up with an organized way of displaying it. You could create a tree view, similar to how Windows Explorer displays folders, but I wanted to try something different in Windows 8 - cascading ListBoxes. The user selects an items in a ListBox, and then a new ListBox appears to the right showing the sub-categories. This continues as long as there's data ...
Previously I wrote a post on how to get the eBay category list using their .Net SDK. I wanted to try doing the same thing in a Windows Store App for Windows 8 using Visual Studio 2012, but quickly ran into compatibility problems since the DLLs are compiled for .Net 2.0. I could have either changed the targetted framework, or attempted to re-write the DLLs, but neither sounded particularly exciting, so I simply decided to fall back to using a simple URL request and parsing it via Linq to XML. As mentioned ...
eBay offers a .Net SDK for its Trading API - this post will show you the basics of making an API call and retrieving a list of current categories. You'll need the category ID(s) for any apps that post or search eBay. To start, download the latest SDK from https://www.x.com/developer... and create a new console app project. Add a reference to the eBay.Service DLL, and a few using statements: using eBay.Service.Call; using eBay.Service.Core.Sdk; using eBay.Service.Core.Soap; ...
Even though this may be a relatively common task for many people, I’ve had to show it to enough new developers that I figured I’d immortalize it… MSDN says “Events enable a class or object to notify other classes or objects when something of interest occurs. The class that sends (or raises) the event is called the publisher and the classes that receive (or handle) the event are called subscribers.” Any time you add a button to a Windows Form or Web app, you can subscribe to the OnClick event, and ...
If you have a GridView that uses BoundFields but does not display line breaks or a lot of spaces quite right here is a way to get around that. This example uses a GridView with one BoundField that uses a DataField of comments. The comments are stored in a database and entered from another page which displays the comments properly in a textbox with all the spaces and line breaks you intended. The trick to get a BoundField to show those items is to take the item and replace the \r\n with a <br /> ...
This post is pretty specific to an issue I had but still has some ideas that could be applied in other scenarios. The problem I had was updating a few buttons so their Text values could be set in the code behind which had a method to grab the proper value from an external source. This was so that if the application needed to be installed by a customer using a language other than English or needed a different notation for the button's Text they could simply update the database. Most of the time this ...
Recently I ran into an issue where the paging text in a RadGrid control needed to be customizable. In my case I was specifically looking at the "Page size" and "xx items in yy pages" text. Getting around it for the "Page size" was a snap. If your RadGrid is called rgTest one line would do it: rgTest.PagerStyle.PageSizeL... = "your text here"; The "xx items in yy pages" was a bit trickier, but still handled in one line of code. rgTest.PagerStyle.PagerText... = "{4} {5} things in {1} my pages"; ...
Here is an easy way to retrieve the user ID from who ever is logged on to a PC using ASP.Net. This is handy for ASP.Net applications where you want to put a "Welcome joe user" label at the top, auto populate a form with the user's ID or add the user ID to some data you are storing back into a database if you keep track of who edited a record last. The code below assumes you have an aspx page with two labels on it, lblFName and lblLName. It grabs the user ID with HttpContext and then splits the ID ...
This post is an example of how to write a WCF Service using a class. The example uses Visual Studio 2010, written in C#, SQL Server 2008 and hosted in IIS. So lets have at it. The table is pretty simple just three columns, an TestID (int), Value1 (varchar(50)) and Value2 (varchar(50)). The stored procedure used will return one record from the table using the TestID as a parameter. Table SQL: CREATE TABLE [dbo].[Table_1]( [TestID] [int] IDENTITY(1,1) NOT NULL, [Value1] [varchar](50) NOT NULL, [Value2] ...
A sample demonstrates the PGP Encryption/Decryption in pipelines. You can download code here. A sample is based on a sample by Brian Jones See original code here The main additions to original code: · Single pipeline component was separated to two Encrypt and Decrypt pipeline components. It simplifies the pipeline configurations. · Configuration parameters are stored in SSO, which, I hope, improves security. · File names for temporary files are regenerated randomly each time. That eliminates errors ...
Here is one way to access a control in a GridView right after a user clicks a button to change from view to edit mode. This example shows a TextBox that gets populated with today's date. The GridView is setup like this:<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="TestID" DataSourceID="SqlDataSource1" onrowdatabound="GridView2_R... > <Columns> <asp:TemplateField> <ItemTemplate> <asp:Button ID="btnEdit" runat="server" Text="Edit" ...
Everyone has an opinion. When you embark upon your first real job as a programmer you will find this out very quickly. I have found that software developers can be some of the most opinionated and dogmatic people you will ever meet. This certainly is not a bad thing. However, young programmers will need to cultivate the ability to make their own minds up when it comes to how to write software. There are those who start out in a corporate environment where the styles and conventions used have already ...
I have been looking into InRule, a business rule management system (BRMS) from InRule Technology, recently and thought I would do an intro blog on it. I have worked with business rule engines before and from past experience have developed my own list of priorities on what I feel are the most important aspects. Here they are… Priority 1 - Reduce the cost of change For me, one of the primary reasons for implementing a business rules engine is because you are expecting change and want to reduce the ...
In the last installment I discussed delegates, which have been in C# since version 1. The problem with delegates in some cases is that having to create separate, named methods to describe the function to be performed can be a bit unwieldy in cases where the method being called is simple and will not be used other than by the delegate invocation. This brings us to a feature added in C# 2.0 – anonymous methods. Anonymous methods distilled down to their most simple explanation are methods that are defined ...
Sitecore has a powerful event pipeline infrastructure that you can leverage to plugin commands into various item creation, change, move, publish etc events. Recently I had to add functionality to Sitecore so that when an items version is created all fields from a target language are copied into the newly created version to ease editing. To do this first we add an event handler in the Web.Config file for the versionAdded event. <event name="item:versionAdded"> <handler type="MyNamespace.MyClass, ...
This is another x64 issue where I was really surprised that it does exist. When you compile in VS2010/MsBuild a managed target for which the corresponding serialization assembly is generated you will find that all works until you try to compile for 64 bit. There you will get: "SGEN : error : An attempt was made to load an assembly with an incorrect format: xxxx.dll." Here is the 32 bit SGen is called for the 64 bit target which cannot load a 64 bit assembly. I have no idea why MS did not provide ...
In my previous post we started a discussion about concepts that are critical to really understanding LINQ. The next couple of posts will build on the same theme by introducing three very closely related (and somewhat evolutionary) pieces of the C# language – delegates, anonymous functions, and lambdas. My original intent had been to introduce them together in single post, but that would be a rather long post. Delegates are a language feature that have been in C# since version 1 of the language and ...

I was recently made aware of a couple of people having issues with WCF services (or ASP.NET applications) when using the MVVM Light project template for Silverlight. There is a blog post and a StackOverflow question, so what exactly is happening there?

Read the rest of this entry »

I’ve been putting a lot of thought lately into how LINQ can be introduced to programmers whose C# skills range from being a fairly new programmer conversant in C# to a seasoned programmer who learned just what they needed to convert skills in another language to C# and the .Net platform and I think that a workable approach would be to introduce first some of the concepts and language features that I view as existing to enable LINQ and then tie them together. The first step we’ll take towards learning ...
My friend in Zimbabwe sent me an email a day ago with the following contents suppose i have a table called week_days with only 3 fields i.e. SEQUENCE DAY SALES as follows: SEQUENCE DAY SALES 1 Sun 23 2 Mon 18 3 Tue 30 4 Wed 15 5 Thu 20 6 Fri 08 7 Sat 0 i need a query that converts DAY column to a header row and sort by SEQUENCE as follows: DAY Sun Mon Tue Wed Thu Fri Sat SALES 23 18 30 15 20 08 0 Pliz Help!!!!!!!! I was like’ this looks like a candidate for pivot, but it requires that the result ...
Note No poker players where harmed during the making of my poker bot. Origin and idea One of my pet projects was a poker bot. This poker bot worked on Pokerstars. It was able to play poker without human intervention. Unfortunately it lost most of the time. The mouse movement was a issue with this bot. To avoid detection i wanted the mouse to move as humanly as possible. So no straight line and at normal speed. After searching on Google and grabing some ideas i have made some code to round the gathered ...
It’s pretty widely accepted (and common sense) that if you’re putting a site out into the wild – such a simple task as minifying CSS and JavaScript files can save a bunch of load time, especially on mobile devices. I’ve been playing about with this today and was quite happily using jsmin as described here until I noticed that in IE 7 and IE 8 the minified CSS didn’t work. The problem seems to be when using a background style, it takes out the space between the image url close bracket and the next ...
Threading was never so easy since .NET 4 with the TPL has been released. I know I am a bit late but there are so many nice things which might still be new to many of us. The IEnumerable interface has become famous with the introduction of LINQ but many of us have not yet realized that IEnumerable<T> and T[] or List<T> can be exchanged in many cases but there are cases where it is important to fall back to a pure IEnumerable<T> if you want to support lazy evaluation. .NET 4 has for ...
I have had a total of 2 years, 3 months, 2 hours of Windows Azure developer experience and it humiliates me to suicidal extents to confess that I am hardly conversant with the platform’s native Diagnostics technicalities. “I am Tinu Thomas and I am a diagnostic-ignorant Azure Developer.” Oh my god…how could he?? Now that we have that past us <sheepish grin>, I would also like to bask in the afterglow of redemption. Thanks to a much-needed job transition phase, I was able to find enough time ...
Today I thought I would just list a little tutorial on how to make an RSS feed reader in C#. The code is very simple… public class RssFeedReader { public IEnumerable<Post> ReadFeed(string url) { var rssFeed = XDocument.Load(url); var posts = from item in rssFeed.Descendants("item") select new Post { Title = item.Element("title").Value, Description = item.Element("description")... PublishedDate = item.Element("pubDate").Value }; return posts; } } public class Post { public string PublishedDate; ...
MVC 2 provides a GREAT feature for dealing with enumerable types. Let's say you have an object with a parent/child relationship and you want to allow users to modify multiple children at the same time. You can simply use the following syntax for any indexed enumerables (arrays, generic lists, etc.) and then your values will bind to your enumerable model properties. 1: <% using (Html.BeginForm("TestModelP... "Home"))2: { %>3: <table>4: <tr><th>ID</... ...
Problem this code does not work Type t = typeof(ESRI.ArcGIS.Framewor... System.Object obj = Activator.CreateInstance(t); but yet this code Type t = Type.GetTypeFromCLSID(typeo... System.Object obj = Activator.CreateInstance(t); Reason In the first variant the runtime tries to cast to AppRefClass . This is not possible. And in the second one, the runtime does not knows anything about AppRefClass. So it leave it as IUnknown. (originally communicated ...
Today I was looking for a solution to get finally the JScript/Javascript/jQuery Intellisense Featureworking with my ASP.Net Webform Project to work. I found some good articles: - JScript IntelliSense Overview- JScript IntelliSense: A Reference for the “Reference” Tag- Enabling JavaScript intellisense in VS.NET 2010 to work with SharePoint 2010- Rich IntelliSense for jQueryBUT, all of suggested solutions did not work right with my Master Page based Visual Studio 2010 Solution.Only with physical Javascript ...
I recently was going over a great book called “Dependency Injection in .Net” by Mark Seeman. So far I have really enjoyed the book and would recommend anyone looking to get into DI to give it a read. Today I thought I would blog about the first example Mark gives in his book to illustrate some of the benefits that DI provides. The ones he lists are Late binding Extensibility Parallel Development Maintainability Testability To illustrate some of these benefits he gives a HelloWorld example using DI ...
In this Issue: Michael Washington, Oliver Fuh, Jeremy Likness, Derik Whittaker, Jesse Liberty, Jeff Blankenburg(-2-), and Michael Crump. Above the Fold: Silverlight: "Handling Extremely Large Data Sets in Silverlight" Jeremy Likness WP7: "31 Days of Mango | Day #8: Contacts API" Jeff Blankenburg LightSwitch: "LightSwitch Chat Application Using A Data Source Extension" Michael Washington Shoutouts: Michael Palermo's latest Desert Mountain Developers is up Michael Washington's latest Visual Studio ...
UPDATED March 24th 2016: Test Data Retention is now added to TFS 2015 Update 1, see this post for more information.UPDATED Apr 15th 2013: Corrected to VS2012 Update 2 UPDATED Mar 23rd 2012: Added information about VS 11 UPDATED Mar 21st 2012: Added info and link to VS/TFS 11 tool for getting the Test Attachment Cleaner, now included with the TFS Power Tools UPDATED Mar 17th 2012: Added sql queries for TFS 11 Beta. Changed structure after Adam’s advices. Updated information. UPDATED Jan 9th 2012: ...
Introduction Microsoft recently released the Kinect for Windows SDK Beta 2. It contains many enhancements and fixes that can be found here. The only problem with it is that a lot of current demo applications no longer function properly. Today, I’m going to walk you through a typical scenario of upgrading a Kinect application built with Beta 1 to Beta 2. Note: This tutorial covers WPF, but you can use the same techniques for WinForms. 1) Fix the references Let’s start with a fairly popular Kinect ...
Today is the big day, the day I attempt to use Ajax in the app… I’ve never done this (well, tell a lie, I’ve done it in a ‘tutorial’ site, but that was a while ago now), so it’s going to be interesting.. OK, basics first, let’s start with the @Ajax.ActionLink Right, first stab: @Ajax.ActionLink("Click to get latest", "LatestEntry", new AjaxOptions { UpdateTargetId = "ajaxEntrant", InsertionMode = InsertionMode.Replace, HttpMethod = "GET" }) As far as I’m aware, I’m asking to get the ‘LatestEntry’ ...
Today we had an interesting problem with file copying. We wanted to use xcopy to copy a file from one location to another and rename the copied file but do this impersonating another user. Getting the impersonation to work was fairly simple, however we then had the challenge of getting xcopy to work. The problem was that xcopy kept prompting us with a prompt similar to the following… Does file.xxx specify a file name or directory name on the target (F = file, D = directory)? At which point we needed ...
Here you will find a sample java program to generate sparse ARFF file. The following italic text text has been taken from: http://www.cs.waikato.ac.nz... Sparse ARFF files are very similar to ARFF files, but data with value 0 are not be explicitly represented.Sparse ARFF files have the same header (i.e @relation and @attribute tags) but the data section is different. Instead of representing each value in order, like this: @data 0, X, 0, Y, "class A" 0, 0, W, 0, "class B" the non-zero ...
I decided it was time to share some of my favorite tools and tricks that I use to make my time in Visual Studio more productive. Naming Standards If you do not already know the name and website IDesign.net, then I suggest you explore them and get to know them well. This is the architecture and design site started by Juval Lowy and now has such .NET architects as Michele Leroux Bustamante, Brian Noyes, Mark Michaelis, Dino Esposito, Miguel A. Castro. I had the luxury of seeing some of their presentations ...
Problem A continuous integration server should only have a minimal toolset installed. This ensures that no unwanted libraries could affect the build and other steps. Clearly that with this slogan also StyleCop should not be installed to the CI server. But we wanna have this analysis as an part of the whole build. Solution Prerequisites First at all we need the necessary files from StyleCop (the core assemblies and the target). The easiest way is to download the MSI of StyleCop, install the software ...

Problem

When using xUnit and constructs like Debug.WriteLine the DbgView-tool does not show the written output anymore.

Solution

Add a new Listener – for example:

Debug.Listeners.Add(new DefaultTraceListener());
Here is a technique to bind a List (of objects) to a DataGridView so that the public Properties appear as columns. In this example, the columns are binded to the individual public property of the object. The column Random Number is binded to the public property RandomNumber while the column Square Root to the public property SqRt. Create a class that contains the public properties that appear as columns in the dataGridView 1: using System; 2: using System.Collections.Generic; 3: using System.Linq; ...
In this Issue: Michael Washington, WindowsPhoneGeek, Jeremy Likness, Mike Taulty, Erno de Weerd, Jesse Liberty, Derik Whittaker, Sumit Dutta, Asim Sajjad, Dhananjay Kumar, and Avi Pilosof. Above the Fold: Silverlight: "Using Jounce Navigation to Create OOB Child Windows in Silverlight 5" Jeremy Likness WP7: "Video on How to work with WCF Services in Windows Phone 7" Dhananjay Kumar Metro/WinRT/WIndows 8: "Development Tip – Tab Control" Avi Pilosof LightSwitch: "Connecting To A .CSV or Excel File ...
In trying to comparing complex objects to confirm a unit test, I thought rather than going through the hassle of trying to implement IComparable or overriding .Equals that perhaps reflection would be a better means. A quick google search turned up some useful code that compares via reflection. This was close to what I wanted but I thought it’d be better to have it available as an extension method and I needed it in vb.net (excuse the horror) so this is what I came up with: <System.Runtime.Compiler... ...
So I am new to TDD and have been enjoying the ride of learning a new approach – today I came across an interesting situation that I thought I would blog about. I was writing a class that had all sorts of string manipulation in it. I needed some helper methods that would extend my string manipulation abilities. I had read somewhere that I should avoid static methods when doing TDD so I wrote the initial helper class to look something like this… public class StringHelper { public string ReverseStringEx1(string ...
Intro If you want to test the internals of a productive assembly you must mark the assembly with the InternalsVisibleTo-attribute. This attribute has only one constructor which needs the name of the testing assembly. http://msdn.microsoft.com/e... So this looks like: [assembly: InternalsVisibleTo("Unlinke... Visual Studio and 3rd party plugins uses the string to mark referencing ...
So, I want potential clients to have to enter the least amount of info possible to get an account, to that end, I really don’t see the benefit of a username and email address, I’d rather just use the email address. Pretty easy, edit the Register.cshtml to remove all traces of a ‘username’ field… Edit the controller so that it now reads: model.UserName = model.Email; if (ModelState.IsValid) { /*...*/ } F5 and … no Hmmm, turns out the ModelState isn’t valid, and that’s down to the fact that I’ve left ...
Structurally, I have 3 projects, the site, the EF database and the randomizer. The randomizer uses entities from the EF database, so all is good on that front. So, first cut, add a method to my Controller called Randomize, which takes in one of the EF entities: public ActionResult Randomize(TableB tableB) { /*...*/ } I’ve even given it an [HttpPost] attribute, now, I’m not anyway sure this is right, time will tell right? Anyhews, simple method: [HttpPost] public ActionResult Randomize(TableB tableB) ...
1: var daysOfWeek = new[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; 2: var workDays = daysOfWeek.Except( new []{ "SUNDAY", "SaTURdaY"}); // Performs a case sensitive search and yields Sunday,Monday - Saturday. 3: workDays = daysOfWeek.Except(new[] { "SUNDAY", "SaTURdaY" },StringComparer.OrdinalIgn... // Performs a case insensitive search and yields Monday-Friday The except operator takes a comparer that tells it how to evaluate the two lists. Nice one ...
In this Issue: Michael Crump, Kevin Dockx, Ollie Riches, Shawn Wildermuth, Kunal Chowdhury, Beth Massi, Joost van Shaik, Colin Eberhardt, Tony Champion, David Catuhe, Igor, Jeremy Likness, and Dhananjay Kumar. Above the Fold: Silverlight: "SL5 PivotViewer Custom DetailPaneStyle" Tony Champion WP7: "Taking screenshots with Windows Phone 7 applications using a video feed" Joost van Schaik LightSwitch: "“I Command You!” - LightSwitch Screen Commands Tips & Tricks" Beth Massi Metro/WinRT/Windows8: ...
In this Issue: Michael Washington, Ollie Riches, Jesse Liberty, Peter Torr, Jeremy Likness, Derik Whittaker, WindowsPhoneGeek, Morten Nielsen, Michael Crump, Asim Sajjad, Andrej Tozon, Dhananjay Kumar, Laurent Bugnion, and Avi Pilosof. Above the Fold: Silverlight: "Using Visual States to Set Focus on a Control" Jeremy Likness WP7: "Background Agents" Jesse Liberty Metro/WinRT/Windows8: "Adding an Application Bar to your XAML Metro Applications." Michael Crump Metro/WinRT/Windows8: "Using The Silverlight ...
ASP.NET view state, in a nutshell, is the technique used by an ASP.NET Web page to persist changes to the state of a Web Form across postbacks. View state has caused the most confusion among ASP.NET developers. When creating custom server controls or doing more advanced page techniques, not having a solid grasp of what view state is and how it works can come back to bite you. Web designers who are focused on creating low-bandwidth, streamlined pages oftentimes find themselves frustrated with view ...