.net

Filling list data into a data model class C#

Hi All, I'm after some advice on the most efficient approach to stepping through a list of fields and filling in their values to a class object. I currently accessing fields via (code isn't exact but you get the idea =] ): private string fieldName; private int fillValue; SessionData rawdata = new SessionData(); var count = 1; fore...

web.config authorization deny unauthorised

I am developing a .NET for ASP.NET Web Application and am trying to deny all users who are unauthorised from accessing my application but allowing them only to the login page. Below is a snippet of the code which is inside my system.web section: <authentication mode="Forms"> <forms loginUrl="Login.aspx" timeout="60" name="APPNAME" ...

C# reflection base class trouble

I want to get value of field of base class, in child class, by name of field: class A { protected static double? x; } class B : A { B() : base() { x = 13F; } void test() { double? s = this.GetType(). GetField("x", BindingFlags.NonPublic | BindingFlags.Static).GetVa...

Best practices for creating a namespace for an extension to another company's product?

I typically follow the Company.(Product|Technology)[.Feature][.Subnamespace] pattern encouraged by Microsoft: http://msdn.microsoft.com/en-us/library/ms229026 when naming class libraries. I'm wondering what convention to use when naming a class library that contains mostly code wrapped around another company's product. My specific case ...

Floating point comparison functions for C#

Can someone point towards (or show) some good general floating point comparison functions in C# for comparing floating point values? I want to implement functions for IsEqual, IsGreater an IsLess. I also only really care about doubles not floats. This is the best I've found so far for an IsEqual function. EDIT: This is junk don't use ...

Delete User from AD Group

Hey, I am trying to delete a user from an Active Directory group via code. Getting the helpful error of: Exception has been thrown by the targe of an invocation" Trace: Stack Trace: at System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args) at Active_Directory.RemoveUserFromGroup(String sInUs...

C# - TCP/IP MIB-II (RFC-1213) Group Support

Group, Is there group support for TCP/IP MIB-II (RFC-1213) in C#. I'm trying to write a client interface that will communicate over SNMP and access data dictionaries plus files. --Looking on the internet. It seems to me that I'll need a SNMP agent. Any suggestions or help. Chad ...

Clipboard.GetData("XML Spreadsheet") return Null

I have to read clipboard from a .net application using c#. I use "Xml Spreadsheet" format to read it to have informations like type of columns. My problem is that sometimes the GetData() return null. Stream stream = Clipboard.GetData("XML Spreadsheet") as Stream; I read clipboard from the main thread. I suppose this is a memory proble...

save text fields to an Array (and pull data from the Array) when using treeview in c#

Ok, I have a treeview which I am using to display a number of nodes. I wish to attach data (three textbox fields) to each node but I do not want to show it in the tree. I wish to save the data to a string[] Array if possible. I want the data in the boxes to save to the Arrays when I click on a new node in the tree and pull the informatio...

C# 4.0: Dynamic, Inheriting from DynamicObject

Let's say I have this: dynamic foo = new Foobar(); And I have this: public class Foobar : DynamicObject { } The question is, is it possible to override members of DynamicObject so that this code: string name = new Foobar().Name Does not throw an Exception at run-time? I want to return default for name's if Name is not a member....

Ways to Maintain Data History in SQL Server 2008 Database

For a long time, we've wanted to create a case management system where no history is ever lost. When a change is made, we want to record that change, but have the ability to go back to any point in time and see what the record looked like. I wanted to pose this question to the Stack Overflow community to see what are some ways of doing t...

Collection was modified; enumeration operation may not execute.

Hi All, This question is asked many a time in this forum. I know solution for the problem. But I am curious to know why "Enumeration operation can not execute when a collection is modified" List<string> list = new List<string>(); list.Add("a"); list.Add("b"); int[] array = new int[6] { 1, 2, 3, 4, 5,...

Why is this LINQ so much slower than its SQL counterpart?

I have the below LINQ to SQL method that takes an inordinate amount of time to execute yet its SQL counterpart is quite simple and fast. Am I doing something wrong in the LINQ part? I am just trying to return some data to display, read-only, in a Data Grid. I understand that if the tool doesn't fit don't use it and as such I could j...

Clever way to append 's' for plural form in .Net (syntactic sugar)

I want to be able to type something like: Console.WriteLine("You have {0:life/lives} left.", player.Lives); instead of Console.WriteLine("You have {0} {1} left.", player.Lives, player.Lives == 1 ? "life" : "lives"); so that for player.Lives == 1 the output would be: You have 1 life left. for player.Lives != 1 : You have 5 lives lef...

.Net Mail Duplicates

Hello everybody, I am facing a weird problem in production, not happening in Local machine. I hosted an application in godaddy that has a aspx page where it collects the email addresses from the text fields (txtTOEmail,txtCCEmail, txtBCCEmail). When I call the send method on the mail object, the mail is sent twice. But this is not happ...

Communication between forms "Not Same process"

How to communicate between two window forms, each has its own project, so forms not running under same process. send and receive string value, .net 2 Thank you for the input. using Interprocess Communication using Named Pipes sample: http://www.switchonthecode.com/tutorials/interprocess-communication-using-named-pipes-in-csharp using...

Should an object return null and a collection of objects return an empty collection?

The topic of returning nulls, empty objects and empty collections came up today and we'd like to get the opinion of others. We have read the discussion on returning null for object and separately the discussion on returning empty collections and agree with the marked answers for both topics. However, in our case, we have a class that c...

Get metadata about components in NHibernate

So, you can use NHibernate.ISessionFactory.GetClassMetadata(System.Type) to get information about a mapped entity class in NHibernate. However when the type is mapped as a component, GetClassMetadata blows up with an exception stating that the class is not an entity. Is there a way to retrieve metadata information about a mapped compon...

Is there a way to create a "Self-hosted" Web Site in .Net?

Similar to WCF SelfHosting. is there to create a website that is "self-hosted" within a console app or dll? probably the wrong way to ask this question, but what i'd like to do is use this website to spit out results that are web pages, without creating the website within IIS. thanks ...

NuPack Package Management

So when planning new projects is it safe to use NuPack to handle dependencies? When I say safe, will it stick around? Or is it going to just be a hyped project that dies (i.e. Google Wave)? Is there really a place, or need for dependency management in .NET? If not, what is the recommended way to handle dependencies? ...