Click here to Skip to main content
15,917,455 members
Home / Discussions / C#
   

C#

 
GeneralRe: get the file type of a file Pin
PIEBALDconsult5-Apr-10 12:02
mvePIEBALDconsult5-Apr-10 12:02 
AnswerRe: get the file type of a file Pin
harold aptroot5-Apr-10 5:11
harold aptroot5-Apr-10 5:11 
GeneralRe: get the file type of a file Pin
PIEBALDconsult5-Apr-10 9:29
mvePIEBALDconsult5-Apr-10 9:29 
GeneralRe: get the file type of a file Pin
harold aptroot5-Apr-10 12:35
harold aptroot5-Apr-10 12:35 
AnswerRe: get the file type of a file Pin
AspDotNetDev5-Apr-10 11:40
protectorAspDotNetDev5-Apr-10 11:40 
QuestionIs there any lnk parser in C#? Pin
newcoder19995-Apr-10 4:07
newcoder19995-Apr-10 4:07 
QuestionWhite Flicker When Observing an Application Using Double Buffer Over RDP Pin
Catfish5405-Apr-10 3:33
Catfish5405-Apr-10 3:33 
QuestionFileSystemWatcher HELP PLEASE !! Pin
Rikq4-Apr-10 21:21
Rikq4-Apr-10 21:21 
Basically i was told to write a file watcher.

what i need is a configuration files that edit the watch path inside the .exe application?
Get the previous time and date this application had run.

This is the code that i haven wrote so far. Also asking if anyone is willingly to be my personal mentor in coding.

