.net

.Net Data structures: ArrayList, List, HashTable, Dictionary, SortedList, SortedDictionary -- Speed, memory, and when to use each?

.Net has a lot of complex data structures. Unfortunately, some of them are quite similar and I'm not always sure when to use one and when to use another. Most of my C# and VB books talk about them to a certain extent, but never really go into any real detail. What's the difference between Array, ArrayList, List, Hashtable, Dictionary, S...

AJAX.NET Reorderlist Control - "It does not a DataSource and does not implement IList."

I keep getting this error when trying to re-order items in my ReorderList control. "Reorder failed, see details below. Can't access data source. It does not a DataSource and does not implement IList." I'm setting the datasource to a DataTable right now, and am currently trying to use an ArrayList datasource instead, but am discourage...

What is the most efficient way to save a byte array as a file on disk in C#?

Pretty simple scenario. I have a web service that receives a byte array that is to be saved as a particular file type on disk. What is the most efficient way to do this in C#? ...

Why is try {...} finally {...} good; try {...} catch{} bad?

I have seen people say that it is bad form to use catch with no arguments, especially if that catch doesn't do anything: StreamReader reader=new StreamReader("myfile.txt"); try { int i = 5 / 0; } catch // No args, so it will catch any exception {} reader.Close(); However, this is considered good form: StreamReader reader=new St...

Absolute URL from base + relative URL in C#

I have a base URL : http://my.server.com/folder/directory/sample And a relative one : ../../other/path How to get the absolute URL from this ? It's pretty straighforward using string manipulation, but I would like to do this in a secure way, using the Uri class or something similar. It's for a standard a C# app, not an ASP.NET one...

Does System.Windows.Forms have a non-static messagebox?

I would like something that I can use as follows var msg = new NonStaticMessageBox(); if(msg.Show("MyMessage", "MyCaption", MessageBoxButtons.OkCancel) == DialogResult.Ok) {....} But specifically non-static (I need to pass a reference to it around) does anyone know if/where such an object exists? ...

.NET Integer vs Int16?

I have a questionable coding practice. When I need to iterate through a small list of items whose count limit is under 32000, I use Int16 for my i variable type instead of Integer. I do this because I assume using the int16 is more efficient than a full blown Integer. Am I wrong? Is there no effective performance difference (however ...

A reliable HTTP library for .Net 2.0

.Net's implementation of HTTP is ... problematic. Beyond some issues in compliance with HTTP/1.0, what's bugging me right now is that HttpWebResponse.GetResponse() with ReadTimeout and Timeout set to 5000 blocks for about 20 seconds before failing (the problem is it should fail after 5 seconds, but it actually takes 20 seconds). I need ...

Network auto-disovery using SNMP and .NET

Are there any libraries, (third party is fine) that can help do network auto-disovery using SNMP and .NET? If not, have you ever rolled your own? ...

How do you determine whether or not a give Type (System.Type) inherits from a specific base class (in .Net)?

This is likely going to be an easy answer and I'm just missing something, but here goes...If I have a Type, (that is, an actual System.Type...not an instance) how do I tell if it inherits from another specific base type? ...

Can attributes be added dynamically in C#?

Is it possible to add attributes at runtime or to change the value of an attribute at runtime? ...

RDLC SubReports Exporting to Excel Are Ignored

I have a RDLC report which has a table, calling a subreport N times. This works perfectly in the control viewer and when I export to PDF. Yet when I export to Excel, I get the following error: Subreports within table/matrix cells are ignored. Does anyone know why this occurs only within the Excel export? And is there a workarou...

How to write the content of one stream into another stream in .net?

I often run into the problem that I have one stream full of data and want to write everything of it into another stream. All code-examples out there use a buffer in form of a byte-array. Is there a more elegant way to this? If not, what's the ideal size of the buffer. Which factors make up this value? ...

Restoring SplitterDistance inside TabControl is inconsistent

I'm writing a WinForms application and one of the tabs in my TabControl has a SplitContainer. I'm saving the SplitterDistance in the user's application settings, but the restore is inconsistent. If the tab page with the splitter is visible, then the restore works and the splitter distance is as I left it. If some other tab is selected, t...

Anybody know where I can get docs or tutorials on VSS 2005 Integration via .net.

I know that I can add the SourceSafeTypeLib to a project and can explore it in object browser and find obvious things (GetLatest, etc), but I am looking for some more thorough documentation or specific tutorials on things like "undo another user's checkout" or"determine who has a file checked out. If anyone knows where to find this mat...

GetElementsByTagName functionality from .net code-behind page?

I am writing a webpage in C# .NET. In javascript there is a function called GetElementsByTagName... this is nice for javascript invoked from the .aspx page. My question is, is there any way I can have this kind of functionality from my C# code-behind? -- The scenario for those curious: I used an asp:repeater to generate a lot of but...

How do you do a deep copy an object in .Net (C# specifically)?

I want a true deep copy. In Java, this was easy, but how do you do it in C#? ...

.NET EventHandlers - Generic or no?

Every time I start in deep in a C# project, I end up with lots of events that really just need to pass a single item. I stick with the EventHandler/EventArgs practice, but what I like to do is have something like: public delegate void EventHandler<T>(object src, EventArgs<T> args); public class EventArgs<T>: EventArgs { private T i...

Anyone know of a solid .NET Framework 2.0 installer script for Inno Setup?

I've spent a good part of the day searching, writing and finally scrapping a script that I can use with my Inno Setup install script that will download and install the appropriate .NET 2.0 Framework if needed. There are definitely a number of examples out there, but they: Want to install Internet Explorer if needed which I wouldn't da...

How to create a C# Login handler

How would I go about creating a web app login handler in C#? In Java I would use a JSP that posts the username and password to a servlet, which then delegates to a POJO - for the db lookup and validation. If validation fails the servlet forwards onto the login.jsp for another attempt, if successfull then forwards to the secure resour...