Solved

Duplicate this code using a different method

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

16 Experts available now in Live!

Get 1:1 Help Now