I solved my problem. The problem wasn't opening and reading the bytes in the server. The problem was in the source of the file (before going to the Folder Recieved).
The problem when I was writing the bytes of the file, I was reading and writhing the bytes of the file using This method and then moving the file to the folder "Received". That method gives me an empty byte for each byte the string has.
Byte[] MyBytes = GetBytes(MyDataSet.GetXml())
// MyBytes == {[F], 0 , [O] , 0 , [R] , 0 , [M]}
Maybe I got that answer for the reason Tim S. Said. The GetBytes Method could be reading the string in a different enconding.
The method MyDataSet.GetXml()
gives you the Xml Text without the enconding {<}?xml version="1.0" encoding="utf-8" ?> (removing brakets). So when I decided to remove the zero bytes, I couldn't read them using the DataSet.ReadXml ()
When I found out thoses errors, I decided to change the way I was ureading the Bytes of the file. Instead of using the GetBytes(MyDataSet.GetXml())
, I used this function.
public byte[] GetBytesFromFile(string FilePath)
{
FileStream Reader = null;;
byte[] bts = null ;
try
{
Reader = new FileStream(FilePath, FileMode.Open);
bts = new byte[Reader.Length];
Reader.Read(bts, 0, (int)Reader.Length);
Reader.Close();
}
catch (Exception ex)
{
bts = null;
}
finally
{
if (Reader != null)
Reader.Close();
}
return bts;
}
Why I decided not to use the GetXml() Method? Because when I read the resulting bytes, I was writhing an XML without the Encoding.
Thanks Tim S. for the Ideas.