.net

"A specified logon session does not exist. It may already have been terminated." when trying to copy a file using WindowsIdentity.Impersonate

I am trying to copy a file from sharepoint to a unc path. I am using the following code: var id = new WindowsIdentity("[email protected]"); var p = new WindowsPrincipal(id); var wic = id.Impersonate(); File.Move(oldName, newName); wic.Undo(); oldname is C:\test.txt newName is \\server\folder\test.txt I am getting the erro...

C# Data Structure Like Dictionary But Without A Value

Is there any data structure in C# that is like a dictionary but that only has a key and doesn't have a value. I basically want a list of integers that I can quickly lookup and see if a certain value is in the list. Granted, for my current use, a List would not cause any performance problem, but it just doesn't seem to fit well with the...

Capturing inner items using .net Regex Balanced Matching

I have found the following resources on Balanced Matching for .net Regexes: http://weblogs.asp.net/whaggard/archive/2005/02/20/377025.aspx http://blogs.msdn.com/bclteam/archive/2005/03/15/396452.aspx http://msdn.microsoft.com/en-us/library/bs2twtah%28VS.85%29.aspx#BalancingGroupDefinitionExample From what I have read in these, the fo...

How can I tell when a managed thread has changed user contexts using impersonation?

Is there a way to find out when a managed thread has changed user contexts due to impersonation? I'd like to be able to do this from unmanaged code that is observing the managed code using Microsoft's .NET Profiling APIs. For example some managed code may be running in user context A, and then impersonate user B. The impersonation may h...

Mixed Mode C++ DLL function call failure when app launched from network share. Called from unmanaged c application.

Mixed-mode DLL called from native C application fails to load: An unhandled exception of type 'System.IO.FileLoadException' occurred in Unknown Module. Additional information: Could not load file or assembly 'XXSharePoint, Version=0.0.0.0, Culture=neutral, PublicKeyToken=e0fbc95fd73fff47' or one of its dependencies. Failed to grant mini...

Can I create a generic function that accepts a Nullable<something>?

I'm working on a method that will accept a StreamWriter, either a string or a nullable value, and a length, and write the value to the StreamWriter, padded to the length. If the value is null, I want to write spaces. I want to do something like the following oversimplified example, which is just for demonstration purposes. public void F...

How to use list/array of some object inheritance with Protobuf/Protobuf-net ?

Using Protobuf/Protobuf-net and two classes, one base class and the other derived from the base. How would you serialize/deserialize a list ? For instance: public class SomeBase { ... } public class SomeDerived : SomeBase { ... } And the following field to be serialized: public List<SomeBase> SomeList; Keep in mind that t...

Keydown event for entire application VB .Net

I want to make it so that no matter which control has focus, it will do my event. So that I dont have to write a keydown event for all 137 of my objects. Is this possible? Thanks ...

Avoiding the woes of Invoke/BeginInvoke in cross-thread WinForm event handling?

I'm still plagued by background threading in a WinForm UI. Why? Here are some of the issues: Obviously the most important issue, I can not modify a Control unless I'm executing on the same thread that created it. As you know, Invoke, BeginInvoke, etc are not available until after a Control is created. Even after RequiresInvoke return...

Changing the type of an (Entity Framework) entity that is part of an inheritance hierarchy

I have an inheritance hierarchy with a base Employee entity and some descendent entities for specific employee types. I need to be able to convert a base Employee entity to a more specific entity (e.g. TemporaryEmployee) and from a more specific type back to the base type (e.g. if an employee is no longer "temporary" then I want that ins...

Service Reference namespace becomes unknown after I 'Update' the service reference

Service Reference namespace becomes unknown after I 'Update' the service reference. Has any one else encountered/resolved this issue? The changes I make to the Service Reference code are sometimes so minor, and always in method, never to the contract or anything and after update the service reference, VS2008 no longer recognizes the name...

Prism: Commanding Delegate<T>

I have a View with ViewModel as datacontext ( set in code) . In my view I have a list <UserControl x:Class="ZPOS.Modules.Menu.Views.DepartmentView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:prism="clr-namespace:Microsoft.Practices.Compo...

Best exception to throw if output of external command is nonsense?

I'm developing a C# utility class that runs an external command on a Linux server via SSH (I'm using SharpSSH; I like it so far and I recommend it) and gives back some meaningful information based on the command's output. Somewhere in the aforementioned output is an integer that should never be outside some range, but I'd like to preven...

Providing common functionality for aggregates derived from the same base object using the Repository Pattern

I'm attempting to use the Repository Pattern to write a data access layer on an existing DB2 schema. This schema has several aggregates all having a common base entity of a "Document." When building the business objects, I created the Document entity as an abstract, and the aggregates as entities derived from Document. For example: p...

Why do I get a thrown exception when I run Response.Redirect()?

I am learning ASP.NET and was looking at QueryStrings. One of the examples I was looking at hooks a button up to a redirect call: protected void btnSubmit_Click(object sender, EventArgs e) { try { //throws ThreadAbortException: "Thread was being aborted" Response.Redirect("Form2.aspx"); ...

Regex with not match at end

I'm trying to write a regex to match patterns like this: <td style="alskdjf" /> i.e. a self terminating <td> but not this: <td style=alsdkjf"><br /></td> I initially came up with: <td\s+.*?/> but that obviously fails on the second example and I thought that something like this might work: <td\s+.*?[^>]/> but it doesn't. I'm ...

Removing manually added DataBindings

If a set of controls on a WinForm have had DataBindings created and attached at runtime, should they be removed when the Form is closed? Or will the GarbageCollecter deal with them? ...

Calculate CPU usage for a process

Given a process ID, how can i get the cpu load from this process with C#? I have tried using PerformanceCounter as described in http://stackoverflow.com/questions/1277556/c-calculate-cpu-usage-for-a-specific-application I have also tried to manually take two values of the total cpu time for the process within a timeframe and divide the...

The Windows GUI Main Loop In C#... where is it?!

I am going out of my skull trying to figure this out. I have a Windows Form app in C# and am trying to figure out where I would implement the CLI app equivalent of the primary while loop in main(). Everywhere I have looked I have found absolutely nothing that will help me. I am using Visual C#'s gui designer. Please help, as this is the ...

How do I HTTP POST from an ASP.NET button?

Sorry, another super basic ASP.NET question. this so embarrassing. I am reading the article on How to: Pass values between ASP.NET pages In the second approach, they suggest hooking up a button and directing the user to another page using POST. I don't know how to do this. How do I HTTP POST? "When the source page uses the H...