I need to convert an .sdf file to a binary file. (I think with streamreader?) Then I need to convert this binary file back to .sdf. How do I do this?
From stackoverflow
-
The file itself is already binary, so I'm assuming that you want to read the file into memory as binary. Give this a shot:
public byte[] ReadBinaryFile(string path) { byte[] data; using (System.IO.FileStream stream = new System.IO.FileStream(path, System.IO.FileMode.Open)) { data = new byte[stream.Length]; stream.Read(data, 0, data.Length); } return data; }If you want to write this
byte[]back to the file, do this:public void WriteBinaryFile(string path, byte[] data) { using (System.IO.FileStream stream = new System.IO.FileStream(path, System.IO.FileMode.Create)) { stream.Write(data, 0, data.Length); } }
Edit
I've updated this to encapsulate the logic into two functions.
Gold : thank's alot, how can I insert this in function that return the byte ?Adam Robinson : What do you mean? All of the code you should need should be there for you...just have your function return the byte[] variable called data.Gold : I need to transfer file between WebService and WinCE, and this is the best way. so if you can, to write for me the func that recive and the func that get the data ?. thenk's in advanceAdam Robinson : Edited. How you get the data between the two is up to you, but those two functions should be all you need. The first takes a path and returns the data as a byte[], and the second takes a path and a byte[] and writes the data to the file.Gold : thank you very much
0 comments:
Post a Comment