Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using FileSystemWatcher, I want to get the size of a file present in my folder. Whereas I can find the size of whole folder but not of a file inside that folder. I'm using FileInfo.Length to get the size of the file, for this the FileInfo.Exists property should be true but it is false I don't know why? Even if file already exists.
I'm using the FileSystemWatcher in a windows application whereas my main application is web based (ASP.NET). Now what I want to achieve is that whenever the user creates a new file or copy an existing file in that folder, the application should get the size of the newly created file or copied file and check with the remaining space of that folder because user is given only a limited space (let's say 1 or 2 GB)
E.g. when you save anything in your PC, the space of the hard disk is decreased. I want to do exactly the same thing that when user creates any file and wishes to save it, at that time the space must be checked.
people with brains please come forward to help me in this regard...THANKS

 private void filewatcher_Changed(object sender, FileSystemEventArgs e)
        {
            string path = e.FullPath;
            int index = path.LastIndexOf("\\");
            string filename = path.Substring(index + 1);
            FileInfo fi = new FileInfo(filename);
            string a=filename.Length.ToString();
            txtLog.Text += e.ChangeType + ": " + e.FullPath + "\r\n";
            txtLog.Focus();
            txtLog.Select(txtLog.TextLength, 0);
            txtLog.ScrollToCaret();
        }
private void Monitor_button (object sender, EventArgs e)
        {
            fileWatcher.Path = @txtPath.Text;
            fileWatcher.Filter = txtFilter.Text;
            fileWatcher.IncludeSubdirectories = chkSubdirectories.Checked;
            fileWatcher.EnableRaisingEvents = true;
           
        }
Posted
Updated 29-Jun-10 23:38pm
v2
Comments
Johnny J. 30-Jun-10 5:38am    
Edited your question for readability - Damn, is there something wrong with your keyboard?

1 solution

I wrote an article series about FileSystemWatcher that might help:

FileSystemWatcher - Pure Chaos (Part 1 of 2)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900