.net

C#: How to know whether certain Office 2003 or 2007 application is installed?

I need to know whether Microsoft Word, Excel, Outlook, Project, etc are installed in a Windows Forms .net 2.0 C# application. The first attempt was by simply trying to create the application objects and catching any exception, but this is too time consuming. Is there any faster way to detect this? Like checking registry values, or anothe...

How to print the current Stack Trace in .NET without any exception?

I have a regular C# code. I have no exceptions. I want to log the current stack trace for debugging purpose. Example: public void executeMethod() { logStackTrace(); method(); } ...

What's the best way to write a parser by hand?

We've used ANTLR to create a parser for a SQL-like grammar, and while the results are satisfactory in most cases, there are a few edge cases that we need to fix; and since we didn't write the parser ourselves we don't really understand it well enough to be able to make sensible changes. So, we'd like to write our own parser. What's the...

How to measure memory leaks in .NET in a reliable and automatic way?

I wrote an automated test in order to ensure that our application does not leak (managed & unmanaged memory) now AND later as development grows up. The problem is that my test does NOT seem reliable, but I don't know whether this is inherent to .NET and leak definition or to the test. It happens this way: long start = PrivateBytes; /...

Render FixedPage contents onto bitmap

I have the following code, taken from http://www.codeplex.com/XPS2Image/ ,which in turn was taken from some people discussing at at Microsoft development forums. int[] pages = new int[] { 0, 1, 2, 3, 4 }; XpsDocument xpsDoc = new XpsDocument(@"c:\tmp\sample.xps", System.IO.FileAccess.Read); FixedDocumentSequence docS...

How do I get a disabled ToolStripButton to paint its image in colour?

We have a button which allows users to 'lock' a form. Users are not permitted to 'unlock' the form, so when pressed, we want the button to be disabled, so that the user receives appropriate visual feedback. However, the customer reports that the greyed 'lock' icon suggests to them that the form is not locked, so we would like to displa...

C# volatile double

As only reference types and a few primitives (including float, but not double, I'm not sure the reason why, I'm happy to hear why) can be declared as volatile, if I wrap a double in a class then declare it as volatile (as below), will the double property be 'read write' thread safe as any other volatile, or should I still be looking at l...

WCF Memory Performance InstanceContextMode

I've been learning my way around WCF and I've got a question regarding the InstanceContextMode. Correct me if I'm wrong, but the WCF will instantiate your object, then call the service method on it per call by default. You can then set it to be PerSession or Single. It seems to me that it would make more sense to have something betwee...

What is the best way to work with time-driven events in WPF

I have a simple app, that has media element in it, and it plays some movies, one after another. I want to have a 15 seconds delay between one movie stops playing, and the next one starts. I'm new to WPF and though I know how to do this the old (WinForms) way with a Timer and control.Invoke, I thought that there must be a better way in WP...

How to use XmlSerializer to deserialize into an existing instance?

Is it somehow possible to use the XmlSerializer to deserialize its data into an existing instance of a class rather than into a new one? This would be helpful in two cases: Easily merge two XML files into one object instance. Let object constructer itself be the one who is loading its data from the XML file. If the is not possible b...

.NET own configuration file

Is there any way that I could specify at runtime the configuration file I would like to use (other than App.config)? For example I would like to read a first argument from a command line that will be a path to the application's config and I would like my application to refer to it when I use ConfigurationManager.AppSettings (It's probabl...

Alternative to .NET's Uri implementation?

I have a problem with the .NET's Uri implementation. It seems that if the scheme is "ftp", the query part is not parsed as a Query, but as a part of the path instead. Take the following code for example: Uri testuri = new Uri("ftp://user:pass@localhost/?passive=true"); Console.WriteLine(testuri.Query); // Outputs an empty string Conso...

What is the difference between .resx and .config files in .NET?

When should I use .resx file and when go for .config file? What is the basic difference between the both in terms of usage? ...

How to sort Generic List Asc or Desc ?

I have a generic collection of type MyImageClass, and MyImageClass has an boolean property "IsProfile". I want to sort this generic list which IsProfile == true stands at the start of the list. I have tried this. rptBigImages.DataSource = estate.Images.OrderBy(est=>est.IsProfile).ToList(); with the code above the image stands at the ...

Debug code security .net framework to use caspol.exe

We have an application that is distribute to a varity of customers. Sometime it is installed on a network share. Usually we can give that application access with caspol.exe and grant the LocalIntranet Zone FullTrust. Sometimes the customers admins do not manage to grant that application access due to some network settings. When we launc...

Reversing ListBox items (descending sort by "nothing")

Is it possible to sort items in WPF ListBox in reverse from their original order? I mean you can use SortDescriptions to sort by some property, but what if I just need to show the items in the reverse order with no real field to sort against? Note: I would prefer not to sort the original collection or clone it, etc. I know how to do tha...

How to clear the cache of HttpWebRequest

I am developing against a proprietary library and are experiencing some issues with the cache of the HttpWebRequest. The library is using code equivalent to below to make requests: var request = WebRequest.Create("http://example.com/") as HttpWebRequest; request.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.CacheIfAvai...

Will SQLite Work in a ClickOnce Deployment?

And if it will, what is the best practice in terms of connection strings? Just a relative path? |DataDirectory| ? ...

How to pick an open source project to join?

I am interested to join an Open Source project using .net; I would like to be able to choose between a mature project and a starting one, as well as other criteria. What do you suggest? (specific projects are welcomed). Later edit: I am disappointed by the arrogant comments / answers received so far. Picking an OS project to contribu...

How to read strongly typed objects from an app.config file manually

I have a dll that I want to read from a manually specified app.config file (the dll is an .net extension to a native com dll that is a Microsoft Management Console snap in, so there is no mmc.exe.config). I have been able to open the config file, read the relevant group and section to get the setting that I want. Like this: ExeConfig...