|
|
Browse by Tags
All Tags » C# Code Snippets
Showing page 1 of 2 (11 total posts)
-
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 the FileSystemWatcher Class which is located in the System.IO NameSpace. First off open Visual ...
-
string ColorToHtml(Color str)
{
return ''#'' + str.ToArgb().ToString(''x'').Substring(2);
}
-
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 = Server.MapPath(virtualPath);
System.IO.FileInfo targetFile = new ...
-
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 = ...
-
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'');
}
}
}
}
-
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'');
fileStream = fileInfo.Create( );
Console.WriteLine(''File created ...
-
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'');
}
}
}
-
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);
Console.WriteLine(''Information for ...
-
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 for {0}'', argv[0]);
Console.WriteLine(''Host name: {0}'', ...
-
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 of the message'';
SmtpMail.SmtpServer = ...
1
|
|
|