/*/// <summary> * /// Gets the path of the user documents folder on the specified storage card * /// </summary> * /// <param name="storageCard">Path to storage card e.g. "\Storage Card"</param> * /// <returns>Path to user documents folder e.g. "\Storage Card\My Documents"</returns> * public static string GetDocumentsFolder(string storageCard) * { * //create buffer (Max Path) * char[] buffer = new char[256]; * * //get documents folder for supplied storage card * bool success = SHGetDocumentsFolder(storageCard, ref buffer); * * if(!success) * { * Console.WriteLine(System.Runtime.InteropServices.Marshal.GetLastWin32Error().ToString()); * } * * //return documents folder as string * return new string(buffer).TrimEnd('\0'); * } * * [DllImport("ceshell.dll", EntryPoint="#75", SetLastError=true)] * private static extern bool SHGetDocumentsFolder(string pszVolume, ref char[] pszDocs); */ #endregion #region GetFreeSpace /// <summary> /// Obtains the following information about the amount of space available on a disk volume: the total amount of space, the total amount of free space, and the amount of free space available to the user associated with the calling thread. /// <para><b>New in v1.1</b></para> /// </summary> /// <param name="directoryName"><see cref="System.String"/> that specifies a directory on the specified disk. /// This string can be a Universal Naming Convention (UNC) name.</param> /// <returns>A <see cref="DiskFreeSpace"/> structure containing details about the space available on the specified storage media.</returns> public static DiskFreeSpace GetDiskFreeSpace(string directoryName) { DiskFreeSpace result = new DiskFreeSpace(); if (!GetDiskFreeSpaceEx(directoryName, ref result.FreeBytesAvailable, ref result.TotalBytes, ref result.TotalFreeBytes)) { throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error(), "Error retrieving free disk space"); } return(result); }
public DiskFreeSpace GetDiskFreeSpace(string directoryName) { DiskFreeSpace result = new DiskFreeSpace(); if (!GetDiskFreeSpaceEx(directoryName, ref result.FreeBytesAvailable, ref result.TotalBytes, ref result.TotalFreeBytes)) { result.FreeBytesAvailable = 0; result.TotalBytes = 0; result.TotalFreeBytes = 0; //throw new Win32Exception(Marshal.GetLastWin32Error(), "Error retrieving free disk space"); } return(result); }
int DokanOperations.GetDiskFreeSpace( ref ulong freeBytesAvailable, ref ulong totalBytes, ref ulong totalFreeBytes, DokanFileInfo info) { ulong diskFreeBytes = DiskFreeSpace.Get(mLocalFilesPath); ulong controlledSize = WalkTree.GetTotalSize(GetRoot()); freeBytesAvailable = diskFreeBytes - controlledSize; totalBytes = diskFreeBytes; totalFreeBytes = diskFreeBytes - controlledSize; return(0); }
private void QueryFreeSpace(XmlElement pathNode, IOSVolumeDeviceInfo vinfo, string pathName) { DiskFreeSpace space = QueryApi(pathNode, "DiskFreeSpace", vinfo, () => { return(vinfo.GetDiskFreeSpace(pathName)); }, out XmlElement spaceInfo); if (space == null) { return; } WriteApiResult(spaceInfo, "SectorsPerCluster", space.SectorsPerCluster); WriteApiResult(spaceInfo, "BytesPerSector", space.BytesPerSector); WriteApiResult(spaceInfo, "TotalBytes", space.TotalBytes); WriteApiResult(spaceInfo, "TotalBytesFree", space.TotalBytesFree); WriteApiResult(spaceInfo, "UserBytesFree", space.UserBytesFree); }
public Task OnFreeSpace(DiskFreeSpace space) { DiskFreeSpace = space.Disks; return(Task.FromResult(0)); }
public static DiskFreeSpace GetDiskFreeSpace(string directoryName) { DiskFreeSpace result = new DiskFreeSpace(); if (!GetDiskFreeSpaceEx(directoryName, ref result.FreeBytesAvailable, ref result.TotalBytes, ref result.TotalFreeBytes)) { throw new Win32Exception(Marshal.GetLastWin32Error(), "Error retrieving free disk space"); } return result; }
// Methods public DeviceInfo() { this.DevLink = this.GetLink(); this.Man = this.GetManufacturer(); if (this.GetHTCdevice()) { this.Man = "HTC"; } else if (this.GetVoxtelDev()) { this.Man = "VOXTEL"; } else if (this.GetAsusDev()) { this.Man = "ASUS"; } else if (this.GetGlofishDev()) { this.Man = "ETEN"; } else { this.Man = this.GetManufacturer(); if (this.Man.StartsWith("Generic Manufacturer")) { this.Man = "Unknown"; } } string directoryName = @"\"; DiskFreeSpace space = new DiskFreeSpace(); try { if (!GetDiskFreeSpaceEx(directoryName, ref space.FreeBytesAvailable, ref space.TotalBytes, ref space.TotalFreeBytes)) { this.FreeSpace = this.FreeSpace + "?/?"; } else { this.FreeSpace = this.FreeSpace + Convert.ToString((long)(space.FreeBytesAvailable / 0x400L)) + "kb/" + Convert.ToString((space.TotalBytes / 0x400L) + "kb"); } } catch { this.FreeSpace = this.FreeSpace + "N/A"; } DirectoryInfo info = new DirectoryInfo(@"\"); foreach (DirectoryInfo info2 in info.GetDirectories()) { if ((info2.Attributes & FileAttributes.Temporary) == FileAttributes.Temporary) { space = new DiskFreeSpace(); try { if (!GetDiskFreeSpaceEx(info2.FullName, ref space.FreeBytesAvailable, ref space.TotalBytes, ref space.TotalFreeBytes)) { this.FreeSpace = this.FreeSpace + " " + info2.Name + ":?/?"; } else { string freeSpace = this.FreeSpace; this.FreeSpace = freeSpace + " " + info2.Name + ":" + Convert.ToString((long)(space.FreeBytesAvailable / 0x400L)) + "kb/" + Convert.ToString((long)(space.TotalBytes / 0x400L)) + "kb"; } } catch { this.FreeSpace = this.FreeSpace + " " + info2.Name + ":N/A"; } } } }
protected override void Page_Load(object sender, EventArgs e) { Document doc = new Document(new DocumentHead("OpenNETCF File Upload Example")); if (Request.HttpMethod == "POST") { // We will save this file to the Virtual Directory folder if (this.Request.ContentLength > 0 && this.Request.Files.Count > 0 && this.Request.Files[0] != null) { try { //Request FileName includes full path from client string remoteName = Path.GetFileName(this.Request.Files[0].FileName); string fullPath = VIRTUAL_DIRECTORY_LOCAL + remoteName; int uploadSize = this.Request.ContentLength; //We'll need to create the directory if it doesn't exist if (!Directory.Exists(VIRTUAL_DIRECTORY_LOCAL)) { Directory.CreateDirectory(VIRTUAL_DIRECTORY_LOCAL); } else if (File.Exists(fullPath)) { //Overwrite file File.Delete(fullPath); } //Verify there's enough disk space DiskFreeSpace folderSpace = new DiskFreeSpace(); //Use our P/Invoke below to determine free space if (!GetDiskFreeSpaceEx(VIRTUAL_DIRECTORY_LOCAL, ref folderSpace.FreeBytesAvailable, ref folderSpace.TotalBytes, ref folderSpace.TotalFreeBytes)) { throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error(), "Error retrieving free disk space"); } else if (uploadSize > folderSpace.FreeBytesAvailable) { doc.Body.Elements.Add(new RawText("Insufficient disk space on server")); } else { //Save file locally this.Request.Files[0].SaveAs(fullPath); FileInfo fiUploaded = new FileInfo(fullPath); //Indicate success to user doc.Body.Elements.Add(new RawText("Upload success")); doc.Body.Elements.Add(new LineBreak()); doc.Body.Elements.Add(new RawText(String.Format("File upload completed at {0}", fiUploaded.CreationTime.ToLongTimeString()))); } } catch { //Indicate failure to user doc.Body.Elements.Add(new RawText("Upload failure")); } } } else { //Utilitarian browse/upload form Form form = new Form("FileReceiver.aspx", FormMethod.Post, "upload", "upload"); form.ContentType = "multipart/form-data"; form.Add(new RawText("File to upload:")); form.Add(new Upload("upfile")); form.Add(new Button(new ButtonInfo(ButtonType.Submit, "Upload"))); doc.Body.Elements.Add(form); } //Send the document html to the Response object Response.Write(doc.OuterHtml); //Flush the response Response.Flush(); }
private void timer2_Tick(object sender, EventArgs e) { // Disk Usage anzeigen... if (home == "true") { try { DiskFreeSpace used = GetDiskFreeSpace("k:\\"); double disk_quota = Convert.ToDouble(used.TotalBytes); double used_bytes = Convert.ToDouble(used.TotalBytes) - Convert.ToDouble(used.TotalFreeBytes); double free_bytes = Convert.ToDouble(used.TotalFreeBytes); double percet_usage = ((100 / disk_quota) * used_bytes); if ((int)percet_usage < 0) { percet_usage = 0; } if ((int)percet_usage > 100) { percet_usage = 100; } f2.colorProgressBar1.Value = (int)percet_usage; double quota = disk_quota / 1024 / 1024; double usedb = used_bytes / 1024 / 1024; double freespace = free_bytes / 1024 / 1024; f2.label5.Text = "Quota: " + quota.ToString("N2") + " MBytes"; f2.label8.Text = "Belegt: " + usedb.ToString("N2") + " MBytes"; f2.label6.Text = "Frei: " + freespace.ToString("N2") + " MBytes"; if ((int)percet_usage >= 90) { f2.label9.ForeColor = Color.Red; f2.colorProgressBar1.BarColor = Color.Red; } else { f2.label9.ForeColor = Color.Green; f2.colorProgressBar1.BarColor = Color.Green; } f2.label9.Text = ((int)percet_usage).ToString() + "%"; } catch {} } else { f2.label5.Text = "Homelaufwerk nicht eingebunden."; } }