.net

How can I avoid SQL injection attacks in my ASP.NET application?

I need to avoid being vulnerable to SQL injection in my ASP.NET application. How might I accomplish this? ...

Which method performs better: .Any() vs .Count() > 0?

Hi folks, in the System.Linq namespace, we can now extend our IEnumerable's to have theAny() and Count() extension methods. I was told recently that if i want to check that a collection contains 1 or more items inside it, I should use the .Any() extension method instead of the .Count() > 0 extension method because the .Count() extensio...

Process.Start() throwing intermittent "No application is associated.." on .DOC files

System.Diagnostics.Process.Start() is throwing intermittent System.ComponentModel.Win32Exception: No application is associated with the specified file for this operation. The file is a .doc file. They are always able to open it manually (double-click). What could be the problem? Thanks ...

What do the "+n" values mean at the end of a method name in a stack trace?

When reading a stack trace like: [FormatException: Input string was not in a correct format.] System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +2755599 System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +112 System.Conver...

Embedding SMO dlls in Setup and deployment.

I have a .NET Set and Deployment project which has to execute a set of really long SQL Scripts as a part of the installation process. I have used SMO dlls to make calls to the .sql script files.These SMO dlls are however not a part of the .NET framework but they come bundled with SQL Server 2005 or 2008. Now, if the setup is run on a mac...

Moq multi-interface question

This may or may not be a multi-interface problem, but I'm doing something like this: var mockInterface1 = new Mock<IInterface1>(); var mockInterface2 = mockInterface1.As<IInterface2>(); mockInterface1.Expect( foo => foo.Foo(It.IsAny<IInterface3>() ) ); ... otherObject.DoSomething( (IInterface1)mockInterface2.Object ); On the DoSomet...

Iterate through an anonymous variable in another scope then where it was created

I am writing an unit test for a mvc web application that checks if a returned list of anonymous variables(in a jsonresult) is correct. therefore i need to iterate through that list but i cannot seem to find a way to do so. so i have 2 methods 1) returns a json result . In that json result there is a property called data. that property ...

How to save the state of an C# app to be able to load later

Hi! I have a program in which the user adds multiple objects to a scene. These objects are all represented as a classes. Now I want the user to be able to save the scenario, so it can be loaded again. Is there some genereic save method I can use, or do I have to write my own that saves the values of all properties and such and then cr...

Run .net code in a separate process

In an impersonation scenario related to Sharepoint I need to execute some code in a separate process (the process will run in the context of a certain user). I do not want to launch a separate application, basically I want to do a "run as" on just a method. ...

Locate Pattern the Letter I followed by a space then three alpha numerics followed by a space

Need to locate the following pattern: The letter I followed by a space then three alpha numerics followed by a space "I ALN " "I H21 " "I 31M " these items are also followed by a lat/lon that is trapped by this expression: Dim regex As New Regex("\d{6} \d{7}") Can the expressions be combined to return a match that would look like: ...

How to get the last selected item in multiselect ListBox?

How to get the last selected item in a .Net Forms multiselect ListBox? Apparently if I select an item in the listbox and then select another 10 the selected item is the first one. I would like to obtain the last element that I selected/deselected. ...

What is res://*/ in .net?

I came across this snippet of code on MSDN: entityBuilder.Metadata = @"res://*/AdventureWorksModel.csdl| res://*/AdventureWorksModel.ssdl| res://*/AdventureWorksModel.msl"; What does the res://*/ mean and how does it work? I think it has to do with resource files, but I am not su...

How do you setup a handler for the dragover/dragdrop events in the MDI client area?

Using C# and the .Net framework 2.0. I have an MDI application and need to handle dragover/dragdrop events. I have a list docked to the left on my application and would like to be able to drag an item from the list and drop it in the MDI client area and have the correct MDI child for the item open. I can't seem to figure out where to att...

How to determine if a string is a number in C#

I am working on a tool where I need to convert string values to their proper object types. E.g. convert a string like 2008-11-20T16:33:21Z to a DateTime value. Numeric values like 42 and 42.42 must be converted to an Int32 value and a Double value respectively. What is the best and most efficient approach to detect if a string is an In...

What is the easiest way to determine the dependencies of a .NET assembly.

Considering a large system with hundreds of assemblies, what is the easiest way to determine which other projects in the large system depend on a specific assembly when there isn't any way to create a single visual studio solution that contains all the projects? ...

Generate class for schema with abstract complex type

I'm working with some schema which defines an abstract complex type, eg. <xs:complexType name="MyComplexType" abstract="true"> This type is then referenced by another complex type in the schema: <xs:complexType name="AnotherType"> <xs:sequence> <xs:element name="Data" type="MyComplexType" maxOccurs="unbounded"/> </xs:sequence...

Set OpenFileDialog to default to Thumbnail view

I'm using the OpenFileDialog class so a user can select an image file. I'd like to default the dialog to Thumbnail view mode. Unfortunately the class doesn't have any way to set a default view mode. Other than creating my own custom dialog (which I may have to do), is there a way to achieve my goal? ...

How can I make a control transparently overlay a DirectShow video?

I have a control, VideoControl, which displays video using DirectShow - it's set as the owner of an IVideoWindow. I have another control, AreaControl, which is supposed to show a dashed rectangle over the video control. AreaControl is set to be transparent using SetStyle(ControlStyles.SupportsTransparentBackColor, true). If I place Ar...

Multiple back ends for Entity Framework

Can I use two different back ends for an .net Entity Framework project? I need to support the full programmability support of stored procedures on SQL server when available. I need to support only table structures in a .mdb file when SQL server is not available. All business logic above the Entity Framework uses the entity abstratction...

Any clever way to fix 'string or binary data would be truncated' warning with LINQ

Is there a clever way to determine which field is causing 'string or binary data would be truncated' with LINQ. I've always ended up doing it manually by stepping through a debugger, but with a batch using 'SubmitChanges' I have to change my code to inserting a single row to find the culprit in a batch of rows. Am I missing something ...