begin process at 2010 02 10 05:02:19
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Applications

 > APPLICATION SIMPLE POUR MODIFIER LES ATTRIBUTS D'UN FICHIER (DATE DE CRÉATION, DE MODIFICATION, D'ACCÈS)

APPLICATION SIMPLE POUR MODIFIER LES ATTRIBUTS D'UN FICHIER (DATE DE CRÉATION, DE MODIFICATION, D'ACCÈS)


 Information sur la source

Note :
Aucune note
Catégorie :Applications Source .NET ( DotNet ) Classé sous :fichier, attributs, date, modifier, c Niveau :Débutant Date de création :22/04/2007 Date de mise à jour :22/04/2007 01:48:28 Vu / téléchargé :10 756 / 319

Auteur : irnbru

Ecrire un message privé
Commentaire sur cette source (1)
Ajouter un commentaire et/ou une note

 Description

Tout est dit dans le titre, c'est une première version donc surement incomplète et à améliorer.

Source

  • using System;
  • using System.Drawing;
  • using System.Collections;
  • using System.ComponentModel;
  • using System.Windows.Forms;
  • using System.Data;
  • namespace FilesManager
  • {
  • /* Available actions : modify created, last modified and last accessed dates */
  • public enum ACTION : int
  • {
  • CREATED = 1,
  • MODIFIED = 2,
  • ACCESSED = 3
  • }
  • /// <summary>
  • /// A simple windows form application to update file attributes
  • /// </summary>
  • public class FilesManagerUI : System.Windows.Forms.Form
  • {
  • /* date format used */
  • private const string FORMATDATE = "dddd dd MMMM yyyy, hh:mm:ss";
  • /* all dates used */
  • private DateTime dCreated = DateTime.Now;
  • private DateTime dAccessed = DateTime.Now;
  • private DateTime dModified = DateTime.Now;
  • /* file path */
  • private string sPath;
  • /* action selected by the user */
  • private ACTION action;
  • private System.Windows.Forms.Label lblAccessed;
  • private System.Windows.Forms.Label lblModified;
  • private System.Windows.Forms.Label lblCreated;
  • private System.Windows.Forms.GroupBox groupBox1;
  • private System.Windows.Forms.Label lblModifiedDate;
  • private System.Windows.Forms.Label lblAccessedDate;
  • private System.Windows.Forms.Label lblCreatedDate;
  • private System.Windows.Forms.NumericUpDown Date;
  • private System.Windows.Forms.NumericUpDown Month;
  • private System.Windows.Forms.NumericUpDown Year;
  • private System.Windows.Forms.RadioButton Modified;
  • private System.Windows.Forms.RadioButton Accessed;
  • private System.Windows.Forms.RadioButton FCreated;
  • private System.Windows.Forms.Button bModify;
  • private System.Windows.Forms.Button bQuit;
  • private System.Windows.Forms.Button bBrowse;
  • private System.Windows.Forms.StatusBar statusBar;
  • /// <summary>
  • /// Required designer variable.
  • /// </summary>
  • private System.ComponentModel.Container components = null;
  • public FilesManagerUI()
  • {
  • //
  • // Required for Windows Form Designer support
  • //
  • InitializeComponent();
  • //
  • // TODO: Add any constructor code after InitializeComponent call
  • //
  • }
  • /// <summary>
  • /// Clean up any resources being used.
  • /// </summary>
  • protected override void Dispose( bool disposing )
  • {
  • if( disposing )
  • {
  • if (components != null)
  • {
  • components.Dispose();
  • }
  • }
  • base.Dispose( disposing );
  • }
  • #region Windows Form Designer generated code
  • /// <summary>
  • /// Required method for Designer support - do not modify
  • /// the contents of this method with the code editor.
  • /// </summary>
  • private void InitializeComponent()
  • {
  • this.bBrowse = new System.Windows.Forms.Button();
  • this.lblAccessed = new System.Windows.Forms.Label();
  • this.lblModified = new System.Windows.Forms.Label();
  • this.lblCreated = new System.Windows.Forms.Label();
  • this.groupBox1 = new System.Windows.Forms.GroupBox();
  • this.lblCreatedDate = new System.Windows.Forms.Label();
  • this.lblModifiedDate = new System.Windows.Forms.Label();
  • this.lblAccessedDate = new System.Windows.Forms.Label();
  • this.Date = new System.Windows.Forms.NumericUpDown();
  • this.Month = new System.Windows.Forms.NumericUpDown();
  • this.Year = new System.Windows.Forms.NumericUpDown();
  • this.Modified = new System.Windows.Forms.RadioButton();
  • this.Accessed = new System.Windows.Forms.RadioButton();
  • this.FCreated = new System.Windows.Forms.RadioButton();
  • this.bModify = new System.Windows.Forms.Button();
  • this.bQuit = new System.Windows.Forms.Button();
  • this.statusBar = new System.Windows.Forms.StatusBar();
  • this.groupBox1.SuspendLayout();
  • ((System.ComponentModel.ISupportInitialize)(this.Date)).BeginInit();
  • ((System.ComponentModel.ISupportInitialize)(this.Month)).BeginInit();
  • ((System.ComponentModel.ISupportInitialize)(this.Year)).BeginInit();
  • this.SuspendLayout();
  • //
  • // bBrowse
  • //
  • this.bBrowse.Location = new System.Drawing.Point(16, 216);
  • this.bBrowse.Name = "bBrowse";
  • this.bBrowse.TabIndex = 0;
  • this.bBrowse.Text = "&Browse";
  • this.bBrowse.Click += new System.EventHandler(this.bBrowse_Click);
  • //
  • // lblAccessed
  • //
  • this.lblAccessed.Location = new System.Drawing.Point(16, 24);
  • this.lblAccessed.Name = "lblAccessed";
  • this.lblAccessed.Size = new System.Drawing.Size(64, 23);
  • this.lblAccessed.TabIndex = 1;
  • this.lblAccessed.Text = "Accessed :";
  • //
  • // lblModified
  • //
  • this.lblModified.Location = new System.Drawing.Point(16, 56);
  • this.lblModified.Name = "lblModified";
  • this.lblModified.Size = new System.Drawing.Size(64, 23);
  • this.lblModified.TabIndex = 2;
  • this.lblModified.Text = "Modified :";
  • //
  • // lblCreated
  • //
  • this.lblCreated.Location = new System.Drawing.Point(16, 88);
  • this.lblCreated.Name = "lblCreated";
  • this.lblCreated.Size = new System.Drawing.Size(64, 23);
  • this.lblCreated.TabIndex = 3;
  • this.lblCreated.Text = "Created :";
  • //
  • // groupBox1
  • //
  • this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  • | System.Windows.Forms.AnchorStyles.Right)));
  • this.groupBox1.Controls.Add(this.lblCreatedDate);
  • this.groupBox1.Controls.Add(this.lblModifiedDate);
  • this.groupBox1.Controls.Add(this.lblAccessedDate);
  • this.groupBox1.Controls.Add(this.lblAccessed);
  • this.groupBox1.Controls.Add(this.lblCreated);
  • this.groupBox1.Controls.Add(this.lblModified);
  • this.groupBox1.Location = new System.Drawing.Point(16, 48);
  • this.groupBox1.Name = "groupBox1";
  • this.groupBox1.Size = new System.Drawing.Size(368, 128);
  • this.groupBox1.TabIndex = 4;
  • this.groupBox1.TabStop = false;
  • this.groupBox1.Text = "Files Attributes";
  • //
  • // lblCreatedDate
  • //
  • this.lblCreatedDate.Location = new System.Drawing.Point(96, 88);
  • this.lblCreatedDate.Name = "lblCreatedDate";
  • this.lblCreatedDate.Size = new System.Drawing.Size(264, 23);
  • this.lblCreatedDate.TabIndex = 6;
  • //
  • // lblModifiedDate
  • //
  • this.lblModifiedDate.Location = new System.Drawing.Point(96, 56);
  • this.lblModifiedDate.Name = "lblModifiedDate";
  • this.lblModifiedDate.Size = new System.Drawing.Size(264, 23);
  • this.lblModifiedDate.TabIndex = 5;
  • //
  • // lblAccessedDate
  • //
  • this.lblAccessedDate.Location = new System.Drawing.Point(96, 24);
  • this.lblAccessedDate.Name = "lblAccessedDate";
  • this.lblAccessedDate.Size = new System.Drawing.Size(264, 23);
  • this.lblAccessedDate.TabIndex = 4;
  • //
  • // Date
  • //
  • this.Date.Location = new System.Drawing.Point(16, 184);
  • this.Date.Maximum = new System.Decimal(new int[] {
  • 31,
  • 0,
  • 0,
  • 0});
  • this.Date.Name = "Date";
  • this.Date.Size = new System.Drawing.Size(48, 20);
  • this.Date.TabIndex = 5;
  • //
  • // Month
  • //
  • this.Month.Location = new System.Drawing.Point(80, 184);
  • this.Month.Maximum = new System.Decimal(new int[] {
  • 31,
  • 0,
  • 0,
  • 0});
  • this.Month.Name = "Month";
  • this.Month.Size = new System.Drawing.Size(48, 20);
  • this.Month.TabIndex = 6;
  • this.Month.ValueChanged += new System.EventHandler(this.Month_ValueChanged);
  • //
  • // Year
  • //
  • this.Year.Location = new System.Drawing.Point(144, 184);
  • this.Year.Maximum = new System.Decimal(new int[] {
  • 2500,
  • 0,
  • 0,
  • 0});
  • this.Year.Minimum = new System.Decimal(new int[] {
  • 1900,
  • 0,
  • 0,
  • 0});
  • this.Year.Name = "Year";
  • this.Year.Size = new System.Drawing.Size(48, 20);
  • this.Year.TabIndex = 7;
  • this.Year.Value = new System.Decimal(new int[] {
  • 1900,
  • 0,
  • 0,
  • 0});
  • //
  • // Modified
  • //
  • this.Modified.Appearance = System.Windows.Forms.Appearance.Button;
  • this.Modified.Location = new System.Drawing.Point(128, 8);
  • this.Modified.Name = "Modified";
  • this.Modified.TabIndex = 9;
  • this.Modified.Text = "Modified";
  • this.Modified.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
  • this.Modified.CheckedChanged += new System.EventHandler(this.Type_CheckedChanged);
  • //
  • // Accessed
  • //
  • this.Accessed.Appearance = System.Windows.Forms.Appearance.Button;
  • this.Accessed.Location = new System.Drawing.Point(16, 8);
  • this.Accessed.Name = "Accessed";
  • this.Accessed.TabIndex = 10;
  • this.Accessed.Text = "Accessed";
  • this.Accessed.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
  • this.Accessed.CheckedChanged += new System.EventHandler(this.Type_CheckedChanged);
  • //
  • // FCreated
  • //
  • this.FCreated.Appearance = System.Windows.Forms.Appearance.Button;
  • this.FCreated.Location = new System.Drawing.Point(240, 8);
  • this.FCreated.Name = "FCreated";
  • this.FCreated.TabIndex = 11;
  • this.FCreated.Text = "&Created";
  • this.FCreated.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
  • this.FCreated.CheckedChanged += new System.EventHandler(this.Type_CheckedChanged);
  • //
  • // bModify
  • //
  • this.bModify.Location = new System.Drawing.Point(104, 216);
  • this.bModify.Name = "bModify";
  • this.bModify.TabIndex = 12;
  • this.bModify.Text = "&Update";
  • this.bModify.Click += new System.EventHandler(this.bModify_Click);
  • //
  • // bQuit
  • //
  • this.bQuit.Location = new System.Drawing.Point(192, 216);
  • this.bQuit.Name = "bQuit";
  • this.bQuit.TabIndex = 13;
  • this.bQuit.Text = "&Quit";
  • this.bQuit.Click += new System.EventHandler(this.bQuit_Click);
  • //
  • // statusBar
  • //
  • this.statusBar.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  • this.statusBar.Location = new System.Drawing.Point(0, 252);
  • this.statusBar.Name = "statusBar";
  • this.statusBar.Size = new System.Drawing.Size(392, 22);
  • this.statusBar.TabIndex = 14;
  • //
  • // FilesManagerUI
  • //
  • this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  • this.ClientSize = new System.Drawing.Size(392, 274);
  • this.Controls.Add(this.statusBar);
  • this.Controls.Add(this.bQuit);
  • this.Controls.Add(this.bModify);
  • this.Controls.Add(this.FCreated);
  • this.Controls.Add(this.Accessed);
  • this.Controls.Add(this.Modified);
  • this.Controls.Add(this.Year);
  • this.Controls.Add(this.Month);
  • this.Controls.Add(this.Date);
  • this.Controls.Add(this.groupBox1);
  • this.Controls.Add(this.bBrowse);
  • this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
  • this.Name = "FilesManagerUI";
  • this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  • this.Text = "Files Manager";
  • this.Load += new System.EventHandler(this.FilesManagerUI_Load);
  • this.groupBox1.ResumeLayout(false);
  • ((System.ComponentModel.ISupportInitialize)(this.Date)).EndInit();
  • ((System.ComponentModel.ISupportInitialize)(this.Month)).EndInit();
  • ((System.ComponentModel.ISupportInitialize)(this.Year)).EndInit();
  • this.ResumeLayout(false);
  • }
  • #endregion
  • /// <summary>
  • /// The main entry point for the application.
  • /// </summary>
  • [STAThread]
  • static void Main()
  • {
  • Application.Run(new FilesManagerUI());
  • }
  • private void bBrowse_Click(object sender, System.EventArgs e)
  • {
  • /* clear all information for the new selected file */
  • lblAccessedDate.Text = null;
  • lblCreatedDate.Text = null;
  • lblModifiedDate.Text = null;
  • OpenFileDialog oFileDialog = new OpenFileDialog();
  • oFileDialog.InitialDirectory = @"C:\";
  • oFileDialog.Filter = "All Files (*.*)|*.*";
  • oFileDialog.RestoreDirectory = true;
  • if(oFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  • {
  • sPath = oFileDialog.FileName;
  • statusBar.Text = sPath;
  • /* only after the very first file has been choosen */
  • Accessed.Enabled = true;
  • Modified.Enabled = true;
  • FCreated.Enabled = true;
  • /* return all attributes information */
  • GetAllDates();
  • if(FCreated.Checked == false)
  • {
  • FCreated.Checked = true;
  • }
  • else
  • {
  • Date.Value = dCreated.Day;
  • Month.Value = dCreated.Month;
  • Year.Value = dCreated.Year;
  • }
  • }
  • }
  • private void FilesManagerUI_Load(object sender, System.EventArgs e)
  • {
  • FCreated.Checked = true;
  • if(sPath == "" || sPath == null)
  • {
  • FCreated.Enabled = false;
  • Accessed.Enabled = false;
  • Modified.Enabled = false;
  • }
  • }
  • private void Type_CheckedChanged(object sender, System.EventArgs e)
  • {
  • RadioButton button = (RadioButton)sender;
  • if(button.Checked)
  • {
  • switch(button.Name)
  • {
  • case "FCreated" :
  • action = ACTION.CREATED ;
  • Date.Value = dCreated.Day;
  • Month.Value = dCreated.Month;
  • Year.Value = dCreated.Year;
  • break;
  • case "Modified" :
  • action = ACTION.MODIFIED;
  • Date.Value = dModified.Day;
  • Month.Value = dModified.Month;
  • Year.Value = dModified.Year;
  • break;
  • case "Accessed" :
  • action = ACTION.ACCESSED;
  • Date.Value = dAccessed.Day;
  • Month.Value = dAccessed.Month;
  • Year.Value = dAccessed.Year;
  • break;
  • }
  • }
  • }
  • /* As soon as the month is selected, the max number of days is updated based on the month and year */
  • private void Month_ValueChanged(object sender, System.EventArgs e)
  • {
  • Date.Maximum = DateTime.DaysInMonth(Convert.ToInt32(Year.Value), Convert.ToInt32(Month.Value));
  • }
  • private void bModify_Click(object sender, System.EventArgs e)
  • {
  • if(sPath == "" || sPath == null)
  • {
  • MessageBox.Show("You must choose a file first please.","Failure",MessageBoxButtons.OK, MessageBoxIcon.Information);
  • return;
  • }
  • DateTime dNewDate = DateTime.Now;
  • switch(action)
  • {
  • case ACTION.CREATED :
  • dNewDate = new DateTime(Convert.ToInt32(Year.Value),Convert.ToInt32(Month.Value),Convert.ToInt32(Date.Value),dCreated.Hour,dCreated.Minute,dCreated.Second,dCreated.Millisecond);
  • break;
  • case ACTION.MODIFIED :
  • dNewDate = new DateTime(Convert.ToInt32(Year.Value),Convert.ToInt32(Month.Value),Convert.ToInt32(Date.Value),dModified.Hour,dModified.Minute,dModified.Second,dModified.Millisecond);
  • break;
  • case ACTION.ACCESSED :
  • dNewDate = new DateTime(Convert.ToInt32(Year.Value),Convert.ToInt32(Month.Value),Convert.ToInt32(Date.Value),dAccessed.Hour,dAccessed.Minute,dAccessed.Second,dAccessed.Millisecond);
  • break;
  • }
  • /* we can set any date we want for the creation but we can't
  • * set a date older than the creation date for the other cases */
  • if(action != ACTION.CREATED)
  • {
  • if(DateTime.Compare(dNewDate, dCreated) < 0)
  • {
  • MessageBox.Show("You can't set this attribute" + ((action == ACTION.ACCESSED)? " Accessed" : " Modified ") +
  • " to an earlier datetime than the Created datetime!",
  • "Failure",MessageBoxButtons.OK, MessageBoxIcon.Information);
  • return;
  • }
  • }
  • else
  • {
  • if((DateTime.Compare(dNewDate, dModified) > 0)||(DateTime.Compare(dNewDate, dAccessed) > 0))
  • {
  • MessageBox.Show("You can't set this attribute Created " +
  • " to an later datetime than the other datetimes!",
  • "Failure",MessageBoxButtons.OK, MessageBoxIcon.Information);
  • return;
  • }
  • }
  • /* Attributes update */
  • switch(action)
  • {
  • case ACTION.CREATED :
  • System.IO.File.SetCreationTime(sPath, dNewDate);
  • break;
  • case ACTION.MODIFIED :
  • System.IO.File.SetLastWriteTime(sPath, dNewDate);
  • break;
  • case ACTION.ACCESSED :
  • System.IO.File.SetLastAccessTime(sPath, dNewDate);
  • break;
  • }
  • lblAccessedDate.Text = null;
  • lblCreatedDate.Text = null;
  • lblModifiedDate.Text = null;
  • GetAllDates();
  • }
  • private void bQuit_Click(object sender, System.EventArgs e)
  • {
  • this.Close();
  • }
  • private void GetAllDates()
  • {
  • /* string used to display the date */
  • string sDate = "";
  • /* return all information about the file attributes */
  • dAccessed = System.IO.File.GetLastAccessTime(sPath);
  • sDate = dAccessed.ToString(FORMATDATE);
  • lblAccessedDate.Text = lblAccessedDate.Text + sDate;
  • dModified = System.IO.File.GetLastWriteTime(sPath);
  • sDate = dModified.ToString(FORMATDATE);
  • lblModifiedDate.Text = lblModifiedDate.Text + sDate;
  • dCreated = System.IO.File.GetCreationTime(sPath);
  • sDate = dCreated.ToString(FORMATDATE);
  • lblCreatedDate.Text = lblCreatedDate.Text + sDate;
  • }
  • }
  • }
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace FilesManager
{
	/* Available actions : modify created, last modified and last accessed dates */
	public enum ACTION : int
	{
		CREATED		= 1,
		MODIFIED	= 2,
		ACCESSED	= 3
	}
	/// <summary>
	/// A simple windows form application to update file attributes
	/// </summary>
	public class FilesManagerUI : System.Windows.Forms.Form
	{
		/* date format used */
		private const string FORMATDATE = "dddd dd MMMM yyyy, hh:mm:ss";
		
		/* all dates used */
		private DateTime dCreated = DateTime.Now;
		private DateTime dAccessed = DateTime.Now;
		private DateTime dModified = DateTime.Now;

		/* file path */
		private string sPath;

		/* action selected by the user */
		private ACTION action;

		private System.Windows.Forms.Label lblAccessed;
		private System.Windows.Forms.Label lblModified;
		private System.Windows.Forms.Label lblCreated;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Label lblModifiedDate;
		private System.Windows.Forms.Label lblAccessedDate;
		private System.Windows.Forms.Label lblCreatedDate;
		private System.Windows.Forms.NumericUpDown Date;
		private System.Windows.Forms.NumericUpDown Month;
		private System.Windows.Forms.NumericUpDown Year;
		private System.Windows.Forms.RadioButton Modified;
		private System.Windows.Forms.RadioButton Accessed;
		private System.Windows.Forms.RadioButton FCreated;
		private System.Windows.Forms.Button bModify;
		private System.Windows.Forms.Button bQuit;
		private System.Windows.Forms.Button bBrowse;
		private System.Windows.Forms.StatusBar statusBar;

		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public FilesManagerUI()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.bBrowse = new System.Windows.Forms.Button();
			this.lblAccessed = new System.Windows.Forms.Label();
			this.lblModified = new System.Windows.Forms.Label();
			this.lblCreated = new System.Windows.Forms.Label();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.lblCreatedDate = new System.Windows.Forms.Label();
			this.lblModifiedDate = new System.Windows.Forms.Label();
			this.lblAccessedDate = new System.Windows.Forms.Label();
			this.Date = new System.Windows.Forms.NumericUpDown();
			this.Month = new System.Windows.Forms.NumericUpDown();
			this.Year = new System.Windows.Forms.NumericUpDown();
			this.Modified = new System.Windows.Forms.RadioButton();
			this.Accessed = new System.Windows.Forms.RadioButton();
			this.FCreated = new System.Windows.Forms.RadioButton();
			this.bModify = new System.Windows.Forms.Button();
			this.bQuit = new System.Windows.Forms.Button();
			this.statusBar = new System.Windows.Forms.StatusBar();
			this.groupBox1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.Date)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.Month)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.Year)).BeginInit();
			this.SuspendLayout();
			// 
			// bBrowse
			// 
			this.bBrowse.Location = new System.Drawing.Point(16, 216);
			this.bBrowse.Name = "bBrowse";
			this.bBrowse.TabIndex = 0;
			this.bBrowse.Text = "&Browse";
			this.bBrowse.Click += new System.EventHandler(this.bBrowse_Click);
			// 
			// lblAccessed
			// 
			this.lblAccessed.Location = new System.Drawing.Point(16, 24);
			this.lblAccessed.Name = "lblAccessed";
			this.lblAccessed.Size = new System.Drawing.Size(64, 23);
			this.lblAccessed.TabIndex = 1;
			this.lblAccessed.Text = "Accessed :";
			// 
			// lblModified
			// 
			this.lblModified.Location = new System.Drawing.Point(16, 56);
			this.lblModified.Name = "lblModified";
			this.lblModified.Size = new System.Drawing.Size(64, 23);
			this.lblModified.TabIndex = 2;
			this.lblModified.Text = "Modified :";
			// 
			// lblCreated
			// 
			this.lblCreated.Location = new System.Drawing.Point(16, 88);
			this.lblCreated.Name = "lblCreated";
			this.lblCreated.Size = new System.Drawing.Size(64, 23);
			this.lblCreated.TabIndex = 3;
			this.lblCreated.Text = "Created :";
			// 
			// groupBox1
			// 
			this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.groupBox1.Controls.Add(this.lblCreatedDate);
			this.groupBox1.Controls.Add(this.lblModifiedDate);
			this.groupBox1.Controls.Add(this.lblAccessedDate);
			this.groupBox1.Controls.Add(this.lblAccessed);
			this.groupBox1.Controls.Add(this.lblCreated);
			this.groupBox1.Controls.Add(this.lblModified);
			this.groupBox1.Location = new System.Drawing.Point(16, 48);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(368, 128);
			this.groupBox1.TabIndex = 4;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Files Attributes";
			// 
			// lblCreatedDate
			// 
			this.lblCreatedDate.Location = new System.Drawing.Point(96, 88);
			this.lblCreatedDate.Name = "lblCreatedDate";
			this.lblCreatedDate.Size = new System.Drawing.Size(264, 23);
			this.lblCreatedDate.TabIndex = 6;
			// 
			// lblModifiedDate
			// 
			this.lblModifiedDate.Location = new System.Drawing.Point(96, 56);
			this.lblModifiedDate.Name = "lblModifiedDate";
			this.lblModifiedDate.Size = new System.Drawing.Size(264, 23);
			this.lblModifiedDate.TabIndex = 5;
			// 
			// lblAccessedDate
			// 
			this.lblAccessedDate.Location = new System.Drawing.Point(96, 24);
			this.lblAccessedDate.Name = "lblAccessedDate";
			this.lblAccessedDate.Size = new System.Drawing.Size(264, 23);
			this.lblAccessedDate.TabIndex = 4;
			// 
			// Date
			// 
			this.Date.Location = new System.Drawing.Point(16, 184);
			this.Date.Maximum = new System.Decimal(new int[] {
																 31,
																 0,
																 0,
																 0});
			this.Date.Name = "Date";
			this.Date.Size = new System.Drawing.Size(48, 20);
			this.Date.TabIndex = 5;
			// 
			// Month
			// 
			this.Month.Location = new System.Drawing.Point(80, 184);
			this.Month.Maximum = new System.Decimal(new int[] {
																  31,
																  0,
																  0,
																  0});
			this.Month.Name = "Month";
			this.Month.Size = new System.Drawing.Size(48, 20);
			this.Month.TabIndex = 6;
			this.Month.ValueChanged += new System.EventHandler(this.Month_ValueChanged);
			// 
			// Year
			// 
			this.Year.Location = new System.Drawing.Point(144, 184);
			this.Year.Maximum = new System.Decimal(new int[] {
																 2500,
																 0,
																 0,
																 0});
			this.Year.Minimum = new System.Decimal(new int[] {
																 1900,
																 0,
																 0,
																 0});
			this.Year.Name = "Year";
			this.Year.Size = new System.Drawing.Size(48, 20);
			this.Year.TabIndex = 7;
			this.Year.Value = new System.Decimal(new int[] {
															   1900,
															   0,
															   0,
															   0});
			// 
			// Modified
			// 
			this.Modified.Appearance = System.Windows.Forms.Appearance.Button;
			this.Modified.Location = new System.Drawing.Point(128, 8);
			this.Modified.Name = "Modified";
			this.Modified.TabIndex = 9;
			this.Modified.Text = "Modified";
			this.Modified.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			this.Modified.CheckedChanged += new System.EventHandler(this.Type_CheckedChanged);
			// 
			// Accessed
			// 
			this.Accessed.Appearance = System.Windows.Forms.Appearance.Button;
			this.Accessed.Location = new System.Drawing.Point(16, 8);
			this.Accessed.Name = "Accessed";
			this.Accessed.TabIndex = 10;
			this.Accessed.Text = "Accessed";
			this.Accessed.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			this.Accessed.CheckedChanged += new System.EventHandler(this.Type_CheckedChanged);
			// 
			// FCreated
			// 
			this.FCreated.Appearance = System.Windows.Forms.Appearance.Button;
			this.FCreated.Location = new System.Drawing.Point(240, 8);
			this.FCreated.Name = "FCreated";
			this.FCreated.TabIndex = 11;
			this.FCreated.Text = "&Created";
			this.FCreated.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			this.FCreated.CheckedChanged += new System.EventHandler(this.Type_CheckedChanged);
			// 
			// bModify
			// 
			this.bModify.Location = new System.Drawing.Point(104, 216);
			this.bModify.Name = "bModify";
			this.bModify.TabIndex = 12;
			this.bModify.Text = "&Update";
			this.bModify.Click += new System.EventHandler(this.bModify_Click);
			// 
			// bQuit
			// 
			this.bQuit.Location = new System.Drawing.Point(192, 216);
			this.bQuit.Name = "bQuit";
			this.bQuit.TabIndex = 13;
			this.bQuit.Text = "&Quit";
			this.bQuit.Click += new System.EventHandler(this.bQuit_Click);
			// 
			// statusBar
			// 
			this.statusBar.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.statusBar.Location = new System.Drawing.Point(0, 252);
			this.statusBar.Name = "statusBar";
			this.statusBar.Size = new System.Drawing.Size(392, 22);
			this.statusBar.TabIndex = 14;
			// 
			// FilesManagerUI
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(392, 274);
			this.Controls.Add(this.statusBar);
			this.Controls.Add(this.bQuit);
			this.Controls.Add(this.bModify);
			this.Controls.Add(this.FCreated);
			this.Controls.Add(this.Accessed);
			this.Controls.Add(this.Modified);
			this.Controls.Add(this.Year);
			this.Controls.Add(this.Month);
			this.Controls.Add(this.Date);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.bBrowse);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "FilesManagerUI";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Files Manager";
			this.Load += new System.EventHandler(this.FilesManagerUI_Load);
			this.groupBox1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.Date)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.Month)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.Year)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new FilesManagerUI());
		}

		private void bBrowse_Click(object sender, System.EventArgs e)
		{
			/* clear all information for the new selected file */
			lblAccessedDate.Text = null;
			lblCreatedDate.Text = null;
			lblModifiedDate.Text = null;

			OpenFileDialog oFileDialog = new OpenFileDialog();
			
			oFileDialog.InitialDirectory = @"C:\";
			oFileDialog.Filter = "All Files (*.*)|*.*"; 
			oFileDialog.RestoreDirectory = true;

			if(oFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
			{
				sPath = oFileDialog.FileName;
			
				statusBar.Text = sPath;

				/* only after the very first file has been choosen */
				Accessed.Enabled = true;
				Modified.Enabled = true;
				FCreated.Enabled = true;
				
				/* return all attributes information */
				GetAllDates();

				if(FCreated.Checked == false)
				{
					FCreated.Checked = true;
				}
				else
				{
					Date.Value = dCreated.Day;
					Month.Value = dCreated.Month;
					Year.Value = dCreated.Year;
				}
			}
		}

		private void FilesManagerUI_Load(object sender, System.EventArgs e)
		{
			FCreated.Checked = true;
			
			if(sPath == "" || sPath == null)
			{
				FCreated.Enabled = false;
				Accessed.Enabled = false;
				Modified.Enabled = false;
			}
		}

		private void Type_CheckedChanged(object sender, System.EventArgs e)
		{
			RadioButton button = (RadioButton)sender;
			
			if(button.Checked)
			{
				switch(button.Name)
				{
					case "FCreated" :
						action = ACTION.CREATED ;
						Date.Value = dCreated.Day;
						Month.Value = dCreated.Month;
						Year.Value = dCreated.Year;
						break;
					case "Modified" :
						action = ACTION.MODIFIED;
						Date.Value = dModified.Day;
						Month.Value = dModified.Month;
						Year.Value = dModified.Year;
						break;
					case "Accessed" :
						action = ACTION.ACCESSED;
						Date.Value = dAccessed.Day;
						Month.Value = dAccessed.Month;
						Year.Value = dAccessed.Year;
						break;
				}
			}
		}

		/* As soon as the month is selected, the max number of days is updated based on the month and year */
		private void Month_ValueChanged(object sender, System.EventArgs e)
		{
			Date.Maximum = DateTime.DaysInMonth(Convert.ToInt32(Year.Value), Convert.ToInt32(Month.Value));
		}

		private void bModify_Click(object sender, System.EventArgs e)
		{
			if(sPath == "" || sPath == null)
			{
				MessageBox.Show("You must choose a file first please.","Failure",MessageBoxButtons.OK, MessageBoxIcon.Information);
				return;
			}
		
			DateTime dNewDate = DateTime.Now;

			switch(action)
			{
				case ACTION.CREATED		:
					dNewDate = new DateTime(Convert.ToInt32(Year.Value),Convert.ToInt32(Month.Value),Convert.ToInt32(Date.Value),dCreated.Hour,dCreated.Minute,dCreated.Second,dCreated.Millisecond);
					break;
				case ACTION.MODIFIED		:
					dNewDate = new DateTime(Convert.ToInt32(Year.Value),Convert.ToInt32(Month.Value),Convert.ToInt32(Date.Value),dModified.Hour,dModified.Minute,dModified.Second,dModified.Millisecond);
					break;
				case ACTION.ACCESSED		:
					dNewDate = new DateTime(Convert.ToInt32(Year.Value),Convert.ToInt32(Month.Value),Convert.ToInt32(Date.Value),dAccessed.Hour,dAccessed.Minute,dAccessed.Second,dAccessed.Millisecond);
					break;
			}
		
			/* we can set any date we want for the creation but we can't 
			 * set a date older than the creation date for the other cases */
			if(action != ACTION.CREATED)
			{
				if(DateTime.Compare(dNewDate, dCreated) < 0)
				{
					MessageBox.Show("You can't set this attribute" + ((action == ACTION.ACCESSED)? " Accessed" : " Modified ") + 
					" to an earlier datetime than the Created datetime!",
					"Failure",MessageBoxButtons.OK, MessageBoxIcon.Information);
					return;
				}
			}
			else
			{
				if((DateTime.Compare(dNewDate, dModified) > 0)||(DateTime.Compare(dNewDate, dAccessed) > 0))
				{
					MessageBox.Show("You can't set this attribute Created " +
					" to an later datetime than the other datetimes!",
					"Failure",MessageBoxButtons.OK, MessageBoxIcon.Information);
					return;
				}

			}
			/* Attributes update */
			switch(action)
			{ 
				case ACTION.CREATED		:
					System.IO.File.SetCreationTime(sPath, dNewDate);
					break;
				case ACTION.MODIFIED		:
					System.IO.File.SetLastWriteTime(sPath, dNewDate);
					break;
				case ACTION.ACCESSED		:
					System.IO.File.SetLastAccessTime(sPath, dNewDate);
					break;
			}
			
			lblAccessedDate.Text = null;
			lblCreatedDate.Text = null;
			lblModifiedDate.Text = null;
			
			GetAllDates();
		}

		private void bQuit_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void GetAllDates()
		{
			/* string used to display the date */
			string sDate = "";

			/* return all information about the file attributes */
				
			dAccessed = System.IO.File.GetLastAccessTime(sPath);
			sDate = dAccessed.ToString(FORMATDATE);
			lblAccessedDate.Text = lblAccessedDate.Text + sDate;

			dModified = System.IO.File.GetLastWriteTime(sPath);
			sDate = dModified.ToString(FORMATDATE);
			lblModifiedDate.Text = lblModifiedDate.Text + sDate;
				
			dCreated = System.IO.File.GetCreationTime(sPath);
			sDate = dCreated.ToString(FORMATDATE);
			lblCreatedDate.Text = lblCreatedDate.Text + sDate;
		}
	}
}

 Conclusion

