Get domain name
Why are you using WMI? Can’t you use the standard .NET functionality? System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;
Why are you using WMI? Can’t you use the standard .NET functionality? System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;
You could access them as key/value pairs: NameValueCollection section = (NameValueCollection)ConfigurationManager.GetSection(“secureAppSettings”); string userName = section[“userName”]; string userPassword = section[“userPassword”];
When you call GetAllAnimals it doesn’t actually execute any code until you enumerate the returned IEnumerable in a foreach loop. The dataContext is being disposed as soon as the wrapper method returns, before you enumerate the IEnumerable. The simplest solution would be to make the wrapper method an iterator as well, like this: public static … Read more
Using has virtually the same syntax in VB as C#, assuming you’re using .NET 2.0 or later (which implies the VB.NET v8 compiler or later). Basically, just remove the braces and add a “End Using” Dim bitmap as New BitmapImage() Dim buffer As Byte() = GetHugeByteArrayFromExternalSource() Using stream As New MemoryStream(buffer, false) bitmap.BeginInit() bitmap.CacheOption = … Read more
Okay, I couldn’t resist having a go at it. It’ll only work for attributes and elements, but hey… what can you expect in 15 minutes 🙂 Likewise there may very well be a cleaner way of doing it. It is superfluous to include the index on every element (particularly the root one!) but it’s easier … Read more
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 framework? Not that way round, no. The .NET 4 CLR can load .NET 2 assemblies (usually – there are a few exceptions for mixed-mode assemblies, IIRC), but not vice versa. … Read more
EDIT: After reading a MS Connect article, it appears that .Net 2.0 has a ‘feature’ where it makes ObsoleteAttribute equivalent to XmlIgnoreAttribute without any notification in the documentation. So I’m going to revise my answer to say that the only way to have your cake and eat it too in this instance is to follow … Read more
You’ll need a PDF API for C#. iTextSharp is one possible API, though better ones might exist. iTextSharp Example You must install iTextSharp.dll as a reference. Download iTextsharp from SourceForge.net This is a complete working program using a console application. using System; using System.Collections.Generic; using System.Linq; using System.Text; using iTextSharp.text.pdf; using iTextSharp.text.xml; namespace GetPages_PDF { … Read more
It’s weird that no one has mentioned LINQBridge. This little awesome project is a backport of LINQ (IEnumerable, but without IQueryable) and its dependencies (Func, Action, etc) to .NET 2.0. And: If your project references LINQBridge during compilation, then it will bind to LINQBridge’s query operators; if it references System.Core during compilation, then it will … Read more
In my opinion the main form should be responsible for opening both child form. Here is some pseudo that explains what I would do: // MainForm private ChildForm childForm; private MoreForm moreForm; ButtonThatOpenTheFirstChildForm_Click() { childForm = CreateTheChildForm(); childForm.MoreClick += More_Click; childForm.Show(); } More_Click() { childForm.Close(); moreForm = new MoreForm(); moreForm.Show(); } You will just need … Read more