The compact framework does not include the whole of .NET - as I'm sure you know.
Unfortunately, File.ReadAllBytes and File.WriteAllBytes are two of the casualties.
They are simple to replace though:
public static byte[] ReadAllBytes(string path)
{
byte[] data;
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
{
int offset = 0;
int count = (int) fs.Length;
data = new byte[count];
while (count > 0)
{
int bytesRead = fs.Read(data, offset, count);
offset += bytesRead;
count -= bytesRead;
}
}
return data;
}
WriteAllBytes is the same process in reverse: I'll leave it to you!
"mostafa.elsadany - 6 mins ago
ok can you tell me how i can write this bytes to file on compact thanks for help
Reply
mostafa.elsadany - 4 mins ago
not leave me because i know this code from other site
but i don't know the reverse
anyway thanks for help"
You are kidding, right?
It is kinda simple:
public static void WriteAllBytes(string path, byte[] data)
{
using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None))
{
fs.Write(data, 0, data.Length);
}
}
Even a beginner should be able to work that one out... :laugh: