Can any one provide code for creating alert for low diskspace using C# in my windows application form.
i have only one drive(say C drive). If available disk space reaches 80%, it should automatically show alert as low disk space.
can you help me i providing sample code.
i have taken button and writen code , but it checks only if press the button.
instead i need automatic alert which can pop up when available disk space reaches 80%.
private void btnSample_Click(object sender, EventArgs e) { ArrayList df = new ArrayList(); DriveInfo[] driveListess = DriveInfo.GetDrives(); // Loop through the list of drives foreach (DriveInfo driven in driveListess) { try { if (driven.TotalFreeSpace == 0) { df.Add(driven.Name.ToString() + ": Disk is full . Please check "); } else { df.Add(driven.Name.ToString() + " Drive does not have space. Do you wish to delete some of the files? "); } } catch(Exception ex) { FreeSpace = 0; TotalSize = 0; UsedSpace = 0; Sweep = 0; lblFileSystem.Text = "N/A"; lblFreeSpace.Text = "N/A"; lblUsedSpace.Text = "N/A"; lblTotalSize.Text = "N/A"; } } string Alertmsg = " " ; foreach (string str in df) { Alertmsg += str + Environment.NewLine; } MessageBox.Show(Alertmsg.ToString(),"Alert",MessageBoxButtons.OK,MessageBoxIcon.Warning); }
Open in new window