Je ferais une mise à jour lors de ma prochaine pause entre deux projets au boulot :) c'est pour passer le temps et apprendre des nouvelles choses !

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Historique

22 avril 2007 01:48:29 :
Mise à jour du code

 Sources de la même categorie

Source avec Zip Source avec une capture Source .NET (Dotnet) RECHERCHE ET GESTION DE FICHIERS PERSONNALISÉES par JeremyLecouvert
Source avec une capture DEFORMÉE D'UNE POUTRE par keiz
Source avec Zip Source avec une capture OUTLOOK RESILIENCY CLEANER par Safti
Source avec Zip Source avec une capture Source .NET (Dotnet) COLORCOMBOBOX, COMBO BOX PERMETTANT DE SÉLECTIONNER DES COUL... par manshivas
Source avec Zip Source avec une capture Source .NET (Dotnet) YREGEXTER - THE REGEX TESTER par pysco68

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture Source .NET (Dotnet) RECHERCHE ET GESTION DE FICHIERS PERSONNALISÉES par JeremyLecouvert
Source .NET (Dotnet) GREP POUR WINDOWS par Warny
Source avec Zip Source .NET (Dotnet) CHECK IDENTICAL FILES par eldim
Source avec Zip Source avec une capture Source .NET (Dotnet) SUPPRIMER LES TAG BOM DANS FICHIER UTF-8 par gluk
Source .NET (Dotnet) PARSER DE NODE XML ALTERNATIF par bubbathemaster

