Contrôle fichier (présence, taille) avec alerte par mail et copie.

Description

Ceci est mon premier programme ( franchement très mal codé, mais je débute ) qui me permet de vérifier sur mes postes de numérisation que je n'excède pas la capacitè de stockage et que je numérise bien ( présence fichier et taille ). Un mail m'averti en cas de problème et je déleste mon serveur de num pour copier ( de façon glissant ) les fichiers vers un autre serveur de stockage celui-ci.

N'hésite pas à le critiquer !!!

Source / Exemple :


//------------------------------------------------------------------------------------------------------------------
//Form 1
//------------------------------------------------------------------------------------------------------------------

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace WindowsApplication3
{
	/// <summary>
	/// Description résumée de Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		#region Variables MMI
		private System.Windows.Forms.ListBox listBox1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.MenuItem menuItem7;
		private System.Windows.Forms.MenuItem menuItem9;
		private System.Windows.Forms.NotifyIcon Notify_Icone;
		private System.Windows.Forms.ContextMenu MenuContextuel;
		private System.Windows.Forms.MenuItem m_restaurer;
		private System.Windows.Forms.Timer TimerCopie;
		private System.Windows.Forms.MenuItem m_fichier;
		private System.Windows.Forms.MenuItem m_parametres;
		private System.Windows.Forms.MenuItem m_iconifier;
		private System.Windows.Forms.MenuItem m_demarrer;
		private System.Windows.Forms.MenuItem m_stop;
		private System.Windows.Forms.MenuItem m_quitter;
		private System.Windows.Forms.MainMenu Mon_Menu;
		private System.Windows.Forms.Button button1;
		private System.ComponentModel.IContainer components;
		#endregion

		#region Constructeur
		/// <summary>
		/// Constructeur
		/// </summary>
		public Form1()
		{
			//
			// Requis pour la prise en charge du Concepteur Windows Forms
			//
			InitializeComponent();

			//
			// TODO : ajoutez le code du constructeur après l'appel à InitializeComponent
			//
		}
		#endregion

		#region Destructeur
		/// <summary>
		/// Nettoyage des ressources utilisées.
		/// </summary>
		/// <param name="disposing">True si l'objet est en cours de destruction</param>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
		#endregion

		#region Windows Form Designer generated code
		/// <summary>
		/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
		/// le contenu de cette méthode avec l'éditeur de code.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
			this.listBox1 = new System.Windows.Forms.ListBox();
			this.label1 = new System.Windows.Forms.Label();
			this.Notify_Icone = new System.Windows.Forms.NotifyIcon(this.components);
			this.MenuContextuel = new System.Windows.Forms.ContextMenu();
			this.m_restaurer = new System.Windows.Forms.MenuItem();
			this.TimerCopie = new System.Windows.Forms.Timer(this.components);
			this.Mon_Menu = new System.Windows.Forms.MainMenu();
			this.m_fichier = new System.Windows.Forms.MenuItem();
			this.m_parametres = new System.Windows.Forms.MenuItem();
			this.menuItem7 = new System.Windows.Forms.MenuItem();
			this.m_iconifier = new System.Windows.Forms.MenuItem();
			this.m_demarrer = new System.Windows.Forms.MenuItem();
			this.m_stop = new System.Windows.Forms.MenuItem();
			this.menuItem9 = new System.Windows.Forms.MenuItem();
			this.m_quitter = new System.Windows.Forms.MenuItem();
			this.button1 = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// listBox1
			// 
			this.listBox1.Location = new System.Drawing.Point(8, 40);
			this.listBox1.Name = "listBox1";
			this.listBox1.Size = new System.Drawing.Size(672, 342);
			this.listBox1.TabIndex = 1;
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 8);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(656, 24);
			this.label1.TabIndex = 2;
			// 
			// Notify_Icone
			// 
			this.Notify_Icone.ContextMenu = this.MenuContextuel;
			this.Notify_Icone.Icon = ((System.Drawing.Icon)(resources.GetObject("Notify_Icone.Icon")));
			this.Notify_Icone.Text = "En attente...";
			this.Notify_Icone.Visible = true;
			// 
			// MenuContextuel
			// 
			this.MenuContextuel.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																						   this.m_restaurer});
			// 
			// m_restaurer
			// 
			this.m_restaurer.Index = 0;
			this.m_restaurer.Text = "Restaurer...";
			this.m_restaurer.Click += new System.EventHandler(this.menuItem5_Click);
			// 
			// TimerCopie
			// 
			this.TimerCopie.Tick += new System.EventHandler(this.timer1_Tick);
			// 
			// Mon_Menu
			// 
			this.Mon_Menu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					 this.m_fichier});
			// 
			// m_fichier
			// 
			this.m_fichier.Index = 0;
			this.m_fichier.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.m_parametres,
																					  this.menuItem7,
																					  this.m_iconifier,
																					  this.m_demarrer,
																					  this.m_stop,
																					  this.menuItem9,
																					  this.m_quitter});
			this.m_fichier.Text = "&Fichier";
			// 
			// m_parametres
			// 
			this.m_parametres.Index = 0;
			this.m_parametres.Text = "&Paramètres";
			this.m_parametres.Click += new System.EventHandler(this.menuItem2_Click);
			// 
			// menuItem7
			// 
			this.menuItem7.Index = 1;
			this.menuItem7.Text = "-";
			// 
			// m_iconifier
			// 
			this.m_iconifier.Index = 2;
			this.m_iconifier.Text = "&Iconifier";
			this.m_iconifier.Click += new System.EventHandler(this.menuItem8_Click);
			// 
			// m_demarrer
			// 
			this.m_demarrer.Index = 3;
			this.m_demarrer.Text = "&Démarrer";
			this.m_demarrer.Click += new System.EventHandler(this.menuItem4_Click);
			// 
			// m_stop
			// 
			this.m_stop.Index = 4;
			this.m_stop.Text = "&Stop";
			this.m_stop.Click += new System.EventHandler(this.menuItem6_Click);
			// 
			// menuItem9
			// 
			this.menuItem9.Index = 5;
			this.menuItem9.Text = "-";
			// 
			// m_quitter
			// 
			this.m_quitter.Index = 6;
			this.m_quitter.Text = "&Quitter";
			this.m_quitter.Click += new System.EventHandler(this.menuItem3_Click);
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(592, 0);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(80, 24);
			this.button1.TabIndex = 3;
			this.button1.Text = "button1";
			//this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(688, 397);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.button1,
																		  this.label1,
																		  this.listBox1});
			this.Menu = this.Mon_Menu;
			this.Name = "Form1";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Form1";
			this.Closed += new System.EventHandler(this.Form1_Closed);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// Affiche la fenêtre des paramètres
		/// </summary>
		/// <param name="sender">Objet Source</param>
		/// <param name="e">Arguments</param>
		private void menuItem2_Click(object sender, System.EventArgs e)
		{
			Form2 fm2 = new Form2();
			fm2.ShowDialog();
			Notify_Icone.Visible=false;
		}

		private void menuItem3_Click(object sender, System.EventArgs e)
		{
			Form1_Closed(sender,e);
		}

		private void menuItem4_Click(object sender, System.EventArgs e)
		{
			//Lancement timer1 ( pour la copie )
			TimerCopie.Interval=10000;
			TimerCopie.Enabled=true;
			Notify_Icone.Text="En cours...";
			//Form cachée
			Notify_Icone.Visible = true;
			this.Visible= false;
		}

		private void menuItem5_Click(object sender, System.EventArgs e)
		{
			this.Visible=true;
		}

		private void menuItem6_Click(object sender, System.EventArgs e)
		{
			TimerCopie.Enabled=false;
		}

		private void menuItem8_Click(object sender, System.EventArgs e)
		{
			this.Visible=false;
			Notify_Icone.Text="En cours...";
			Notify_Icone.Visible = true;
		}

		private void timer1_Tick(object sender, System.EventArgs e)
		{
			#region champs
			BinaryFormatter bfmt = new BinaryFormatter();
			int nbr_heure;
			int nbr_minute;
			int nbr_heure_remote;
			string dossier_local;
			string dossier_distant;
			#endregion
			
			EnvoiMail em = new EnvoiMail();
			//Ces paramètres sont dans le timer afin de les charger dynamiquement

			#region timer_delay catché
			string timer_delay = Environment.CurrentDirectory + "\\timer_delay.ser";
			
			try 
			{
			
				if (File.Exists(timer_delay))
				{
					
					FileStream str = new FileStream(timer_delay,FileMode.Open,FileAccess.Read,FileShare.None);
					nbr_minute= Convert.ToInt32((string) bfmt.Deserialize(str));
					str.Close();
				}
				else
				{
					nbr_minute= 15;
				}
			}
			catch(ArgumentException ae) // path est vide, ne contient que des espaces blancs ou contient un ou plusieurs caractères non valides comme spécifié par InvalidPathChars. 
			{
				this.listBox1.Items.Add (ae.ToString());
				nbr_minute= 15;
			} 
			catch(PathTooLongException ptle) // La longueur de path ou les informations relatives au chemin d'accès absolu pour path excèdent la longueur maximale définie par le système. 
			{
				this.listBox1.Items.Add (ptle.ToString());
				nbr_minute= 15;
			} 
			catch(NotSupportedException nse) // path contient un signe deux-points (:) au milieu de la chaîne. 
			{
				this.listBox1.Items.Add (nse.ToString());
				nbr_minute= 15;
			} 
			#endregion

			#region remote_dir catché
				string remote_dir = Environment.CurrentDirectory + "\\remote_dir.ser";
				
			try
			{
				if (File.Exists(timer_delay))
				{
				
					FileStream str1 = new FileStream(remote_dir,FileMode.Open,FileAccess.Read,FileShare.None);
					dossier_distant= (string) bfmt.Deserialize(str1);
					str1.Close();
				}
				else
				{
					dossier_distant= @"\\HERA\QualiCommun\";
				}
			}
			catch(ArgumentException ae) // path est vide, ne contient que des espaces blancs ou contient un ou plusieurs caractères non valides comme spécifié par InvalidPathChars. 
			{
				this.listBox1.Items.Add (ae.ToString());
				dossier_distant= @"\\HERA\QualiCommun\";
			} 
			catch(PathTooLongException ptle) // La longueur de path ou les informations relatives au chemin d'accès absolu pour path excèdent la longueur maximale définie par le système. 
			{
				this.listBox1.Items.Add (ptle.ToString());
				dossier_distant= @"\\HERA\QualiCommun\";
			} 
			catch(NotSupportedException nse) // path contient un signe deux-points (:) au milieu de la chaîne. 
			{
				this.listBox1.Items.Add (nse.ToString());
				dossier_distant= @"\\HERA\QualiCommun\";
			} 
			#endregion

			#region local_dir catché
				string local_dir = Environment.CurrentDirectory + "\\local_dir.ser";
			try
			{
				if (File.Exists(local_dir))
				{
				
					FileStream str2 = new FileStream(local_dir,FileMode.Open,FileAccess.Read,FileShare.None);
					dossier_local= (string) bfmt.Deserialize(str2);
					str2.Close();
				}
				else
				{
					dossier_local= @"\\QUALI_NUM_TF1\TF1\";
				}
			}
			catch(ArgumentException ae) // path est vide, ne contient que des espaces blancs ou contient un ou plusieurs caractères non valides comme spécifié par InvalidPathChars. 
			{
				this.listBox1.Items.Add (ae.ToString());
				dossier_local= @"\\QUALI_NUM_TF1\TF1\";
			} 
			catch(PathTooLongException ptle) // La longueur de path ou les informations relatives au chemin d'accès absolu pour path excèdent la longueur maximale définie par le système. 
			{
				this.listBox1.Items.Add (ptle.ToString());
				dossier_local= @"\\QUALI_NUM_TF1\TF1\";
			} 
			catch(NotSupportedException nse) // path contient un signe deux-points (:) au milieu de la chaîne. 
			{
				this.listBox1.Items.Add (nse.ToString());
				dossier_local= @"\\QUALI_NUM_TF1\TF1\";
			} 
			#endregion

			#region supress_day catché
				string supress_day = Environment.CurrentDirectory + "\\supress_day.ser";
			try
			{
				if (File.Exists(supress_day))
				{
					FileStream str3 = new FileStream(supress_day,FileMode.Open,FileAccess.Read,FileShare.None);
					nbr_heure= Convert.ToInt32((string) bfmt.Deserialize(str3));
					str3.Close();
				}
				else
				{
					nbr_heure= 72;
				}
			}
			catch(ArgumentException ae) // path est vide, ne contient que des espaces blancs ou contient un ou plusieurs caractères non valides comme spécifié par InvalidPathChars. 
			{
				this.listBox1.Items.Add (ae.ToString());
				nbr_heure= 72;
			} 
			catch(PathTooLongException ptle) // La longueur de path ou les informations relatives au chemin d'accès absolu pour path excèdent la longueur maximale définie par le système. 
			{
				this.listBox1.Items.Add (ptle.ToString());
				nbr_heure= 72;
			} 
			catch(NotSupportedException nse) // path contient un signe deux-points (:) au milieu de la chaîne. 
			{
				this.listBox1.Items.Add (nse.ToString());
				nbr_heure= 72;
			} 
			#endregion

			#region supress_remote catché
				string supress_remote = Environment.CurrentDirectory + "\\supress_remote.ser";
				
			try
			{
				if (File.Exists(supress_remote))
				{
					FileStream str4 = new FileStream(supress_remote,FileMode.Open,FileAccess.Read,FileShare.None);
					nbr_heure_remote= Convert.ToInt32((string) bfmt.Deserialize(str4));
					str4.Close();
				}
				else
				{
					nbr_heure_remote= 120;
				}
			}
			catch(ArgumentException ae) // path est vide, ne contient que des espaces blancs ou contient un ou plusieurs caractères non valides comme spécifié par InvalidPathChars. 
			{
				this.listBox1.Items.Add (ae.ToString());
				nbr_heure_remote= 120;
			} 
			catch(PathTooLongException ptle) // La longueur de path ou les informations relatives au chemin d'accès absolu pour path excèdent la longueur maximale définie par le système. 
			{
				this.listBox1.Items.Add (ptle.ToString());
				nbr_heure_remote= 120;
			} 
			catch(NotSupportedException nse) // path contient un signe deux-points (:) au milieu de la chaîne. 
			{
				this.listBox1.Items.Add (nse.ToString());
				nbr_heure_remote= 120;
			} 
			#endregion

			#region Création d'un tableau des fichiers du dossier_local catché
			ArrayList mes_fichiers = new ArrayList();
			
			try
			{
				string[] fic = Directory.GetFiles(dossier_local);
				if (fic.Length > 0)
				{
					foreach(string f in fic)
					{
						mes_fichiers.Add(f);
					}
				}
			}
			catch(DirectoryNotFoundException dnfe)
			{
				listBox1.Items.Add ("Tab local :" + dnfe.ToString());
			}
			catch(System.Exception se)
			{
				listBox1.Items.Add ("Tab local :" + se.ToString());
			}

			#endregion

			#region Vérification du nombre de fichier créér depuis 15 minutes
			DateTime Ma_Date = DateTime.Now.AddMinutes(-15) ;
			int nbr_fic;
			nbr_fic=0;
			foreach(string mon_fichier in mes_fichiers)
			{
				if (File.GetCreationTime(mon_fichier) < Ma_Date)
				{
					nbr_fic++;
				}
			}
			if (nbr_fic<2)
			{
				if (em.JenvoiUnMail("Pas de numérisation depuis 15 minutes sur "+dossier_local,"KO Numerisation","NumRobot@entreprise.com" )==true)
				{
					listBox1.Items.Add("Envoi OK - Erreur numerisation "+ dossier_local);
				}
				else
				{
					listBox1.Items.Add("Envoi KO - Erreur numerisation "+ dossier_local);
				}
			}
			#endregion

			#region Copie des fichiers de la plage nb_minute catché

				int Compteur_fichier;
				Compteur_fichier =0;			
				Ma_Date = DateTime.Now.AddMinutes(-(int)nbr_minute) ;
				
			if (mes_fichiers.Count > 0)
			{
				foreach(string mon_fichier in mes_fichiers)
				{
					if (File.GetCreationTime(mon_fichier) > Ma_Date)
						//Je vérifie que mon fichier est plus récent que la date - nbr_minute
					{
						if(File.GetLastAccessTime(mon_fichier) < DateTime.Now.AddMinutes(-5))
							//Je vérifie que le dernier accès en écriture du fichier date de plus de 5 minutes (4 minutes plus l'intervalle de 1 min )
						{

							try
							{
								if (File.Exists(dossier_distant + mon_fichier.Replace(dossier_local,""))== false)
									//Je vérifie que le fichier n'est pas présent sur le serveur de stockage
								{
									File.Copy(mon_fichier,dossier_distant + mon_fichier.Replace(dossier_local,""), true);
									listBox1.Items.Add("Copie vers " + dossier_distant + " " + mon_fichier);
									Compteur_fichier ++;
								}
							}
							catch(ArgumentException exc) //path est une chaîne de longueur nulle, ne contient que des espaces blancs ou contient un ou plusieurs caractères non valides comme défini par InvalidPathChars. 
							{
								this.listBox1.Items.Add ("Copie :" +exc.ToString());
							}
							catch(System.Security.SecurityException se) //L'appelant n'a pas l'autorisation requise. 
							{
								this.listBox1.Items.Add ("Copie :" +se.ToString());
							}
							catch(PathTooLongException ptle) //La longueur de path ou les informations relatives au chemin d'accès absolu pour path excèdent la longueur maximale définie par le système. 
							{
								this.listBox1.Items.Add ("Copie :" +ptle.ToString());
							}
							catch(DirectoryNotFoundException dnfe) //Le répertoire spécifié dans path est introuvable. 
							{
								this.listBox1.Items.Add ("Copie :" +dnfe.ToString());
							}
							catch(IOException ioe) //Le fichier spécifié est utilisé. 
							{
								this.listBox1.Items.Add ("Copie :" +ioe.ToString());
							}
							catch(UnauthorizedAccessException uae) //path est un répertoire. 
							{
								this.listBox1.Items.Add ("Copie :" +uae.ToString());
							}
							catch(NotSupportedException nse) // ?
							{
								this.listBox1.Items.Add ("Copie :" +nse.ToString());
							}

						}
					}
					else
					{
						if(Erreur.ControlePresenceFichier(mon_fichier)==false)
						{
							if (em.JenvoiUnMail("Fichier non copié " + dossier_distant + mon_fichier.Replace(dossier_local,""),"KO FileCopy","NumRobot@entreprise.com" )==true)
							{
								listBox1.Items.Add("Envoi OK - Erreur copie fichier "+ dossier_distant + mon_fichier.Replace(dossier_local,""));
							}
							else
							{
								listBox1.Items.Add("Envoi KO - Erreur copie fichier "+ dossier_distant + mon_fichier.Replace(dossier_local,""));
							}
						}
						if (Erreur.ControleTailleFichier(mon_fichier) == false)
						{							
							if (em.JenvoiUnMail("Taille Incorrecte "+mon_fichier,"KO FileSize","NumRobot@entreprise.com" )==true)
							{
								listBox1.Items.Add("Envoi OK - Erreur taille fichier "+mon_fichier);
							}
							else
							{
								listBox1.Items.Add("Envoi KO - Erreur taille fichier "+mon_fichier);
							}
						}
					}
				} 
			}
				listBox1.Items.Add("Copie de " + Compteur_fichier + " fichiers.");
			#endregion

			#region Suppression des fichiers MPEG catché

				DateTime date_fichier = new DateTime();
				DateTime date_reference = new DateTime();
				string sup_fichier;
				foreach(string mon_fichier in mes_fichiers)
				{
					date_fichier = File.GetCreationTime(mon_fichier);
					date_reference = DateTime.Now.AddHours(-(int)nbr_heure);
					if (date_fichier < date_reference)
					{
						sup_fichier = mon_fichier;
						try
						{
							File.Delete(sup_fichier);
							listBox1.Items.Add("Suppression de " + sup_fichier);
						
						}
						catch(ArgumentException exc) //path est une chaîne de longueur nulle, ne contient que des espaces blancs ou contient un ou plusieurs caractères non valides comme défini par InvalidPathChars. 
						{
							this.listBox1.Items.Add ("Sup Mpeg2 Local : " +exc.ToString());
						}
						catch(System.Security.SecurityException se) //L'appelant n'a pas l'autorisation requise. 
						{
							this.listBox1.Items.Add ("Sup Mpeg2 Local : " +se.ToString());
						}
						catch(PathTooLongException ptle) //La longueur de path ou les informations relatives au chemin d'accès absolu pour path excèdent la longueur maximale définie par le système. 
						{
							this.listBox1.Items.Add ("Sup Mpeg2 Local : " +ptle.ToString());
						}
						catch(DirectoryNotFoundException dnfe) //Le répertoire spécifié dans path est introuvable. 
						{
							this.listBox1.Items.Add ("Sup Mpeg2 Local : " +dnfe.ToString());
						}
						catch(IOException ioe) //Le fichier spécifié est utilisé. 
						{
							this.listBox1.Items.Add ("Sup Mpeg2 Local : " +ioe.ToString());
						}
						catch(UnauthorizedAccessException uae) //path est un répertoire. 
						{
							this.listBox1.Items.Add ("Sup Mpeg2 Local : " +uae.ToString());
						}
						catch(NotSupportedException nse) // ?
						{
							this.listBox1.Items.Add ("Sup Mpeg2 Local : " +nse.ToString());
						}
					
						//malgrès l'erreur, je supprime le fichier du tableau
					
						try
						{
							mes_fichiers.Remove(sup_fichier);
						}
						catch(NotSupportedException nse)
						{
							label1.Text =  nse.ToString();
							break;
						}
					
					}
	
				}
			#endregion

			#region Création d'un tableau des fichiers du dossier remote catché
				ArrayList mes_mpeg2 = new ArrayList();
			try
			{
				string[] fics = Directory.GetFiles(dossier_distant);
				if (fics.Length > 0)
				{
					foreach(string f in fics)
					{
						mes_mpeg2.Add(f);
					}
				}
			}
			catch(DirectoryNotFoundException dnfe)
			{
				listBox1.Items.Add ("Tab Mpeg2 Remote : " + dnfe.ToString());
			}
			catch(System.Exception se)
			{
				listBox1.Items.Add ("Tab Mpeg2 Remote : " + se.ToString());
			}
			#endregion
			
			#region Suppression des fichiers MPEG2 sur le dossier remote catché
				
			if (mes_mpeg2.Count > 0)
			{
				foreach(string mon_fic in mes_mpeg2)
				{
					date_fichier = File.GetCreationTime(mon_fic);
					date_reference = DateTime.Now.AddHours(-(int)nbr_heure_remote);
					if (date_fichier < date_reference)
					{
						sup_fichier = mon_fic;
						try
						{
							File.Delete(sup_fichier);
							listBox1.Items.Add("Suppression de " + sup_fichier);
						}
						catch(ArgumentException exc) //path est une chaîne de longueur nulle, ne contient que des espaces blancs ou contient un ou plusieurs caractères non valides comme défini par InvalidPathChars. 
						{listBox1.Items.Add ("Sup Mpeg2 : " + exc.ToString());}
						catch(System.Security.SecurityException se) //L'appelant n'a pas l'autorisation requise. 
						{listBox1.Items.Add ("Sup Mpeg2 : " + se.ToString());}
						catch(PathTooLongException ptle) //La longueur de path ou les informations relatives au chemin d'accès absolu pour path excèdent la longueur maximale définie par le système. 
						{listBox1.Items.Add ("Sup Mpeg2 : " + ptle.ToString());}
						catch(DirectoryNotFoundException dnfe) //Le répertoire spécifié dans path est introuvable. 
						{listBox1.Items.Add ("Sup Mpeg2 : " + dnfe.ToString());}
						catch(IOException ioe) //Le fichier spécifié est utilisé. 
						{listBox1.Items.Add ("Sup Mpeg2 : " + ioe.ToString());}
						catch(UnauthorizedAccessException uae) //path est un répertoire. 
						{listBox1.Items.Add ("Sup Mpeg2 : " + uae.ToString());}
						catch(NotSupportedException nse) // ?
						{listBox1.Items.Add ("Sup Mpeg2 : " + nse.ToString());}

						try
						{
							mes_mpeg2.Remove(sup_fichier);
						}
						catch(NotSupportedException nse)
						{
							label1.Text =  nse.ToString();
							break;
						}
					
					}
	
				}
			}
			#endregion

				TimerCopie.Interval= (int)(1000 * 60 * 5);
			}

		private void Form1_Closed(object sender, System.EventArgs e)
		{
		Application.Exit();
		}
	
		#region Main
		/// <summary>
		/// Point d'entrée principal de l'application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}
		#endregion
	}
}

