.net

Map two lists into a dictionary in C#

Given two IEnumerables of the same size, how can I convert it to a Dictionary using Linq? IEnumerable<string> keys = new List<string>() { "A", "B", "C" }; IEnumerable<string> values = new List<string>() { "Val A", "Val B", "Val C" }; var dictionary = /* Linq ? */; And the expected output is: A: Val A B: Val B C: Val C I wonder if ...

xsd schema file must be annotated in SQLXMLBULKLOADLib.SQLXMLBulkLoad4Class?

Here is an example to use SQLXMLBULKLOADLib.SQLXMLBulkLoad4Class - [STAThread] static void Main(string[] args) { try { SQLXMLBULKLOADLib.SQLXMLBulkLoad4Class objBL = new SQLXMLBULKLOADLib.SQLXMLBulkLoad4Class(); objBL.ConnectionString = "Provider=sqloledb;server=server;database=databas...

Why SomethingCollection is used instead of Collection<Something>?

Hi, In .NET Framework, there are some classes which use SomethingCollection syntax. For example, when dealing with SqlCommand, it has a parameter Parameters of type SqlParameterCollection. Since it does not have a form of IEnumerable<SqlParameter> (or IList<SqlParameter> or something similar), it is impossible to write: foreach (var c...

How to load an XmlNode object ignoring undeclared namespaces?

I want to load up an XmlNode without getting an XmlException when an unrecognized namespace is present. The reason is because I need to pass an XMLNode instance to a method. I'm loading up arbitrary XML fragments having namespaces out of their original context (e.g. MSWord formatting and other software products with various schemas t...

Define a seperate ViewModel for EditProfile View or use the User model (DRY vs convenience)

For my Edit Profile page, all the items are from the User entity. Things like email, password, fullname, city, etc. I'm using ASP .NET MVC2 along with Entity Framework 4. I'm wondering if I should create a separate ProfileModel for my EditProfile View or if I should just use the User entity created by EF. My dilemmna is that if I crea...

Detect 404 without catching exceptions

Simple function: Check if a webserver returns a non-200 HTTP status. Private Function RemoteFileOk(ByVal Url As String) As Boolean Dim req As HttpWebRequest = TryCast(WebRequest.Create(Url), HttpWebRequest) req.Method = "HEAD" Dim rsp As HttpWebResponse = TryCast(req.GetResponse(), HttpWebResponse) Return (rsp.StatusCode = Http...

Why is List<T>.IndexOf() a lot faster than List<T>.Contains()?

Hello, I have List which has 150K elements. Average time of work IndexOf() is 4 times lower than Contains(). I tried to use List of int. For List of strings IndexOf is a bit faster. I found only one main difference, it's attribute TargetedPatchingOptOut. MSDN tells: Indicates that the .NET Framework class library method to which th...

any reason to not use a dictionary

I was having a discussion with a co-worker over whether it is better to use a Dictionary and repopulate it whenever a result set changes or to just use linq loop over all elements in the list each time. We're trying to map a parent / child relationship, and I suggested using the ParentID as the dictionary key, and the dictionary value a...

Microsoft .net Security Warning : Never enter personal information or passwords ...

So I have an ASP.net application, with an ActiveX Control which brings up a pop up When I point to the application directly through IP there is no problem with the pop up eg. xxx.xxx.xxx.xxx/MyApp (under Default Website in the IIS -- IIS 7) Problem arises when I set up the IIS to point it to a domain xxx.xxxxx.com which points to the...

Can we create Test Suite Using WATIN?

I would like to know whether we can create Test Suites for WATIN. Im using WATIN to automate my Web Application. I was planning to create a set of Test Cases and save them in an Excel sheet and use WATIN to read data from them. But since its not posible using WATIN, I'm planning to create a Test Suite. ...

Use of StoredProcs in an application

hi. we're in the process of designing an enterprise application & our technical architects suggest that "lets have no sql queries in the code. even if its a simple select call to the database a stored procedure should be written for it in the database & the code should call it." my issue with this is that it seems like a dumb idea to ha...

Total rows that we can add to datatable

Hi, I wants to know whether there is any limit for number of rows that we can add to datatable. I am doing this in C# and .NET 2005. Actually my application is reading large text file around 40 MB,application reads text file line by line and adds it as row in datatable once all file reads then calls update method to update data to datab...

Timeout with HttpWebResponse in .NET

I have the following code, and after ~60 times calling it (20 concurrent connections) it starts timing out. if i lower the timeout from 10 minutes to 1 minute, they start timing out at ~34 downloads. what gives? i know that you can get this if you don't properly close your response, but i'm definitely closing it: //=================...

When are reference-type attached properties (DependencyProperty) released?

Say I want to make an attached property that attaches a list of object references to a view instance (a DependencyObject/FrameworkElement)... When does it release all of those references? Will it call Dispose on attached property values if they implement it? ...

Cookie always is NULL in Session_Start

Hi, I want in Session_Start method check if cookie with specific key exists and if not create cookie with this key. if (Request.Cookies[key] == null) { SetCookie(); } But in Session_Start it is always NULL. If check it in another place I get cookie's value. Why is it always NULL in Session_Start? Thanks, Raya ...

Get source code filename of file from a type in debug build

Given a Type object in .NET, is it possible for me to get the source code filename? I know this would only be available in Debug builds and that's fine, I also know that I can use the StackTrace object to get the filename for a particular frame in a callstack, but that's not what I want. But is it possible for me to get the source code ...

What a simple get; set; in a class means?

Take for example following code from a class: public class Employee : IEntity { public string FirstName { get; set; } public string LastName { get; set; } public int EmployeeID { get; set; } } public class Company : IEntity { public string Name { get; set; } public string TaxID { get; set } } I always used get; an...

Why not always use Generics?

I am reading existing posts on Generics at SO. If Generics has so many advantages like Type safety, no overhead of boxing/unboxing and it is fast, why not always use it. Why to go for a non-generic thing? Edited (Question further extended below) I am a bit confused. The last time I read about Generics, months back, I read that if the T...

Inconsistent empty (blank, white) lines (area, rows) on top of listview in virtual mode

Helllo. I have application with some listviews that are configured to virtual-mode. On several computers I've seen strange phenomenon: somtimes there are white row[s] (one or more) above all items. Apperantly it happens when there are insufficent items for showing vertical scrollbar. It's inconsistent: on some computers it shows one, at ...

Force LINQ to SQL getting data just one time

I'm using linq to sql. And do something like: IEnumerable<VarValues> parameters = GetDayParameters(); protected IEnumerable<VarValues> GetDayParameters() { return "some linq query"; } After that, i'm using LINQ to Objects for "parameters"-variable, in loop, and that queries start to connect to database. Question is, can i force L...