Solved

Duplicate this code using a different method

Posted on 2013-06-04
2
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

622 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