.net

Forcing creation of HttpContext.Current.Session in .NET

I'm working on an application that uses .NET's StaticFileHandler to serve up dynamically generated content... There is also another part of our application that uses the current HttpSession to store user-specific data. Since the StaticFileHandler is designed to handle static files, it doesn't implement IRequiresSessionState, thus anythi...

WPF Validation: Styling/templating validation properties

I have a WPF screen that displays a number of TextBox inputs. I have a style that handles all the validation: <Style x:Key="TextBoxStyle" BasedOn="{x:Null}" TargetType="{x:Type TextBox}"> <!-- etc etc --> <Setter Property="Validation.ErrorTemplate"> <Setter.Value> <ControlTemplate> <Border Gri...

Unity Application Block - Convert example from C# to VB

I'm attempted to convert the WPF Starter Kit from C# to VB.net and I'm doing really well, except for one area... Dependency Injection using the Unity Application Block. I have the following C# code block: Type viewModelType = viewModelAssembly.GetType(action.ViewModelTypeName); var notificationPolicy = unity...

Remove record from a datatable when record disappears from a mirrored datatable

I have two mirrored datatables (same structure with two primary keys) : DataTable_A ---> bound to a datagridView DataTable_B ---> filled from a database Since DataTable_B is filled by a query into database every 2 seconds, I need to mirror the DataTable_A like DataTable_B avoiding filling directly DataTable_A. When a record disappea...

Is there an easy way to return a string repeated X number of times?

I'm trying to insert a certain number of indentations before a string based on an items depth and I'm wondering if there is a way to return a string repeated X times. Example: string indent = "---"; Console.WriteLine(indent.Repeat(0)); //would print nothing. Console.WriteLine(indent.Repeat(1)); //would print "---". Console.WriteLine(in...

nhibernate and nested transactions

I know that nhibernate doesnt support nested transactions. Let's say that I got something like this: UserService.BeginTransaction (on current session) UserService.Save UserService->FeedService FeedService.BeginTransaction (on current session) FeedService.Save FeedService.Commit (on the returned transaction in #3.1) UserService->Add...

Java Equivalent to .NET/C# String.Format

Is there an equivalent to the .NET/C#'s String.Format in Java? ...

Stored Procedures programmed to fire in separate serial transactions appear to execute simultaneously

I have a .net application that has to execute a series of steps in a job. Each step lives in its own transaction, and all tasks are executed serially (no explicit async). The last two tasks are a data transform, and a data retrieval of the transformed data. We are getting deadlock errors from these last two steps, because the last step l...

Regex nested groups

I am attempting to extract all data from a file with one regex expression. Since there are optional(?,*) and repitious(*,+) expressions, it would be difficult to enumerate through the captures, at least in a readable and understandable fashion. Therefore, I am using named groups. However the data is in an XML like structure; neseted elem...

Native namespace exported in C++/CLI project?

I am wrapping a native C++ library for consumption by the CLR. However, I'm running into a strange... problem? The native library's headers look like so: namespace Foo { class Bar { public: Bar(); //etc... }; } So, to consume this class, I have my own class definition: #include "Foo/Bar.h" namespace Fo...

Is there a way to find a file by just its name in C#?

We use absolut path or relatvie path to find a file in our C# application right now. Is there a way to find the file just by its name if the file is under the currect working directory or under one of the "paths"? Use absolute pathe is not good and use relative path is not good enough because we may change project structure by rename o...

How do I install a windows service that runs as an administrator?

I've written an installer that installs a windows service (A) that needs to start/stop another service (B). However, when A tries to start/stop B, I get this exception: System.InvalidOperationException: Cannot open MyService service on computer '.'. ---> System.ComponentModel.Win32Exception: Access is denied The installer installs the ...

Reading .doc file without launching MSWord

I'm trying to open .doc file and read its content. But i can't find any way how to do this without launching MSWord. Now I have following code: Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application(); object nullObject = System.Reflection.Missing.Value; object file = @"C:\doc.doc"; ...

Comparing a possibly empty string in C#

Hi all, I'm trying to compare a string field from a LINQ query on a database using: e.Comment.equals("Working From Home") on the WHERE clause. However, sometimes the Comment field could be empty which currently causes an Object reference not set to an instance of an object exception. Is there any way I can check if the Comment isn...

Is it possible to deploy DLL's to separate directory than the executable for a console application?

Is there a way in .NET C# Console Application to deploy the executable to a different directory than the DLL's it depends on? In this case I would like to structure my deployment so that on the server where this will run I have the following directory structure. c:\app\bin\sample.exe c:\app\dll*.dll ...

Regular expression to check for two of three criteria

I need to create a regular expression to match strings that satisfy any two of the following three criteria: at least one upper case letter, at lease one lower case letter, at least one number. for example the following would be the result: "TestString" = MATCH (upper & lower) "TestSTring5" = MATCH (upper, lower, & number) "teststring"...

Is there a better way?

Is There a better way to do this. FileInfo f = new FileInfo("C://notebook.txt"); public bool Archived { get { return (((File.GetAttributes(f.FullName)) & FileAttributes.Archive) == FileAttributes.Archive); } set { if (value == true) ...

Why isn't my Visual Studio working properly on Windows 7?

For some reason the Web Development VSExtension isn't working, even though I've installed the SP1. The Web Development templates are available (web forms, generic handlers) and I can compile web projects but the designers are missing. Is there a way I can solve that? ...

Can all of the classes in my .NET application be internal?

Note: application, as opposed to libraries. I've got a WPF application. It's broken down into a main application project and associated class libraries. Are there any circumstances where any of the classes in the main application need to be public, as opposed to internal? For example, do data bindings or WPF value converters need to be...

Entity Framework Doesn't Update Precision?

Let's say that I had a SQL Server database with a table called MyValues and a column called ValueA defined as decimal(7,4) and I created an Entity Framework 4 model from that table within Visual Studio 2010. The result would be an entity called MyValue with a Decimal ValueA property having a Precision set to 7. If I go into the databas...