Visual-C#
DateTime thisDate1 = new DateTime(2011, 6, 10);
Console.WriteLine("Today is " + thisDate1.ToString("MMMM dd,
yyyy") + ".");
DateTimeOffset thisDate2 = new DateTimeOffset(2011, 6, 10,
15, 24, 16,
TimeSpan.Zero);
Console.WriteLine("The current date and time: {0:MM/dd/yy
H:mm:ss zzz}",
thisDate2);
public class IniFile
{
public string path;
[DllImport("
kernel32"
)]
private static extern long
WritePrivateProfileString(string section,
string key,string val,string filePath);
[DllImport("
kernel32"
)]
private static extern int GetPrivateProfileString(string
section,
string key,string def, StringBuilder retVal,
int size,string filePath);
public IniFile(string INIPath)
{
path = INIPath;
}
public void IniWriteValue(string Section,string
Key,string Value)
{
WritePrivateProfileString(Section,Key,Value,this.path);
}
public string IniReadValue(string Section,string Key)
{
StringBuilder temp = new StringBuilder(255);
int i =
GetPrivateProfileString(Section,Key,"
"
,temp,255, this.path);
return temp.ToString();
}
}
/// <summary>
/// Rotates the image by angle.
/// </summary>
/// <param name="oldBitmap">The old bitmap.</param>
/// <param name="angle">The angle.</param>
/// <returns></returns>
private static Bitmap RotateImageByAngle(System.Drawing.Image oldBitmap, float angle)
{
var newBitmap = new Bitmap(oldBitmap.Width, oldBitmap.Height);
var graphics = Graphics.FromImage(newBitmap);
graphics.TranslateTransform((float)oldBitmap.Width / 2, (float)oldBitmap.Height / 2);
graphics.RotateTransform(angle);
graphics.TranslateTransform(-(float)oldBitmap.Width / 2, -(float)oldBitmap.Height / 2);
graphics.DrawImage(oldBitmap, new Point(0, 0));
return newBitmap;
}
using System.Collections;
private ArrayList TextToArraylist(string Pfad)
{
ArrayList Text = new ArrayList();
System.IO.StreamReader SR = new System.IO.StreamReader(Pfad);
while ( SR.Peek() > -1)
{
Text.Add(SR.ReadLine());
}
SR.Close();
return Text;
}
public class ListFiles
{
/// <summary>
/// Creates a list which contains all filenames in a specific folder
/// </summary>
/// <param name="Root">Folder which contains files to be listed</param>
/// <param name="SubFolders">True for scanning subfolders</param>
/// <returns></returns>
public List<string> GetFileList(string Root, bool SubFolders)
{
List<string> FileArray = new List<string>();
try {
string[] Files = System.IO.Directory.GetFiles(Root);
string[] Folders = System.IO.Directory.GetDirectories(Root);
for (int i = 0;
i < Files.Length;
i++)
{
FileArray.Add(Files[i].ToString());
}
if (SubFolders == true)
{
for (int i = 0;
i < Folders.Length;
i++)
{
FileArray.AddRange(GetFileList(Folders[i], SubFolders));
}
}
}
catch (Exception Ex)
{
throw (Ex);
}
return FileArray;
}
}
private void umbennen(string path)
{
// Alle Datainamen aus dem Ordner auslesen und in ein Stringarray speichern
string[] files = Directory.GetFiles(path);
for (int i = 0;
i < files.Length;
i++)
{
string tmp = Path.GetFileName(files[i]);
// Auffüllen der der Stringlänge ( hier auf 9 zeichen mit nullen )
tmp = tmp.PadLeft(9, '0');
// Datei umbennen
File.Move(files[i], this.path + "\\" + tmp);
}
}
Public Class FolderSize
Private Shared FolderSize As Long = 0
''' <summary>
''' Diese Funktion ermittelt die Größe eines Ordners und gibt diese in Byte zurück
''' </summary>
''' <param name="Root">Der Ordner dessen Größe ausgelesen werden soll</param>
Public Shared Function GetFolderSize(ByVal Root As String) As Long
FolderSize = 0
SeekFiles(Root)
Return FolderSize
End Function
Private Shared Sub SeekFiles(ByVal Root As String)
Dim Files() As String = System.IO.Directory.GetFiles(Root)
Dim Folders() As String = System.IO.Directory.GetDirectories(Root)
For i As Integer = 0 To Files.Length - 1
FolderSize += FileLen(Files(i))
Next
For i As Integer = 0 To Folders.Length - 1
SeekFiles(Folders(i))
Next
End Sub
End Class
private string getwochentag(string datum)
{
string[] felder = datum.Split(new char[] { '.'
});
int tag = Convert.ToInt32(felder[0]);
int monat = Convert.ToInt32(felder[1]);
string wochentag = "";
int chkschaltjahr = monat;
int tagesziffer = tag % 7;
switch (monat)
{
case 1:
monat = 0;
break;
case 2:
monat = 3;
break;
case 3:
monat = 3;
break;
case 4:
monat = 6;
break;
case 5:
monat = 1;
break;
case 6:
monat = 4;
break;
case 7:
monat = 6;
break;
case 8:
monat = 2;
break;
case 9:
monat = 5;
break;
case 10:
monat = 0;
break;
case 11:
monat = 3;
break;
case 12:
monat = 5;
break;
}
int jahr = Convert.ToInt32(felder[2].Remove(0, 2));
int jahresziffer = (jahr + (jahr / 4)) % 7;
int jahrzehnt = Convert.ToInt32(felder[2].Remove(2, 2));
int zs2 = jahrzehnt % 4;
int zs3 = 3 - zs2;
int jahrhundert = zs3 * 2;
int wochenziffer = (jahrhundert + jahresziffer + monat + tagesziffer) % 7;
if (chkschaltjahr == 1 || chkschaltjahr == 2)
{
switch (wochenziffer)
{
case 1:
wochentag = "Sonntag";
break;
case 2:
wochentag = "Montag";
break;
case 3:
wochentag = "Dienstag";
break;
case 4:
wochentag = "Mittwoch";
break;
case 5:
wochentag = "Donertag";
break;
case 6:
wochentag = "Freitag";
break;
case 0:
wochentag = "Samstag";
break;
}
}
else
{
switch (wochenziffer)
{
case 0:
wochentag = "Sonntag";
break;
case 1:
wochentag = "Montag";
break;
case 2:
wochentag = "Dienstag";
break;
case 3:
wochentag = "Mittwoch";
&nbsnbsp; break;
case 4:
wochentag = "Donnerstag";
break;
case 5:
wochentag = "Freitag";
break;
case 6:
wochentag = "Samstag";
break;
}
}
return wochentag;
}
string dirName = DateTime.Now.ToString("yyyyMMdd");
/// <summary>
/// Removes the HTML Code.
/// </summary>
/// <param name="Text">The text.</param>
/// <returns>The string without HTML Code</returns>
private string StripHTML(string inputString)
{
return Regex.Replace(inputString, "<.*", string.Empty);
}
private void SendEmail()
{ if(this.tbAddress.Text == "")
{ this.tbAddress.Focus();
MessageBox.Show("Bitte Adresse eingeben");
return;
} if(this.tbSubject.Text == "")
{ tbSubject.Focus();
MessageBox.Show("Betreff eingeben");
return;
}
if(this.rtbBody.Text=="")
{
rtbBody.Focus();
MessageBox.Show("Nachricht eingeben");
return;
}
//Geben Sie hier die smtp-IP ihres Providers ein
System.Web.Mail.SmtpMail.SmtpServer = "smtp.provider.com";
System.Web.Mail.SmtpMail.Send("George Bush", tbAddress.Text, tbSubject.Text, rtbBody.Text);
tbAddress.Text="";
tbSubject.Text="";
rtbBody.Text = "";
}
private void btSend_Click(object sender, System.EventArgs e)
{
SendEmail();
}
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace TL.Drive
{
//Erstellung und Löschung nicht persistenter virtueller
Laufwerke.
//Das Laufwerk muss nach jedem Neustart des Systems
wiederhergestellt werden.
HKLM\System\MountedDevices.
public class VirtualDrive
{
#region Win32
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private static extern bool DefineDosDevice(
int dwFlags,
string lpDeviceName,
string lpTargetPath
);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private static extern int GetDriveType(
string lpRootPathName
);
private const int DDD_RAW_TARGET_PATH = 0x00000001;
private const int DDD_REMOVE_DEFINITION = 0x00000002;
private const int DDD_EXACT_MATCH_ON_REMOVE = 0x00000004;
private const int DRIVE_UNKNOWN = 0;
private const int DRIVE_NO_ROOT_DIR = 1;
private const int DRIVE_FIXED = 3;
#endregion // Win32
#region Öffentliche Methoden
#region Erstellen
Ordner.</param>
erstellen</returns>
public static bool Create(char driveChar, string path)
{
return DDDOperation(driveChar, path, true);
}
#endregion // Erstellen
#endregion //Löschen
#endregion //Öffentliche Methoden
#region Private Methoden
#region DDDOperationen
private static bool DDDOperation(char driveChar, string
path, bool create)
{
//Gültiges Verzeichnis?
if (!Directory.Exists(path))
return false;
string drive = string.Format("{0}:",
driveChar.ToString().ToUpper());
//Existiert das Volumen?
int type = GetDriveType(string.Format("{0}{1}", drive,
Path.DirectorySeparatorChar));
if ((create && type != DRIVE_UNKNOWN && type !=
DRIVE_NO_ROOT_DIR) ||
(!create && type != DRIVE_FIXED))
return false;
int flags = DDD_RAW_TARGET_PATH;
if (!create) flags |= (DDD_REMOVE_DEFINITION |
DDD_EXACT_MATCH_ON_REMOVE);
return DefineDosDevice(
flags,
drive,
string.Format("{0}??{0}{1}",
Path.DirectorySeparatorChar, path)
);
}
#endregion // DDDOperationen
namespace CD_Key
{
public class Win32
{
#region Properties
/// <summary>
/// Reads the Windows CD key from the registry and returns it as string separated by '-' chars.
/// </summary>
public static string WindowsCDKey
{
get
{
RegistryKey rKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
byte[] rpk = (byte[])rKey.GetValue("DigitalProductId", new byte[0]);
string strKey = "";
const int iRPKOffset = 52;
const string strPossibleChars = "BCDFGHJKMPQRTVWXY2346789";
int i = 28;
do
{
long lAccu = 0;
int j = 14;
do
{
lAccu *= 256;
lAccu += Convert.ToInt64(rpk[iRPKOffset + j]);
rpk[iRPKOffset + j] =
Convert.ToByte(
Convert.ToInt64(Math.Floor((float)lAccu / 24.0f)) & Convert.ToInt64(255)
);
lAccu %= 24;
j -= 1;
}
while (j >= 0);
i -= 1;
strKey = strPossibleChars[(int)lAccu].ToString() + strKey;
if ((0 == ((29 - i) % 6)) && (-1 != i))
{
i -= 1;
strKey = "-" + strKey;
}
}
while (i >= 0);
return strKey;
}
}
/// <summary>
/// Reads the Windows CD key from the registry and returns it as string array.
/// </summary>
public static string[] WindowsCDKeyParts
{
get
{
string[] strKeyParts = WindowsCDKey.Split('-');
return strKeyParts;
}
}
#endregion
}
}
private string GetOSandServicepack()
{
OperatingSystem os = Environment.OSVersion;
string osText = "";
if (os.Version.Major == 5)
{
switch (os.Version.Minor)
{
case 0: osText = "Windows 2000";
break;
case 1: osText = "Windows XP";
break;
case 2: osText = "Windows Server 2003";
break;
default: osText = os.ToString();
break;
}
}
else
{
if (os.Version.Major == 6)
osText = "Windows Vista";
else
osText = os.ToString();
}
string osVersion = os.VersionString;
string spText = os.ServicePack;
// parameterweise zurück ..
return string.Format("{0} , {1}", osText, spText );
}