christiantric Member Licensed User Jan 21, 2020 #1 Hello Devs, I have a custom type with a field Doc() As Byte where I store documents. Supported types are txt, docx, xlsx, and images. What I'm trying to do is: - Get the file stream from my istance - Save the file on file system - Open the file with default system program (notepad for txt files, office word for docx, office excel for xlsx). B4X: Copy Sub clvDocuments_ItemClick (Index As Int, Value As Object) Dim item As Document = documentRepo.Read(Value) If item.Doc <> Null And item.FileName.Length > 0 Then FileUtils.BytesToFile(File.DirTemp, item.Description, item.Doc) ' how to open the file now?!? End If End Sub How can I accomplish this? Thanks in advance.
Hello Devs, I have a custom type with a field Doc() As Byte where I store documents. Supported types are txt, docx, xlsx, and images. What I'm trying to do is: - Get the file stream from my istance - Save the file on file system - Open the file with default system program (notepad for txt files, office word for docx, office excel for xlsx). B4X: Copy Sub clvDocuments_ItemClick (Index As Int, Value As Object) Dim item As Document = documentRepo.Read(Value) If item.Doc <> Null And item.FileName.Length > 0 Then FileUtils.BytesToFile(File.DirTemp, item.Description, item.Doc) ' how to open the file now?!? End If End Sub How can I accomplish this? Thanks in advance.
Erel B4X founder Staff member Licensed User Longtime User Jan 22, 2020 #2 I don't know what is FileUtils however you don't need it. You can read and write bytes with File.ReadBytes / WriteBytes. You can use fx.ShowExternalDocument to open files with the default app. Upvote 0
I don't know what is FileUtils however you don't need it. You can read and write bytes with File.ReadBytes / WriteBytes. You can use fx.ShowExternalDocument to open files with the default app.
christiantric Member Licensed User Jan 22, 2020 #3 Erel said: I don't know what is FileUtils however you don't need it. You can read and write bytes with File.ReadBytes / WriteBytes. You can use fx.ShowExternalDocument to open files with the default app. Click to expand... Thank you Erel, this is exactly what I need. I searched in the forum before open this thread but I wonder why I can't find a so simple solution. In FileUtils I have this shorthand method: B4X: Copy Sub BytesToFile (dir As String, fileName As String, data() As Byte) Dim out As OutputStream = File.OpenOutput(dir, fileName, False) out.WriteBytes(data, 0, data.Length) out.Close End Sub ... but File.WriteBytes is even better ;-) Upvote 0
Erel said: I don't know what is FileUtils however you don't need it. You can read and write bytes with File.ReadBytes / WriteBytes. You can use fx.ShowExternalDocument to open files with the default app. Click to expand... Thank you Erel, this is exactly what I need. I searched in the forum before open this thread but I wonder why I can't find a so simple solution. In FileUtils I have this shorthand method: B4X: Copy Sub BytesToFile (dir As String, fileName As String, data() As Byte) Dim out As OutputStream = File.OpenOutput(dir, fileName, False) out.WriteBytes(data, 0, data.Length) out.Close End Sub ... but File.WriteBytes is even better ;-)