Wrox Programmer Forums
|
BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9
This is the forum to discuss the Wrox book Professional ASP.NET 2.0 Special Edition by Bill Evjen, Scott Hanselman, Devin Rader, Farhan Muhammad, Srinivasa Sivakumar; ISBN: 9780470041789
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 28th, 2009, 07:43 PM
Registered User
 
Join Date: Feb 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Listing 6-11

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.
 
Old August 29th, 2009, 03:53 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

What about:

Code:
myFileUpload.FileBytes

It returns a byte array....

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Listing 8-10 and Listing 8-16. Asp.Net BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 1 February 6th, 2008 01:11 PM
Listing 11-7 Consume an RSS feed. Asp.Net BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 0 November 9th, 2006 05:26 AM
Listing 11-6 Asp.Net BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 0 November 6th, 2006 03:15 PM
Listing 8-11 nike76 BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 1 November 2nd, 2006 02:59 PM
Listing 18-11 <location path='AdminPage.aspx'> terry hutt BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 0 June 20th, 2006 05:35 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.