//------------------------------------------------------------------------------------------------------------------
//Classe Erreur
//------------------------------------------------------------------------------------------------------------------

using System;
using System.IO;
using System.Web.Mail;

namespace WindowsApplication3
{
	/// <summary>
	/// Description résumée de Erreur.
	/// </summary>
	/// 
	public class EnvoiMail
	{
		public EnvoiMail()
		{
			//
			// TODO : ajoutez ici la logique du constructeur
			//
		}
		
		public bool JenvoiUnMail(string body, string subject, string from)
		{
			SmtpMail.SmtpServer ="Serveur";
			System.Web.Mail.MailMessage m = new System.Web.Mail.MailMessage();
			m.Body=body;
			m.Subject=subject;
			m.From=from;
			m.To="monmail@mail.fr";
			try
			{
				SmtpMail.Send(m);
				return true;
			}
			catch(System.Exception)
			{
				return false;
			}
						
		}
	}
	public class Erreur
	{
		#region Constantes
		/// <summary>
		/// 
		/// </summary>
		private const long FILELENGHT=100000000;
		#endregion

		public static bool ControlePresenceFichier(string fichier)
		{
			///<summary>
			///Cette méthode permet de savoir si un fichier est présent
			///sur le répertoire locale
			///</summary>
			if(File.Exists(fichier)) return true;
			return false;

		}
		/// <summary>
		///Cette méthode permet de savoir si le fichier est présent sur
		///le serveur de stockage 
		/// </summary>
		/// <param name="fichier"></param>
		/// <returns></returns>
		public static bool ControleCopieFichier(string fichier)
		{		
			if(File.Exists(fichier))return true;
			return false;
		}

		///<summary>
		///Cette méthode permet de savoir si le fichier à une taille correcte
		///</summary>
		///<param name="fichier"></param>
		///<returns></returns>
		public static bool ControleTailleFichier(string fichier)
		{
			if((new FileInfo(fichier)).Length > FILELENGHT) return true;
				return false;
		}

	}
}

Conclusion :


En faîtes , dans ce programme j'ai surtout utilisé les SystemDate, L'icône dans la barre de tâche, l'assistant déploiement d'application et le mail

Si celà peux servir !!!

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.

Du même auteur (pasmago)