<br />
public partial class frmNotifier : Form<br />
{<br />
private StringBuilder m_Sb;<br />
private bool m_bDirty;<br />
private System.IO.FileSystemWatcher m_Watcher;<br />
private bool m_bIsWatching;<br />
<br />
<br />
public frmNotifier()<br />
{<br />
InitializeComponent();<br />
m_Sb = new StringBuilder();<br />
m_bDirty = false;<br />
m_bIsWatching = false;<br />
<br />
<br />
<br />
<br />
RegistryKey rkApp = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);<br />
rkApp.SetValue("MyApp", Application.ExecutablePath.ToString());<br />
<br />
}<br />
<br />
private void frmNotifier_Load(object sender, EventArgs e)<br />
{<br />
//Run the filewatcher raise certain event once they are fired.<br />
string date,time;<br />
date =DateTime.Now.ToString("dd/MM/yyyy");<br />
time = DateTime.Now.ToString("hh:mm:sstt");<br />
<br />
lstNotification.Items.Add("Program executed at: " + date+" , " + time);<br />
<br />
m_bIsWatching = true;<br />
m_Watcher = new System.IO.FileSystemWatcher();<br />
m_Watcher.Filter = "*.*";<br />
m_Watcher.Path = "D:\\TEMP\\";<br />
m_Watcher.IncludeSubdirectories = true;<br />
m_Watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite<br />
| NotifyFilters.FileName | NotifyFilters.DirectoryName;<br />
m_Watcher.Changed += new FileSystemEventHandler(OnChanged);<br />
m_Watcher.Created += new FileSystemEventHandler(OnChanged);<br />
m_Watcher.Deleted += new FileSystemEventHandler(OnChanged);<br />
m_Watcher.Renamed += new RenamedEventHandler(OnRenamed);<br />
m_Watcher.EnableRaisingEvents = true;<br />
<br />
}<br />
<br />
<br />
private void OnChanged(object sender, FileSystemEventArgs e)<br />
{<br />
<br />
if (!m_bDirty)<br />
{<br />
m_Sb.Remove(0, m_Sb.Length);<br />
m_Sb.Append(e.FullPath);<br />
m_Sb.Append(" ");<br />
m_Sb.Append(e.ChangeType.ToString());<br />
m_Sb.Append(" ");<br />
m_Sb.Append(DateTime.Now.ToString());<br />
m_bDirty = true;<br />
}<br />
}<br />
<br />
private void OnRenamed(object sender, RenamedEventArgs e)<br />
{<br />
if (!m_bDirty)<br />
{<br />
m_Sb.Remove(0, m_Sb.Length);<br />
m_Sb.Append(e.OldFullPath);<br />
m_Sb.Append(" ");<br />
m_Sb.Append(e.ChangeType.ToString());<br />
m_Sb.Append(" ");<br />
m_Sb.Append("to ");<br />
m_Sb.Append(e.Name);<br />
m_Sb.Append(" ");<br />
m_Sb.Append(DateTime.Now.ToString());<br />
m_bDirty = true;<br />
<br />
}<br />
}<br />
<br />
private void tmrEditNotify_Tick(object sender, EventArgs e)<br />
{<br />
//update to the list box if file change is detected<br />
if (m_bDirty)<br />
{<br />
lstNotification.BeginUpdate();<br />
lstNotification.Items.Add(m_Sb.ToString());<br />
lstNotification.EndUpdate();<br />
m_bDirty = false;<br />
}<br />
}<br />
<br />
<br />
<br />
<br />
<br />
<br />
private void frmNotifier_Resize(object sender, EventArgs e)<br />
{<br />
if (this.WindowState == FormWindowState.Minimized)<br />
{ //so we check if the form was minimized<br />
if (this.WindowState == FormWindowState.Minimized)//this code gets fired on every resize<br />
{ //so we check if the form was minimized<br />
Hide();//hides the program on the taskbar<br />
FileChangeWatcher.Visible = true;//shows our tray icon<br />
Thread.Sleep(1000);//pause for 3 seconds<br />
//shows a balloon for 1 sec with a title, some text, and the info icon<br />
//other possibilities are: TooltipIcon.None, Tooltipicon.Error, and TooltipIcon.Warning<br />
//FileChangeWatcher.ShowBalloonTip(1000,"NOTICE","File Change Detecter is still running!",ToolTipIcon.Info);<br />
}<br />
<br />
}<br />
}<br />
<br />
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)<br />
{<br />
Show();//shows the program on taskbar<br />
this.WindowState = FormWindowState.Normal;//undoes the minimized state of the form<br />
FileChangeWatcher.Visible = false;//hides tray icon<br />
}<br />
<br />
private void frmNotifier_FormClosing(object sender, FormClosingEventArgs e)<br />
{<br />
m_bIsWatching = false;<br />
m_Watcher.EnableRaisingEvents = false;<br />
m_Watcher.Dispose();<br />
<br />
string date, time,date1,time1;<br />
<br />
date =DateTime.Now.ToString("ddMMyyyy");<br />
time = DateTime.Now.ToString("hhmm tt");<br />
<br />
if (Directory.Exists("c:\\FileChangeLog"))<br />
{<br />
<br />
<br />
<br />
}<br />
else {<br />
Directory.CreateDirectory("C:\\FileChangeLog");<br />
}<br />
<br />
<br />
StreamWriter sw = new StreamWriter(@"c:\FileChangeLog\" + date + "@" + time + "log.txt");<br />
<br />
date1 = DateTime.Now.ToString("dd/MM/yyyy");<br />
time1 = DateTime.Now.ToString("hh:mm:ss:tt");<br />
lstNotification.Items.Add("Program ended at: " + date1 + " , " + time1);<br />
<br />
foreach (string sItem in lstNotification.Items)<br />
{<br />
sw.WriteLine(sItem);<br />
}<br />
sw.Close();<br />
}<br />

AnswerRe: FileSystemWatcher HELP PLEASE !! Pin
OriginalGriff4-Apr-10 21:54
mveOriginalGriff4-Apr-10 21:54 
AnswerRe: FileSystemWatcher HELP PLEASE !! Pin
FyreWyrm5-Apr-10 16:12
FyreWyrm5-Apr-10 16:12 
QuestionHow to send Email in C# through the Exchange Server? Pin
ravis194-Apr-10 21:00
ravis194-Apr-10 21:00 
AnswerRe: How to send Email in C# through the Exchange Server? Pin
Abhinav S4-Apr-10 21:49
Abhinav S4-Apr-10 21:49 
QuestionHow to ATL COM exe(out-of-proc) in .net? Pin
SRKSHOME4-Apr-10 20:32
SRKSHOME4-Apr-10 20:32 
QuestionWindows Service service Account = Network Pin
yadlaprasad4-Apr-10 20:18
yadlaprasad4-Apr-10 20:18 
AnswerRe: Windows Service service Account = Network Pin
Dave Kreskowiak5-Apr-10 1:53
mveDave Kreskowiak5-Apr-10 1:53 
AnswerRe: Windows Service service Account = Network Pin
PIEBALDconsult5-Apr-10 3:38
mvePIEBALDconsult5-Apr-10 3:38 
Questioniteration Pin
adrian5644-Apr-10 19:34
adrian5644-Apr-10 19:34 
AnswerRe: iteration Pin
Abhinav S4-Apr-10 19:51
Abhinav S4-Apr-10 19:51 
GeneralRe: iteration Pin
adrian5644-Apr-10 19:55
adrian5644-Apr-10 19:55 
GeneralRe: iteration Pin
VCsamir4-Apr-10 20:33
VCsamir4-Apr-10 20:33 
GeneralRe: iteration Pin
adrian5645-Apr-10 8:00
adrian5645-Apr-10 8:00 
GeneralRe: iteration Pin
adrian5645-Apr-10 8:01
adrian5645-Apr-10 8:01 
GeneralRe: iteration Pin
adrian5645-Apr-10 19:05
adrian5645-Apr-10 19:05 
AnswerRe: iteration [modified] Pin
PIEBALDconsult7-Apr-10 13:49
mvePIEBALDconsult7-Apr-10 13:49 
QuestionWant to learn how to develop components for .net eg:Chart components Pin
milpo4-Apr-10 18:57
milpo4-Apr-10 18:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.