File.WriteAllBytes for Pocket PC

  • Thread starter Thread starter Nicolas
  • Start date Start date
N

Nicolas

Hi,
How can I convert this following code (from a window application) in a
device application (for PocketPC)

imports System.IO
CONST FILE_NAME1="myXMLfile1.xml"
CONST FILE_NAME2="myXMLfile2.xml"
File.WriteAllBytes(FILE_NAME1, File.ReadAllBytes(FILE_NAME2))


I tried the following but I didn't get very far as I also get a problem into
the xml return string placing an ? in front ------- ?<?xml version="1.0"
encoding="utf-16"?>

'Dim txtRep As String = "<?xml"

Dim fs As New FileStream(FILE_NAME1, FileMode.Open, FileAccess.ReadWrite,
FileShare.None)

Dim binReader As New BinaryReader(fs)

Dim AE As New System.Text.UnicodeEncoding

tmpTXT = AE.GetString(binReader.ReadBytes(fs.Length))

Console.WriteLine(tmpTXT)

binReader.Close()

fs.Close()





Thanks a lot for the help

Nicolas
 
Doesn't

File.Copy(FILE_NAME1,FILE_NAME2)

Have the same outcome - you are just reading all the contents of one file
and writing to another...

Peter
 
Thanks but need more works than that as I should have explain a bit better.
Sorry.
I call a function where I pass the bytes of the file and return bytes as
well but either encrypted or decrypted
File.WriteAllBytes(FILE_NAME1, encryptFile(File.ReadAllBytes(FILE_NAME1)))

Function EncryptFile(ByVal thoseBytes As Byte()) As Byte()

Thank for your help
Nicolas
 
Something like this should work:-

Dim fs As New FileStream(FILE_NAME1, FileMode.Open, FileAccess.ReadWrite,
FileShare.None)
Dim buffer(fs.Length) As Byte
Dim bytesread As Integer = fs.Read(buffer, 0, buffer.Length)
fs.Close()

do your encryption here then write all using:-

Dim fsw As FileStream = File.OpenWrite(FILE_NAME2)
fsw.Write(buffer, 0, buffer.Length)
fsw.Close()

Peter
 
Thank you for your help Peter,

I found the solution as well and I had to use a binaryreader

Thanks again

Nicolas
 
Back
Top