Reputation: 697
Is it possible to use TextFieldParser on Byte
? I am uploading a file via a Web Service using Byte
and I am having some trouble figuring out if I can access this CSV directly or if I need to first write it to disk. Writing it to disk would be easy, but I am not convinced I need to do so.
TextFieldParser accepts System.IO.Stream
, System.String
(path to file), or System.IO.TextReader
but I cannot figure out if I can get the Byte into one of those easily.
This is what I am looking at and what I would like to do (this code doesn't work)
Public Function Import(ValidationKey As String, FileBytes() As Byte) As String
Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(FileBytes)
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")
'other code here
End Using
'other code here
End Function
Upvotes: 3
Views: 1296
Reputation: 499042
You can read the byte
array into a MemoryStream
- TextFieldParser
will accept it.
Using MemStream As New MemoryStream(FileBytes)
Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(MemStream)
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")
'other code here
End Using
End Using
Upvotes: 4