Questions tagged [.net-2.0]

The 2.0 version of the .NET Framework. For questions on .NET Framework generally, use the .net tag.

The 2.0 version of the .NET Framework.

What's New in the .NET Framework 2.0
.NET Framework 2.0 System Requirements

Released by Microsoft Corporation
Version Number: 2.0.50727.42
Release Date: 2005-11-07

2578 questions
86
votes
4 answers

file exists by file name pattern

I am using: File.Exists(filepath) What I would like to do is swop this out for a pattern, because the first part of the filename changes. For example: the file could be 01_peach.xml 02_peach.xml 03_peach.xml How can I check if the file exists…
JL.
  • 78,954
  • 126
  • 311
  • 459
85
votes
6 answers

Check if object is NOT of type (!= equivalent for "IS") - C#

This works just fine: protected void txtTest_Load(object sender, EventArgs e) { if (sender is TextBox) {...} } Is there a way to check if sender is NOT a TextBox, some kind of an equivalent of != for "is"? Please, don't suggest…
roman m
  • 26,012
  • 31
  • 101
  • 133
79
votes
3 answers

How to use Reflection to Invoke an Overloaded Method in .NET

Is there a way to Invoke an overloaded method using reflection in .NET (2.0). I have an application that dynamically instantiates classes that have been derived from a common base class. For compatibility purposes, this base class contains 2…
Wes P
  • 9,622
  • 14
  • 41
  • 48
78
votes
7 answers

Can .NET source code hard-code a debugging breakpoint?

I'm looking for a way in .NET (2.0, C# in particular) for source code to trigger a debugging break as if a breakpoint was set at that point, without having to remember to set a specific breakpoint there in the debugger, and without interfering with…
Rob Parker
  • 4,078
  • 1
  • 25
  • 26
76
votes
7 answers

.net: System.Web.Mail vs System.Net.Mail

I am considering converting a project that I've inherited from .net 1.1 to .net 2.0. The main warning I'm concerned about is that it wants me to switch from System.Web.Mail to using System.Net.Mail. I'm not ready to re-write all the components…
Dana
  • 32,083
  • 17
  • 62
  • 73
75
votes
3 answers

Redirect Trace output to Console

Let's say I'm working on a little batch-processing console app in VB.Net. I want to be able to structure the app like this: Sub WorkerMethod() 'Do some work Trace.WriteLine("Work progress") 'Do more work Trace.WriteLine("Another…
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
72
votes
13 answers

Best way to encode text data for XML

I was looking for a generic method in .Net to encode a string for use in an Xml element or attribute, and was surprised when I didn't immediately find one. So, before I go too much further, could I just be missing the built-in function? Assuming…
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
69
votes
13 answers

Sorting Directory.GetFiles()

System.IO.Directory.GetFiles() returns a string[]. What is the default sort order for the returned values? I'm assuming by name, but if so how much does the current culture effect it? Can you change it to something like creation date? Update:…
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
62
votes
14 answers

How to open a new form from another form

I have form which is opened using ShowDialog Method. In this form i have a Button called More. If we click on More it should open another form and it should close the current form. on More Button's Click event Handler i have written the following…
Dinesh
  • 2,026
  • 7
  • 38
  • 60
62
votes
7 answers

Obsolete attribute causes property to be ignored by XmlSerialization

I'm refactoring some objects that are serialized to XML but need to keep a few properties for backwards compatibility, I've got a method that converts the old object into the new one for me and nulls the obsolete property. I want to use the Obsolete…
Rob Stevenson-Leggett
  • 35,279
  • 21
  • 87
  • 141
61
votes
8 answers

LINQ on the .NET 2.0 Runtime

Can a LINQ enabled app run on a machine that only has the .NET 2.0 runtime installed? In theory, LINQ is nothing more than syntactic sugar, and the resulting IL code should look the same as it would have in .NET 2.0. How can I write LINQ without…
urini
  • 32,483
  • 14
  • 40
  • 37
60
votes
8 answers

Determine number of pages in a PDF file

I need to determine the number of pages in a specified PDF file using C# code (.NET 2.0). The PDF file will be read from the file system, and not from an URL. Does anyone have any idea on how this could be done? Note: Adobe Acrobat Reader is…
Tangiest
  • 43,737
  • 24
  • 82
  • 113
58
votes
12 answers

"This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded"

I'm getting the error: "This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded." I have a .NET 4.0 dll project that is being called by a .NET 2.0 project. Is there a way to reconcile the difference in…
Nick Myers
  • 662
  • 1
  • 5
  • 10
56
votes
5 answers

How does the "Using" statement translate from C# to VB?

For example: BitmapImage bitmap = new BitmapImage(); byte[] buffer = GetHugeByteArray(); // from some external source using (MemoryStream stream = new MemoryStream(buffer, false)) { bitmap.BeginInit(); bitmap.CacheOption =…
Daniel
  • 10,864
  • 22
  • 84
  • 115
56
votes
14 answers

How to get xpath from an XmlNode instance

Could someone supply some code that would get the xpath of a System.Xml.XmlNode instance? Thanks!
joe
  • 16,988
  • 36
  • 94
  • 131