Link to home
Start Free TrialLog in
Avatar of Camillia
CamilliaFlag for United States of America

asked on

Duplicate this code using a different method

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?
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Camillia

ASKER

let me try. Thanks