.net

Impersonation the current user using WindowsImpersonationContext to access network drive

I need to access a remote drive from a Web App. The drive isn't accessible to the ASP.NET process, so I want to impersonate the current user for the request. I saw some basic examples using WindowsImpersonationContext, and have tried the following. WindowsImpersonationContext impersonationContext = null; try { impersonationConte...

Prevent parent event from propagating to child

I have a form which contains a bunch of controls. When I change the form font, the font change event propagates to the children. That is the desired behavior except for the datetimepicker control, where I do not want the font change to trigger. Is it possible to prevent it, or do I have to set the font back to the original after the chan...

SQL injections and .NET 4

Is there instruments in .NET 4 to "automatize" verifications of SQL fields against SQL injections? I saw this article, but afraid could be not to date... EDIT: Oracle Db compatible... ...

MS Workflow Foundation 4 - Can the workflow model be interigated at runtime, as in to generate a visual representation of it?

can the workflow model be interigated at runtime. Reason, to generate a visual web representation of it? For highlighting the current node of the workflow, for example. ...

BackgroundWorker: Enabling/Disabling Buttons in Completed Event not working after switching between UserControls

Hi there I have a problem with my BackgroundWorker placed in a UserControl. My WPF application has a navigation on the left and each entry loads its own UserControl where the user can generate a PDF file. Because the creation of the PDF takes some time I've implemented a BackgroundWorker which does the job and additionally I disable s...

Memory Leaks in Winforms application.

Hi, We are developing a big .Net Windows Forms application. We are facing memory leak/usage problem in that despite we are disposing the forms. Scenario is like: Our application is using 60K of memory with list of records displaying in a Grid. When user click on a record it opens a form myform.showDialog, show the details. Memory ju...

c# Granting "Log On As Service" permission to a windows user

how do I grant a user the LogOnAsService right for a service? I need to do this manually, in the services.msc app I can go to the service, change the password (setting the same that there was before), click apply and I get a message: The account .\postgres has been granted the Log On As Service right. How do I do this from code,...

MessageBox with exception details immediately disappears if use splash screen in WPF 4.0

My desktop-based WPF-application (4.0) works with DB and in order to this it should establish a connection with SQL Server on application's startup. Of course, this operation takes some time and user have to wait some seconds (3-5) while .Net Framework start and connect to SQL Server. As appropriate in such kind of cases I decided to us...

How do I add a collection e.g. dynamic array as a property of a custom asp.net control?

I'm trying to add a dynamically expandable property to a composite control that I can drop on the designer surface. I've tried this with a String Array, a List, and an ArrayList. All with similar results. I'm missing something and I don't know what. Here is what I think is the relevant code: [DesignerSerializationVisibility(Desig...

deallocating memory for objects I haven't set to null

EDIT: Problem wasn't related to the question. It was indeed something wrong with my code, and actually, it was so simple that I don't want to put it on the internet. Thanks anyway. I read in roughly 550k Active directory records and store them in a List, the class being a simple wrapper for an AD user. I then split the list of ADRecords...

.NET - Way to display all available vars?

I know absolutely zero about .NET. Is there a way for me to show all the vars that are available to a user control to use? If they only showed like in a debug mode or something on the host machine that'd be fine. Thanks! ...

ServiceController permissions in Windows 7

I have an application which consists of a service and an executable. Essentially it's a forms application that is responsible for starting and stopping a service under specific circumstances. On windows XP the application manages this fine using the following code: ServiceController controller = new ServiceController(); controller.Mach...

IPhone / Android / WP7 app?

Which one should I go after/learn? In terms of market share, prospect, market penetration, opportunity, learning curve etc. I am a .NET programmer myself. I really hope that Microsoft can do better this time. I hope I can make use of my little knowledge in Microsoft platform to achieve something in mobile apps. I am opened to any comme...

Design Pattern for creating a set of data objects

Hi, I'm writing some code to do some stuff and I'm pretty sure its not well designed at the moment but I can't think how I should be refactoring it to make it nicer... The simple summary is that I have some code which goes through some files in a directory structure and different directories contain different content types. I have a li...

Why SynchronizationContext does not work properly?

I have following code: [TestMethod] public void StartWorkInFirstThread() { if (SynchronizationContext.Current == null) SynchronizationContext.SetSynchronizationContext( new SynchronizationContext()); var syncContext = SynchronizationContext.Current; Console.WriteLine("Start work in the first thread ({0}...

C# Message box and input value

Hello, Could I add some custom control to the standard Message Box for read input value, for example text fields for user name and password, or I should create custom winform with "Ok,Cancel" buttons and text fields? Thanks. ...

casting multiple integer values in sql

Hello - I would like to cast multiple variables which are coming from .net solution to integer. Something like this: I am using IN keyword for selecting more then one keyword, because I don't know how many variables are selected by the customer and I am putting them in nvarchar variable. Example: StatusID selected: 30,40,50 '30,40,5...

How to check if an interface extends another in C#?

The Type.IsSubclassOf method only works with two concrete types, e.g. public class A {} public class B : A {} typeof(B).IsSubclassOf(typeof(A)) // returns true Is there a way to find out if an interface extends another? e.g. public interface IA {} public interface IB : IA {} The only thing I can think of is to use GetInterfaces on ...

Are there free mocking frameworks that can mock methods and classes that are non-virtual, static or sealed?

I know there is TypeMock and JustMock, but both are commercial products and quite expensive. Are there free or open source mocking frameworks that can compete with the two? I am currencly using Moq, but I'm wondering if open source can catch up? Maybe Moles is the answer (http://msdn.microsoft.com/en-us/library/ff798506.aspx), although ...

C# declare a method always throws an exception?

I have a method like... int f() { try { int i = process(); return i; } catch(Exception ex) { ThrowSpecificFault(ex); } } This produces a compiler error, "not all code paths return a value". But in my case ThrowSpecificFault() will always throw (the appropriate) exception. So I am forced to a put a return value at t...