Solved

Duplicate this code using a different method

Posted on 2013-06-04
2
227 Views
Last Modified: 2013-06-05
I've been Googling for half a day and I still don't know how to do this...

This works but I save the file in the database and I need to read it back from database into stream.

1. I use RadUpload to read the file content and save the file in database and encrypt it.
 
if (RadUpload1.UploadedFiles.Count > 0)
                {
                    foreach (UploadedFile file in RadUpload1.UploadedFiles)
                    {
                         byte[] bytes = new byte[file.ContentLength];
                        file.InputStream.Read(bytes, 0, file.ContentLength);
                       ...
                      //save in databse

Open in new window


2. Now, I need to read the file back. I can do that but I also need to duplicate this row because I don't have RadUpload control when I read it back..
 
 
file.InputStream.Read(bytes, 0, file.ContentLength);

Open in new window


This is how I read the file back from the database. I can even display the file using Response but I don't want to display it. I want to read the content into a stream

Byte[] bytesFile = null;
                 string fileExt = string.Empty;
                 string fileName = string.Empty;

                 using (SqlDataReader sdr = objSqlCmd.ExecuteReader())
                 {
                     while (sdr.Read())
                     {
                         bytesFile = (Byte[]) sdr[2];
                         fileExt = sdr[1].ToString();
                         fileName = sdr[0].ToString();

                     }
                 }

                 var decryptFile = bytesFile; 
                 var decrypted = EncryptDecrypt.EncryptData(decryptFile, key, key, false); //I decrypt the file

Open in new window


   //**** now how I read the content into a stream just like that line of code? Do I need to use  Response.OutputStream OR StreamReader?
0
Comment
Question by:Camillia
2 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39221181
use MemoryStream:
   MemoryStream ms = new MemoryStream(bytesFile, false);

Open in new window

0
 
LVL 7

Author Comment

by:Camillia
ID: 39221682
let me try. Thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now