.net

TCPClient vs Socket in Csharp

I don't see much use of TCPClient, yet there is a lot of Socket? What is the major difference between them and when would you use each? I understand that .net socket are written on top of WINSOCK, and TCPClient is a wrapper over Socket class. Thus TCPClient is way up the chain, and possibly inefficient. Correct me if I am wrong. Than...

WPF: Swap entire View of a ListView

Is it possible to swap out the entire View of a ListView in Xaml using datatemplates? Looking for a way to allow the user to change how they view the data in a ListView and I'm hoping to stay within Xaml. I have found how to change the template of a single column/cell. A bit more detail of what I'm trying to accomplish: I'd like to ...

How to consume multiple WCF services from one client

I am still learning the whole WCF thing, so please bear with me here. What I have is two self hosted services created using C# and VS 2008: Service # 1 Adds two numbers and returns the result. Service # 2 Returns the square of a number. I want the client to be able to send in two numbers to Service 1, get the sum and then send the su...

Error while converting grid data to excel

This is the code : TextWriter writer = null; HttpResponse response = new HttpResponse(writer); response.ClearContent(); response.AddHeader("content-disposition", "attachment;filename=" + filename + ".xls"); // response.ContentType = "application/ms-excel"; StringWriter stringWriter = new StringWriter(); HtmlTextWriter htmlTextWriter =...

How would I modify this regex to extract the left and right hand parts of a UK postal code?

I have a regular expression which works for validating UK postal codes but now I would like to extract the constituent parts of the code and I'm getting confused. For those who do not know examples of UK postal codes are 'WC1 1AA', 'WC11 1AA' and 'M1 1AA'. The regular expression below (apologies for the formatting) handles the lack of a...

XmlTextReader - Does it lock the file?

This is probably a really simple thing, but I haven't been able to find it, and I'm probably just searching for the wrong thing... XmlTextReader --> Does it lock the file you're reading? I'm using reader.Read() and that's about it. ...

.Net Deploying application that use Excel

I develop an application that use the Microsoft.Interop.Excel version 11 in .Net 3.5 How could I deploy it to a machine that doesn't have Microsoft Office 2003 installed ? Did I absolutely need a full office license ? I hope no ... ...

How do I bind a Byte array to an Image in WPF with a value converter?

I'm trying to bind a Byte array from my databse to a WPF Image. My XAML: <Window.Resources> <local:BinaryImageConverter x:Key="imgConverter" /> </Window.Resources> ... <Image Source="{Binding Path=ImageData, Converter={StaticResource imgConverter}}" /> I've modified code published by Ryan Cromwell for a value converter: Class Bi...

changing to a different StreamWriter constructor causing bad output

I had this code StreamWriter sw = new StreamWriter(this.FileName, true); sw.WriteLine(text); sw.Close(); Which I changed to this (because of a contention issue): StreamWriter sw = new StreamWriter( new FileStream(this.FileName, FileMode.OpenOrCreate , FileAccess.ReadWrite, FileShare.Write) , Encod...

Why is Entity Framework taking 30 seconds to load records when the generated query only takes 1/2 of a second?

The executeTime below is 30 seconds the first time, and 25 seconds the next time I execute the same set of code. When watching in SQL Profiler, I immediately see a login, then it just sits there for about 30 seconds. Then as soon as the select statement is run, the app finishes the ToList command. When I run the generated query from M...

Constructor chaining with multiple calls

Given my code below, is there a way that the first WebTestingApp constructor can call the second before returning the new instance? I want to set some readonly fields in the constructor and, short of copy/pasting, I can't see how I can. I feel that the answer will have something to do with constructor chaining, but I can't figure out ho...

Static Generic Class as Dictionary

A static field in a generic class will have a separate value for each combination of generic parameters. It can therefore be used as a Dictionary<Type, whatever> Is this better or worse than a static Dictionary<Type, whatever>? In other words, which of these implementations more efficient? public static class MethodGen<TParam> { ...

Embed Python script

Hi, I have some Python Scripts which I would like to use from my VB.NET class library however instead of increasing the amount of files that I distribute is it possible to embed the script into my project/dll in Visual Studio and then run the script from the dll during my program runtime? Thanks for any help. Rob ...

base_convert in .NET

Does .NET have a native function that is equivalent to PHP's base_convert or will I need to write my own? I want to convert from any base to any other base -- where either the 'to' base or the 'from' base can be any integer 2-36. Example of the PHP function: base_convert($number_to_convert, $from_base, $to_base) // convert 101 from bin...

Best practices for error handling in a web service

I'm now toying around with WebServices, using the .NET framework (.asmx files, not WCF). I'm wondering what's the best practice to tell the user that some sort of business-error has happened in the method call. My small test-case: I have measuring probes which need to register with a central server. Each probe should have a different p...

Is there a way to ease the pain of maintaining .NET assembly references?

I'm currently working on a web project that involves several assemblies, structured something like this: WebProject | +--> A (external assembly, Version 1.0.0.0) | +--> B (external assembly, Version 1.0.0.0) The difficulty is that in order to keep track of what's deployed, I'd like to updated the version numbers of assemblies A an...

VBPROJ / CSPROJ

I'm trying to dig into the XML for a VBPROJ file. Does anyone know where I can find a good resource that explains the structure and attribute usage? ...

Large Object Heap Fragmentation

The C#/.NET application I am working on is suffering from a slow memory leak. I have used CDB with SOS to try to determine what is happening but the data does not seem to make any sense so I was hoping one of you may have experienced this before. The application is running on the 64 bit framework. It is continuously calculating and se...

IHTMLTxtRange, TextRanges and knowing if the text is visible or not

In a winforms application, I am using the IHTMLTxtRange interface (in c#) created from the body element to wander through the text on a page and process each word i come across using the MoveStart and MoveEnd methods.This works fine. I then need to know if the text would actually be visible to the end user - this is where i then start g...

Using HashSet in C# 2.0, compatible with 3.5

I really want to use hashsets in my program. Using a dictionary feels ugly. I'll probably start using VS2008 with .Net 3.5 some day, so my ideal would be that even though I can't (or can I?) use hashsets in VS2005, when I start using .NET 3.5, I don't want to have to change much, if anything, in order to switch to using these hashsets....