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;
}