Commentaires et avis

Commentaire de iklolzam le 19/07/2007 12:09:07

Salut,

Au risque de passer pour le parfait débutant, est-il normal de n'avoir aucun fichier .exe associé?
Le programme a l'air prometteur, mais je ne sais commment le lancer.
Merci de votre aide

Iklo

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

DE l'aide SVP Attributs Xml [ par rintchu ] Bonjour,je rencontre des problemes lorsque je veux inserer un attribut dans un node, mais je veux que celui ci depende d'un namespace et j'y arrive pa Modifier un fichier [ par gillescpp ] Voila, j'aimerais savoir si il est possible de modifier un fichier (binaire dans mon cas) ou plus precisément de supprimer ou ajouter des octets a l'i Gérer du xml à travers un datagrid [ par Januka ] Bonjour,j'ai un pb avec un fichier xml que j'aimerais gérer au travers d'une interface, au lieu d'éditer le fichier et le compléter dans un fichier te récupération du résumé d'un fichier image [ par LeGnuff ] Bonjour j'aurai aimé savoir s'il y a un moyen en C# de récupérer les informations stockées dans un fichier image sous Windows XP (dans Propriétés =&gt Date de création d'un fichier [ par thebigboss ] Je voudrais savoir s'il existe une façon de modifier la date de création d'un fichier???Merci d'avance. ajouter, modifier un fichier xml [ par tmcuh ] bonjour, je d&#233;bute un peu dans le xml et j'aurais aim&#233; modifier des donn&#233;es pr&#233;sentes dans un cl&#233; (avec param&#232;tres), raj Date de creation d'un fichier [ par 24 ans ] mon besoin c'est que je veux savoire la date de creation d'un fichier qui se trouve dans un compte ftp .comment faire c'est trop Urgentmerci d'avance Modifier heure et date du PC [ par hetneo ] Bonjour,Je voudrais savoir si il est possible de modifier l'heure et la date du PC en lancant un programme C# ?Par exemple, on charge un fichier qui c [c# /xml] comment modifier un fichier xml par programmation c# [ par moha_yougo ] comment modifier un document xml ,suppr&#233;ssion des element,ajout des elements a des en droit&nbsp; bien pr&#233;cis Modifier le contenu d un fichier [ par titou0809 ] Salut,Je suis un GROS debutant en C# alors please soyez cool :)J aimerais modifier des chaines de caracteres par d autres dans un fichier.Seulement je


Nos sponsors


Sondage...

Comparez les prix


HTC Hero

Entre 550€ et 550€

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 3,510 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales