.net

Determine file type of an image

I'm downloading some images from a service that doesn't always include a content-type and doesn't provide an extension for the file I'm downloading (ugh, don't ask). What's the best way to determine the image format in .NET? The application that is reading these downloaded images needs to have a proper file extension or all hell breaks...

What is the difference between const and readonly?

What is the difference between const and readonly and do you use one over the other? ...

.NET serialization class design problem

We have a rather large object graph that needs to be serialized and deserialized in a lot of different ways (modes). In some modes we want certain properties to be deserialized and in some we don't. In future modes it might also be possible that there are more options for properties than yes or no. The problem is now how we implement the...

Cross platform .Net?

If you were to write an GUI application that runs locally and calls a webservice, to be cross platform, can you do it with .Net, what tools would you recommend? I was considering Java as it would be relatively easy to pick up due to its C# similarity and then I could use the JVM. ...

What is the best way to parse html in C#?

I'm looking for a library/method to parse an html file with more html specific features than generic xml parsing libraries. ...

WCF, ASP.NET Membership Provider and Authentication Service

I have written a Silverlight 2 application communicating with a WCF service (BasicHttpBinding). The site hosting the Silverlight content is protected using a ASP.NET Membership Provider. I can access the current user using HttpContext.Current.User.Identity.Name from my WCF service, and I have turned on AspNetCompatibilityRequirementsMode...

IPC Mechanisms in C# - Usage and Best Practices..

I have used IPC in win32 code a while ago. [Critical sections, events & semaphores] How is the scene in .NET enviroment? Are there any tutorial explaining all available options and when to use and why? ...

Context.User losing Roles after being assigned in Global.asax.Application_AuthenticateRequest

I am using Forms authentication in my asp.net (3.5) application. I am also using roles to define what user can access which subdirectories of the app. Thus, the pertinent sections of my web.config file look like this: <system.web> <authentication mode="Forms"> <forms loginUrl="Default.aspx" path="/" protection="All" timeout="360" ...

Are non-generic collections in .NET obsolete?

Put differently: Is there a good reason to choose a loosely-typed collection over a type-safe one (HashTable vs. Dictionary)? Are they still there only for compatibility? As far as I understand, generic collections not only are type-safe, but their performance is better. Here's a comprehensive article on the topic: An Extensive Exam...

Create drop down list options from enum in a DataGridView

I currently have a class and I'm trying to create an easy GUI to create a collection of this class. Most of the attributes of this class are strings. However, one of the attributes I want the user to be able to set is an Enum. Therefore, I would like the user interface, to have a dropdownlist for this enum, to restrict the user from ent...

.Net arrays with lower bound > 0

Although perhaps a bizare thing to want to do, I need to create an Array in .Net with a lower bound > 0. This at first seems to be possible, using: Array.CreateInstance(typeof(Object), new int[] {2}, new int[] {9}); Produces the desired results (an array of objects with a lower bound set to 9). However the created array instance can n...

Will .NET MVC give me the HTML/CSS/JS separation I need?

I'm working with my ASP.NET development team to try and create "better" (i.e. cleaner) HTML when rendering pages. At the moment, .NET has a nasty tendency to do things like dump JavaScript into the page, making it a mandatory requirement on form controls and not allowing forms to work when JS isn't available. In some instances, we're s...

C#: Is there any difference between bool? and Nullable<bool> ?

In C# are the nullable primitive types (i.e. bool?) just aliases for their corresponding Nullable<T> type or is there a difference between the two? ...

What is the best way to convert between char* and System::String in C++/CLI

What is the approved way to convert from char* to System::string and back in C++/CLI? I found a few references to marshal_to<> templated functions on Google, but it appears that this feature never made the cut for Visual Studio 2005 (and isn't in Visual Studio 2008 either, AFAIK). I have also seen some code on Stan Lippman's blog, but it...

how to convert from prtime to .net datetime

I want to convert a number that is in PRTime format (a 64-bit integer representing the number of microseconds since midnight (00:00:00) 1 January 1970 Coordinated Universal Time (UTC)) to a datetime. note that this is slightly different than the usual "number of millisecconds since 1/1/1970" ...

How do I access performance counters from C# in Windows XP Embedded?

I have an application running under Windows XP, and I'm accessing the Processor and Memory performance counters. When I try to run the same code and access them on XP Embedded, the counters don't seem to be present. They are present in the image - I can see them all in perfmon. What's the missing piece here? ...

Custom Counter Creation Through Web Application

I have a .NET 3.5 web application for which I have implemented a class called CalculationsCounterManager (code below). This class has some shared/static members that manage the creation and incrementing of two custom performance counters that monitor data calls to a SQL Server database. Execution of these data calls drives the creation...

Best way to query disk space on remote server

I am trying to nail down free space on a remote server by querying all the drives and then looping until I find the drive I am seeking. Is there a better way to do this? Dim oConn As New ConnectionOptions Dim sNameSpace As String = "\\mnb-content2\root\cimv2" Dim oMS As New ManagementScope(sNameSpace, oConn) Dim oQuery As System.Man...

How to call the AllocateAndInitializeSid function from C#?

Can somebody give me a complete and working example of calling the AllocateAndInitializeSid function from C# code? I found this: BOOL WINAPI AllocateAndInitializeSid( __in PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, __in BYTE nSubAuthorityCount, __in DWORD dwSubAuthority0, __in DWORD dwSubAuthority1, __in DWOR...

Starting a new job focused on brownfield application refactoring & Agile

I am starting a new job on Monday. The company has a home grown enterprise case management application written in ASP.NET/VB.NET. They are attempting to implement an Agile development process. They have gone so far as to get two people Scrum Master certified and hire an Agile coach. They are currently focused on 6-9 months of refactoring...