.net

How can I re-factor this code?

I'm using the following function to map columns from a DataTable (passed from the data tier) to object properties. The function exists within the class I'm populating. The class has two methods: Load() which loads the object with values and LoadAll() which returns a collection of populated objects. I wanted to be able to use the same cod...

Why can I not set this ACL rule in C#?

Running as an elevated admin on Vista SP1, my C# app tries to set the following rule with the following code. No error is produced, but neither is any change on the directory's ACL. What am I missing? public static void Main( string args[] ) { string dirPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonAp...

TcpListener: Listen on every address, including GPRS IP address

Hi, We have a simple piece of legacy software with which we need to communicate using TCP/IP over port 15001. We need to listen on port 15001 for the legacy software to make a connection and then read whatever it sends us. We have tested this solution accross the internet and it works just fine. If however we test the same solution acr...

What are the Differences between XSLT and the T4 Code Generation Methods?

I am just getting into the idea of code generation for repetitive coding tasks and have seen both of these approaches. I've seen the XSLT approach in an Apress book Code Generation in Microsoft .Net and have read about the T4 approach in relation to what's new in the MVC framework. What kind of projects is each method better suited for?...

Should we select VB.NET or C# when upgrading our legacy apps?

At the company where I work, we have a number of legacy apps written in Visual Basic 6.0. Without casting aspersions on the developers who wrote them, suffice it to say we have decided to rewrite the applications from scratch due to several compelling factors: 1.) Lack of documentation. 2.) Lack of exception handling. 3.) Lack of logg...

Print a 2-column report in .net

How do you create a report with 2 columns: Example: Student Name: Reyes JA Student Name: Reyes K Student ID: 2008-1000 Student ID: 2008-1000 Semester: First Sem, 2008-2009 Semester: First Sem, 2008-2009 Amount: 2000.00 Amount: 2000.00 ...

How to allow the user to add annotations to UI controls in WPF?

WPF document viewing controls that support annotations include FlowDocumentReader and FlowDocumentScrollViewer, as well as controls derived from DocumentViewerBase such as DocumentViewer and FlowDocumentPageViewer. The in-built Annotations support for Document based controls is awesome in WPF I was wondering how would it be possible to...

Does IEnumerable<TSource> Concat<TSource> preserve the order of elements?

Assume two lists, A and B so that A = (1,2,3) and B = (4,5,6). Will A.Concat(B) preserve the order so that the result is (1,2,3,4,5,6)? ...

MVC general class location

In the MVC folder structure, where should general class files reside? For example, I have a class that determines the right DataContext to use, so I'm not reinventing the wheel in each of my controllers. Should it live in the Controllers folder even though it's not a controller? Should it be with the Models because it's database related,...

What are the best resources to learn writing idiomatic c#?

I am looking for something like idiomatic ruby for c# programmers It should: be for people that can already programm be terse not be to basic just found a better thread for this question on stackoverflow: c-coding-standard-best-practices ...

Scheduled console app vs Windows service? When is it appropriate to use each

I just read this: http://stackoverflow.com/questions/442264/what-is-the-benefit-of-developing-the-application-as-a-windows-service but I'm still unsure of when to use a windows service. I have a couple tasks that need to be run at intervals (i.e. every 5 minutes). Which project type should I use? Are there any examples of the types of a...

Will #if RELEASE work like #if DEBUG does in C#?

In all the examples I've seen of the #if compiler directive, they use "DEBUG". Can I use "RELEASE" in the same way to exclude code that I don't want to run when compiled in debug mode? The code I want to surround with this block sends out a bunch of emails, and I don't want to accidentally send those out when testing. ...

ItemActivated event in WPF ListBox or ComboBox

Is there an ItemActivated event (like in Windows Forms) in the WPF ListBox or ComboBox controls? I can't see one. It seems crazy for there not to be some event doing the same kind of thing - so does it just go by another name? If not, is there another easy way to do it? I've seen various blog posts about this but they all seem to involv...

Can you explain the concept of streams?

I understand that a stream is a representation of a sequence of bytes. Each stream provides means for reading and writing bytes to its given backing store. But what is the point of the stream? Why isn't the backing store itself what we interact with? For whatever reason this concept just isn't clicking for me. I've read a bunch of...

Merge Datatable columns

Hi I have two data tables say: Table 1: name age ---- --- Bob 40 Table 2: auto kids ---- ---- 3 3 I want to merge the two tables to get something like name age auto kids --- --- --- ---- Bob 40 3 3 Is this possible? I tried merge but it does not seem to be working, thanks. ...

What's the easiest way to verify there's an available network connection?

Hi, I'm a bit of newbie to c#/.net development, but I've put together a stock tracking application for a small set of assets in my company. I have also set up the database it connects to in SQL 2000. It currently works brilliantly when a network connection is available, but I want to expand it for use when I'm away from a connection. ...

Global variable (or alternative) best practise in .NET

What's the best practise for storing global variables in a VB.NET WinForms app. For example when a user logs into an app you may want to store a CurrentUser object which can be accessed throughout the app. You could store this as an object in a module or create a class which contains members for all the required globals, you would still ...

Why isn't String.Empty a constant?

In .Net why is String.Empty read only instead of a constant? I'm just wondering if anyone knows what the reasoning was behind that decision. ...

How to use string for TcpClient in C# instead of byte?

In C# I try to send a string through TcpClient as such: byte[] outputOutStream = new byte[1024]; ASCIIEncoding outputAsciiEncoder string message //This is the message I want to send TcpClient outputClient = TcpClient(ip, port); Stream outputDataStreamWriter outputDataStreamWriter = outputClient.GetStream(); outputOutStream = output...

FF3 AwesomeBar-like behaviour in WPF

I'm trying to implement behaviour similar to the Firefox 3 AwesomeBar in WPF. I've got a ComboBox to use a DataTemplate that makes the dropdown look like the dropdown for the AwesomeBar, but I'm not sure how to get the right behaviour. What I want to happen is for the user to type their search into the TextBox bit of the ComboBox and th...