Welcome to AspAdvice Sign in | Join | Help

Browse by Tags

All Tags » C# Code Snippets   (RSS)

Monitor a specified file location for changes

Assume for a moment that you need to monitor a specific folder and its subfolders for incoming files such as a FTP transfer and you wanted to accomplish such a task without an type of action from the system administrator. To accomplish this I will employ

Return The HTML Code For The Specified Color

string ColorToHtml(Color str) { return "#" + str.ToArgb().ToString( "x" ).Substring(2); } Share this post: email it! | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted by sswafford | (Comments Off)
Filed under:

Download Example #1

This routine is useful when you want to download a file that is otherwise processed by IIS. void DownloadFile( string virtualPath) { // retrieve the physical path of the file to download, and create // a FileInfo object to read its properties string filePath
Posted by sswafford | (Comments Off)
Filed under:

How To Write To An XML File

using System; using System.Xml; namespace ConsoleApplication3 { class Class1 { static void Main( string [] args) { string filename = @"c:\authors.xml" ; XmlTextWriter textwriter = new XmlTextWriter(filename, null ); textwriter.Formatting = Formatting.Indented;
Posted by sswafford | (Comments Off)
Filed under:

Check If A Text File Exist

using System; using System.IO; namespace csharp { class Class1 { static void Main( string [] args) { if (File.Exists( @"c:\myfile.txt" )) { Console.WriteLine( "File exists" ); } else { Console.WriteLine( "Does not exist" ); } } } } Share this post: email
Posted by sswafford | (Comments Off)
Filed under:

How To Create A Text File

using System; using System.IO; namespace csharp { class CreateTextFile { static void Main( string [] args) { FileInfo fileInfo = null ; FileStream fileStream = null ; if (!File.Exists ( @"c:\testfile1.txt" )) { fileInfo = new FileInfo( @"c:\testfile1.txt"
Posted by sswafford | (Comments Off)
Filed under:

Is A Given Number Odd Or Even

using System; namespace OddOrEven { class IsNumberOddOrEven { static void Main( string [] args) { int intValue = 8 ; if ((intValue & 1) == 0) Console.WriteLine( "Number is even" ); else Console.WriteLine( "Number is odd" ); } } } Share this post:
Posted by sswafford | (Comments Off)
Filed under:

Find The Hostname For A Known IP Address

using System; using System.Net; class GetAddress { public static void Main( string [] argv) { if (argv.Length ! = 1) { Console.WriteLine( "Usage: GetAddress address" ); return ; } IPAddress test = IPAddress.Parse(argv[0]); IPHostEntry iphe = Dns.GetHostByAddress(test);
Posted by sswafford | (Comments Off)
Filed under:

Remote Host Information

using System; using System.Net; class ResolveIt { public static void Main( string [] argv) { if (argv.Length ! = 1) { Console.WriteLine( "Usage: ResolveIt address" ); return ; } IPHostEntry iphe = Dns.Resolve(argv[0]); Console.WriteLine( "Information
Posted by sswafford | (Comments Off)
Filed under:

Simple Email Example

using System; using System.Net; using System.Web.Mail; class SimpleEmail { public static void Main() { string from = "youremail@email.com" ; string to = "myemail@email.com" ; string subject = "This is the subject line" ; string body = "This is the body
Posted by sswafford | (Comments Off)
Filed under:

Current Date and Time

class DateTime { public static void Main() { // display the current date and time System.Console.WriteLine( "The current date and time is " + System.DateTime.Now); } } Share this post: email it! | bookmark it! | digg it! | reddit! | kick it! | live it
Posted by sswafford | (Comments Off)
Filed under: