.net

Poxy Proxy Problem! c#

Hi The code below works fine to instruct the system not to use a proxy and to not auto detect one, which causes a delay without the code. However while on a network with a proxy I just get the underlying connection is closed! So four questions: Am I specifying the proxy correctly? If so how do I tell it to use default proxy credenti...

Flag Enum and mutually exclusive Enum with overlapping meaning

I have a model that must be in one of the following mutually exclusive states: New, In Progress, or Closed. The application allows a user to save a record and then retrieve them by providing a list of matching states. I inherited an SQL database where the state is stored as an integer that represents bitwise flags. I have to call a pro...

.net WinForms application use domain credentials of another username and password

Hi, I want to create a program that will allow someone to add a user to a group. I don't want to give the user the ability to do this on the domain through their account. I want to use a separate username and password stored in the program that will be used. What documentation should I be reviewing? ...

Database access in a web service

I'm currently working on a web service implementation to a combined web/desktop application (ie. access from different sources). Now there are two questions I can't really find an answer to: How would I access the database in the right way (static class? singleton? DI?)? I didn't find any information on using a Web Service in a DI con...

"System.TypeLoadException: Internal limitation: too many fields." With Large Static Data Structure

I have a small C# library with a static class that holds a very large, but simple four-dimensional byte array representing a multi-dimensional decision table (about 90K bytes in total). There's one other data structure of note in there, a Dictionary which helps index into the first dimension of the decision table. This decision table ...

Restrict a method call to a specific page in a .net application (in C#)

Hei, I have a method from a class in a custom library which I would like to restrict to be called only on a specific page, somehow using conditional methods. The problem is that I need a return value and conditional methods do not allow return other than void or 'out' parameters. Using a void method it works fine, but is there a way to a...

How to apply a global style (allowing hightlighting after focus is lost) to a wpf treeview

I found the following code for showing the selected item in a treeview when focus has left, but I'm having trouble moving the code to App.xaml so any UserControl could use it. This does what I want <TreeView x:Name="trviewArchives" Width="141" Height="154" Canvas.Left="20" Canvas.Top="167" Background="{x:Null}" BorderBrush="#FF08182...

Creating Thousands of Threads Quickly and Executing Them Near Simultaneously

I have a C#.NET application that needs to inform anywhere from 4000 to 40,000 connected devices to perform a task all at once (or as close to simultaneous as possible). The application works well; however, I am not satisfied with the performance. In a perfect world, as soon as I send the command I would like to see all of the devices r...

Javacript Calling Into Silverlight for Webcam Capture

I have a rather unique situation here. I have a Silverlight application that captures images and uploads them to a web server which is pretty standard, but a requirement I have is to allow the web designer to make their own buttons and controls (or to style them) that controls the application. So I decided to use ScriptableMember functi...

Cannot specify which attributes to return when querying an LDAP store.

I am using the DirectoryServices.Protocols.SearchRequest type to make a request against an OpenDS store to retrieve some entries. I want to be able to control which attributes are returned for the entries in the response and thought the "Attributes" property would do it. However that property does not have a setter so I cannot do somethi...

Error loading Bitmap from MemoryStream

I'm trying to load images (pdfs and Word documents) from a memory stream so I can manipulate them before they get added to a pdf. Whenever I try and load a bitmap or a GIF I get one of the dreaded GDI+ errors. This call... System.Drawing.Bitmap myImage = System.Drawing.Image.FromStream(docStream); Generates this error... Sys...

Is there a way to get the original HTTP response string from a WebException?

I have a web app which talks to a custom back-end server over HTTP. The server provides its responses in XML and I use Linq-to-XML to parse the results. If the server cannot process a query it will send back a 400 bad request header which includes detailed information about the problem. i.e. HTTP/1.1 400 Bad Request (invalid query)...

Entity Framework 4 - AddObject vs Attach

Hi All, I have been working with Entity Framework 4 recently, and am slightly confused as to when to use ObjectSet.Attach, and ObjectSet.AddObject. From my understanding: Use "Attach" when an Entity already exists in the system Use "AddObject" when creating a brand new Entity So, if i'm creating a new Person, i do this. var ctx = ...

Is String.Format and DateTimeFormatInfo pluggable/extensible?

So for example lets say when I string.format a date and use the string "or" in format pattern I want that converted to the ordinal value of the Date. ie string.Format("{0:ddor MMM yyyy}.", DateTime.Now) should output 1st Jan 2010 See below for how to derive the ordinal numbers http://stackoverflow.com/questions/69262/is-there-an-...

What's the lifetime of an unmanaged DLL once it's been pInovked from managed code?

For example if you have a simple managed console app and a simple unmanaged C++ DLL. You pInvoke into a function in the C++ DLL, does the DLL stay loaded in the unmanaged process until said process comes down? Or does the DLL get unloaded at the completion of every pInvoke call? ...

Using named groups in .NET Regex

I'm new to .NET and having a hard time trying to understand the Regex object. What I'm trying to do is below. It's pseudo-code; I don't know the actual code that makes this work: string pattern = ...; // has multiple groups using the Regex syntax <groupName> if (new Regex(pattern).Apply(inputString).HasMatches) { var matches = new...

Access return value from VBA Function in .NET?

I have the following code in VBA (which resides in an Excel 2007 Workbook): Public Function Multiply(a As Double, b As Double) As Double Multiply = a * b End Function If I invoke Multiply from other VBA code, it returns the correct value. However, when I call Multiply from C#: var excel = new Application {Visible = true}; excel....

IIS and WebDev server problem

developing web application i faced a problem. i wrote code, and it worked fine on webdev server in vs2010. i hosted it on remote iis, because, my windows 7 home basic doesnt have iis, and almost all code fails, so i had to rewrite it with using helpers for links, ResolveUrl and many other functions. So here is the question, how can i hos...

NHibernate 3.0 beta1 Bidirectional One-To-Many Cannot Add Child Object

Hi guys, In short, the problem is that, when add child object to the collection property of the parent object without explicit setting the parent property of the child object, the insert will fail. Let's take a example: NOTE: I'm using NHibernate 3.0 beta1. Example: Product-Category Senario: (1) Database Schema: Category (Id, Name)...

Using conditional replace in C# Regular Expressions for CSS minification

Hey guys, I am making an application using C# in Visual Studio that minifies CSS code. Now I came across a piece of code that strips all prefixes for the # ID selector. strCSS = Regex.Replace(strCSS, @"[a-zA-Z]+#", "#"); However, this would also remove any class names in front the ID selector. For example, #interior .field#user-comme...