ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 


 

Company >> Activa Softec >> Activa Softec Questions
 
 
Back to Questions Page
Question   how to retrive file ,using file info on click event of a buton and disply it on a web form Rank Answer Posted By  
 Interview Question Submitted By :: Tina
I also faced this Question!!   © ALL Interview .com
Answer
If your document store in database in binary format then
code for retrive the document is

string sqlQuery="write the select statement"
datareaderObject =cmd.executereader(sqlQuery,connectionname);
if(datareaderObject.read())
{
 Response.Buffer = false;
            Response.ClearHeaders();
            Response.ContentType = "application/octet-stream";
            Response.AddHeader("Content-Disposition",
"attachment; filename=" +
datareaderObject["docname"].ToString());

            //Code for streaming the object while writing
            const int ChunkSize = 1024;
            byte[] buffer = new byte[ChunkSize];
            byte[] binary = (datareaderObject["doc"]) as byte[];
            MemoryStream ms = new MemoryStream(binary);
            int SizeToWrite = ChunkSize;
            for (int i = 0; i < binary.GetUpperBound(0) - 1;
i = i + ChunkSize)
            {
                if (!Response.IsClientConnected) return;
                if (i + ChunkSize >= binary.Length)
SizeToWrite = binary.Length - i;
                byte[] chunk = new byte[SizeToWrite];
                ms.Read(chunk, 0, SizeToWrite);
                Response.BinaryWrite(chunk);
                Response.Flush();
            }
            Response.Close();
        }
    }

if document store in virtual path


 if (datareadear.Read())
        {
            FileInfo file = new
System.IO.FileInfo(Server.MapPath("datareadear["filename"].ToString());
            if (file.Exists)
            {
                Response.Clear();
                Response.AddHeader("content-disposition",
"attachment; filename=" + file.Name);
                Response.AddHeader("Content-Length",
file.Length.ToString());
                Response.ContentType =
"application/octet-stream";
                Response.WriteFile(file.FullName);
                Response.End();
            }
            else
            {
                Response.Redirect("../error.aspx?error=" +
"File dose not exits");
                Response.End();
            }
        }
 
0 Kapil
 
 
 
Back to Questions Page
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com