What is the correct way to get the file content into a byte array?
Listing 6-11 shows the following C# code:
Code:
Byte myByteArray[];
System.IO.Stream myStream;
myStream = FileUpload.FileContent;
myByteArray = myStream.ToArray();
I'm getting two errors from this code. The first is a syntax error on the first line which I was able to correct by moving the brackets:
Code:
Byte[] myByteArray;
The second error that I'm getting is on the fourth line. The System.IO.Stream object does not have a ToArray() method. The
VB example above it uses System.IO.MemoryStream, which does have a ToArray() method, but I have to cast the file content:
Code:
myStream = (MemoryStream)FileUpload.FileContent;
...which builds but is throwing an invalid cast error when I run it.
Ultimately I need to pass this into an insert parameter...
Code:
srcDocuments.InsertParameters["DocumentContent"].DefaultValue = myByteArray.ToString();
...and then dump it into SQL but the given method here for doing that is not working.