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   interview questions urls   External Links  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Code Snippets  >>  Programming Code  >>  Dot Net Code  >>  ADO.NET Code
 
 


 

 
 ASP.NET Code interview questions  ASP.NET Code Interview Questions
 VB.NET Code interview questions  VB.NET Code Interview Questions
 C Sharp Code interview questions  C Sharp Code Interview Questions
 ADO.NET Code interview questions  ADO.NET Code Interview Questions
Question
how to retrive file ,using file info on click event of a 
buton and disply it on a web form
 Question Submitted By :: Tina
I also faced this Question!!     Rank Answer Posted By  
 
  Re: how to retrive file ,using file info on click event of a buton and disply it on a web form
Answer
# 1
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();
            }
        }
 
Is This Answer Correct ?    0 Yes 0 No
Kapil
 

 
 
 
Other ADO.NET Code Interview Questions
 
  Question Asked @ Answers
 
How we work on N tire architecture in asp.net Please give me Examle... HCL2
how to retrive file ,using file info on click event of a buton and disply it on a web form Activa-Softec1
In the Design view in Visual Studio 2005 of an ASP.NET web page, what is the easiest way to create an event handler for the default event of an ASP.NET server control?  1
how to connect bind a control to database by writing a stored procedure? Satyam3
 
For more ADO.NET Code Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

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