SD Memory status

  • Thread starter Thread starter Ofer B.
  • Start date Start date
O

Ofer B.

Is it possible to know the sd card memoty status with c#?

And of course, how?

Ofer
 
Here is a little sample, P/Invoking GetDiskFreeSpaceEx


--------------------------- file MemoryStatus.cs ----------------------

using System;
using System.Runtime.InteropServices;

namespace SmartDeviceApplication2
{

public class MemoryStatus
{
[DllImport("coredll.dll")]
public static extern bool GetDiskFreeSpaceEx (
string lpDirectoryName,
out ulong lpFreeBytesAvailableToCaller,
out ulong lpTotalNumberOfBytes,
out ulong lpTotalNumberOfFreeBytes
);

public const string STORAGE_INTERNAL = "\\";
public const string STORAGE_CARD = "\\storage card\\";

public MemoryStatus()
{
}

public static void GetStorageInfo (string storagePath, out int
totalBytes, out int availBytes)
{
ulong freeBytesAvail, totalBytesAvail, freeBytesTotal;
bool result = GetDiskFreeSpaceEx(storagePath, out freeBytesAvail, out
totalBytesAvail, out freeBytesTotal);

if (result == true)
{
totalBytes = Convert.ToInt32(totalBytesAvail);
availBytes = (int)freeBytesAvail;
}
else
{
totalBytes = -1;
availBytes = -1;
}
}
}
}

--------------------------- end file MemoryStatus.cs ----------------------

Usage:

int totalBytes, availBytes;

MemoryStatus.GetStorageInfo(MemoryStatus.STORAGE_CARD, out totalBytes, out
availBytes);
label1.Text = totalBytes.ToString();
 
Is there a way to get the actual path to the SD-card independent on machine?
For example, on Dell Axim the path would be \SD Card\ while on a Intermec
700C it's \SDMMC disk\

br,

Peter


Maarten Struys said:
Here is a little sample, P/Invoking GetDiskFreeSpaceEx


--------------------------- file MemoryStatus.cs ----------------------

using System;
using System.Runtime.InteropServices;

namespace SmartDeviceApplication2
{

public class MemoryStatus
{
[DllImport("coredll.dll")]
public static extern bool GetDiskFreeSpaceEx (
string lpDirectoryName,
out ulong lpFreeBytesAvailableToCaller,
out ulong lpTotalNumberOfBytes,
out ulong lpTotalNumberOfFreeBytes
);

public const string STORAGE_INTERNAL = "\\";
public const string STORAGE_CARD = "\\storage card\\";

public MemoryStatus()
{
}

public static void GetStorageInfo (string storagePath, out int
totalBytes, out int availBytes)
{
ulong freeBytesAvail, totalBytesAvail, freeBytesTotal;
bool result = GetDiskFreeSpaceEx(storagePath, out freeBytesAvail, out
totalBytesAvail, out freeBytesTotal);

if (result == true)
{
totalBytes = Convert.ToInt32(totalBytesAvail);
availBytes = (int)freeBytesAvail;
}
else
{
totalBytes = -1;
availBytes = -1;
}
}
}
}

--------------------------- end file
MemoryStatus.cs ----------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top