.net

How do I get a list of local Windows users?

I'm trying to write a faster user switching app for Windows. Win+L and selecting users is very cumbersome. If I start Task Manager as administrator, it shows active users and I can select one and "Connect" (if I enter their password). How do I get the list of all users (or all active users)? I'm using C# (Visual Studio Express). ...

What's the strangest corner case you've seen in C# or .NET?

I collect a few corner cases and brain teasers and would always like to hear more. The page only really covers C# language bits and bobs, but I also find core .NET things interesting too. For example, here's one which isn't on the page, but which I find incredible: string x = new string(new char[0]); string y = new string(new char[0]); ...

Multiple deletions using LINQ (more specifically Linq2Nhibernate, but...)

Is there any smart way to do this? If using Linq2Nhibernate, you really seem to have to rely on HQL or the likes to do multiple deletes from a database (without loading up and deleting one by one)? It doesn't seem like Linq2Sql have it either? I just want something that can do stuff like: DELETE FROM Accounts WHERE amount < 1000 Any...

How to tell if .net app was compiled in DEBUG or RELEASE mode?

I have an application installed on my computer and I need to find out if it was compiled in DEBUG mode or not? I've tried to use Reflector, but it does not show anything specific. Here is what I see: // Assembly APPLICATION_NAME, Version 8.0.0.15072 Location: C:\APPLICATION_FOLDER\APPLICATION_NAME.exe Name: APPLICATION_NAME, Version=8....

How to automatically register an HttpHandler required by a web server control?

In ASP.NET, when building a web server control in a class library that includes an HttpHandler is there a way to automatically register the handler without having to manually edit the web application's web.config file? I have a class library that contains a CompositeControl. In the composite control I have an Image control with a ImageU...

How do you determine if an Internet connection is available for your WinForms App?

What is the best way to determine whether there is an available Internet connection for a WinForms app. (Programatically of course) I want to disable/hide certain functions if the user is not connected to the Internet. ...

Where does Visual Studio get the type description info used by Intellisense?

Where do the type/member/parameter descriptions that you see in the Intellisense bubble come from? Are they stored in type attributes? EDIT: I'm specifically interested in the built-in types. ...

Adding spaces between strings

Hi, What's the best way of adding spaces between strings myString = string.Concat("a"," ","b") or myString = string.Concat("a",Chr(9),"b") I am using stringbuilder to build an XML file and looking for something efficient. Thanks Edit ~ Language VB.NET ...

How do I find out what exceptions might be thrown by a .NET function?

I might be missing something obvious but is there a reference somewhere about what exceptions are thrown by functions in .NET and why the exception might be thrown? As an example, I was recently trying out Linq in Visual C# 2008 and I was loading an XML file into an XDocument. It was only through testing that I realised that if you try...

How to run NUnit programmatically

I have some assembly that references NUnit and creates a single test class with a single test method. I am able to get the file system path to this assembly (e.g. "C:...\test.dll"). I would like to programmatically use NUnit to run against this assembly. So far I have: var runner = new SimpleTestRunner(); runner.Load(path); var result ...

Custom button in C#: How to remove hover background?

Hi, I'm trying to do a custom button to my form (which has FormBorderStyle = none). I have my 3 states button images in an ImageList linked to the button. this.btnClose.AutoSize = false; this.btnClose.BackColor = System.Drawing.Color.Transparent; this.btnClose.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btnClo...

How do I set the login info for SQL Server 2008 in Entity Framework?

Okay I'm still learning the ropes with the Entity Framework and I came across one more small issue. When I create my Entity Model from the SQL Server 2008 database it warns me about saving the login information in the connection string in the config file. Initially I wasn't concerned about that so I just left it in there, but now I want...

File.Move not working properly for UNC paths

I'm attempting to use File.Move to move a file from one UNC location to another. This blows up if the UNC path for the destination happens to be the local machine (error: Access to the path is denied). Example File.Move(@"\someServer\path\file.txt", @"\blah2\somewhere\file.txt"). This assumes there's a network share out there somewher...

Best Wizard Control for .NET Windows Forms?

I'm looking to add one or two wizards (you know, a simple dialog with multiple pages that walks a user through a process, step by step) to my WinForms application. I'm just curious of what controls -- whether they be third-party or you rolled your own -- you used to accomplish this? ...

Dataset ReadXmlSchema Errors

How is it possible for this to be true XmlDocument d = BuildReportXML(schema); DataSet ds = new DataSet(); ds.ReadXmlSchema(schema); ds.ReadXml(new XmlNodeReader(d)); schema is the schema location that I apply to the xmldocument before I start setting data, assuring that all the columns are of the correct type. Then I set the schema t...

TransactionScope bug in .NET? More information?

I have read (or perhaps heard from a colleague) that in .NET, TransactionScope can hit its timeout and then VoteCommit (as opposed to VoteRollback). Is this accurate or hearsay? I couldn't track down information on the web that talked about this issue (if it IS an issue), so I wonder if anyone has any direct experience with it and can ...

Can you have two forms on a page with ASP.NET MVC?

Using web forms I know that you can only have one ASP.NET form on a page. I've done some implementations where I've used Javascript to add other forms to a page to support things like logon controls (that post back to Logon.aspx instead of the current page). I'm wondering if the single form per page is still present in ASP.NET MVC or i...

Password protected .NET ClickOnce deployment?

How can I protect a ClickOnce deployed application with a password? Do I have to change the IIS settings of the web or is there a way to do it programmatically? I'm using Visual Studio 2005 (.NET 2.0). If I have to use web credentials, are auto-updates of the application still possible? Would be great if you could provide some sample c...

C# check if a COM (Serial) port is already open

Is there an easy way of programmatically checking if a serial COM port is already open/being used? Normally I would use: try { // open port } catch (Exception ex) { // handle the exception } However, I would like to programatically check so I can attempt to use another COM port or some such. ...

Deriving COM interfaces in .NET

This is complicated, at least for me, so please bare with me. I'll also preface with I've spent a day searching, to no avail. Due to company constraints out of my control, I have the following scenario: A COM library that defines the following interface (no CoClass, just the interface): [ object, uuid(xxxxxxxx-xxxx-xxxx-xxxx-...