Search found 71 matches
- Thu Dec 31, 2009 9:47 am
- Forum: .NET Programming
- Topic: Extract multiple items using one regular expression in C#
- Replies: 0
- Views: 2046
Extract multiple items using one regular expression in C#
First, create a regular expression with named patterns, for example, IPAddr, Day, etc. The Discard named pattern names items that are not used. Then use the Match Result method to extract the item corresponding to the named pattern. String Pattern = @"(?[\S]+)(?[\s-\[]*)(?\d{1,2})(?/)(?[a-zA-Z]+)(?/...
- Thu Dec 31, 2009 9:41 am
- Forum: .NET Programming
- Topic: Extract the timestamp from a JPEG file's EXIF metadata in C#
- Replies: 0
- Views: 2706
Extract the timestamp from a JPEG file's EXIF metadata in C#
In addition to the bits of an image, JPEG files have timestamps and other information embedded inside. The metadata consists of EXIF (Exchangable Image File Format) tags. You can extract a JPEG file's timestamp as follows: 1. Instantiate an ASCIIEncoding object. 2. Instantiate an Image object associ...
- Thu Dec 31, 2009 9:36 am
- Forum: .NET Programming
- Topic: How to determine system uptime without overflow issues in C#
- Replies: 0
- Views: 1986
How to determine system uptime without overflow issues in C#
Environment.TickCount returns a 32-bit signed integer containing the amount of time in milliseconds that has passed since the last time the computer was started. But this value can overflow for systems that stay up for days at a time. To avoid this overflow problem, you can query the "System Up Time...
- Thu Dec 31, 2009 9:33 am
- Forum: .NET Programming
- Topic: How to pretty-print XML in C#
- Replies: 0
- Views: 6995
How to pretty-print XML in C#
It's easy to attractively format XML data as long as it's well-formed. Just load the XML into an XmlDocument. Then write the XML into an XmlTextWriter with formatting enabled. finally, extract the XML text from the XmlTextWriter. // Attractively format the XML with consistant indentation. public sta...
- Thu Dec 31, 2009 9:21 am
- Forum: .NET Programming
- Topic: How to determine angle between two geographical locations C#
- Replies: 0
- Views: 1832
How to determine angle between two geographical locations C#
Use the following method to determine the angle subtended at the earth's center by two geographical coordinates. Latitude is positive north of the equator. Longitude is negative west of Greenwich. Both latitude and longitude are specified in degrees: public static double AngleBetweenLocations(double...
- Thu Dec 31, 2009 9:17 am
- Forum: .NET Programming
- Topic: How to send folders and/or files to the Recycle Bin
- Replies: 0
- Views: 1849
How to send folders and/or files to the Recycle Bin
Use the SHFileOperation API. In the SHFILEOPSTRUCT that you pass to SHFileOperation, set the pFrom field to a string containing each file or folder path seperated by a null character. Make sure that there is an additional null character at the end of the pFrom string. This code is adapted from sourc...
- Thu Dec 31, 2009 9:13 am
- Forum: .NET Programming
- Topic: How to send an e-mail via SMTP in C#
- Replies: 0
- Views: 1809
How to send an e-mail via SMTP in C#
Here's the code to send an e-mail using .Net 2.0's System.Net.Mail namespace. Your SMTP server address is specified in the SmtpClient object's constructor. If you don't know your server address you may be able to find it in your e-mail client's configuration. Note: the .Net 1.1 System.Web.Mail names...
- Thu Dec 31, 2009 9:08 am
- Forum: .NET Programming
- Topic: How to exit from a console application
- Replies: 0
- Views: 1837
How to exit from a console application
Use Environment.Exit to immediately return from a console application with a specified result code. using System; namespace ConsoleApplication1 { class Class1 { [STAThread] static void Main(string[] args) { Console.WriteLine("About to exit"); int exitCode = 0; Environment.Exit(exitCode); // This lin...
- Thu Dec 31, 2009 8:59 am
- Forum: .NET Programming
- Topic: How to install .NET 2.0 SP2 without .NET 3.5 SP1 on Vista
- Replies: 0
- Views: 1906
How to install .NET 2.0 SP2 without .NET 3.5 SP1 on Vista
The .NET Framework 3.5 SP1 was released last fall along with Visual Studio 2008 SP1. The .NET Framework 3.5 SP1 installs the .NET Framework 2.0 SP2 and the .NET Framework 3.0 SP2 behind the scenes as prerequisites. Initially, the only way to get the .NET Framework 2.0 SP2 was to install the full .NE...
- Thu Dec 31, 2009 8:49 am
- Forum: .NET Programming
- Topic: How to return the x86 Program Files directory
- Replies: 0
- Views: 1814
How to return the x86 Program Files directory
This function will return the x86 Program Files directory in all 3 of the windows configurations 32 bit Windows 32 bit program running on 64 bit Windows 64 bit program running on 64 bit windows static string ProgramFilesx86() { if( 8 == IntPtr.Size || (!String.IsNullOrEmpty(Environment.GetEnvironmen...