Solved

Duplicate this code using a different method

Posted on 2013-06-04
2
238 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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