Dorababu Meka

Dorababu Meka

  • 228
  • 8.3k
  • 1.7m

Help please

Jun 4 2009 2:35 AM
I have written the code for inserting data and retrieving the data in to sql. I am uploading any type of data by this but the problem is when i upload a word document or any other file and if i am viewing that the whole description contained in that document or file is viewing on the page can any one help...

For Inserting:

  string Con = "Data Source=System1;Initial Catalog=master;Integrated Security=True";
       
        SqlConnection Conn = new SqlConnection(Con);
        Conn.Open();

        SqlCommand Cmd = new SqlCommand("web", Conn);
        Cmd.CommandType = CommandType.StoredProcedure;

        SqlParameter p1 = Cmd.Parameters.Add("@data", SqlDbType.VarBinary);
        p1.Direction = ParameterDirection.Input;

        byte[] bImage = new byte[FileUpload1.PostedFile.ContentLength];
        Stream Str = FileUpload1.PostedFile.InputStream;
        Str.Read(bImage, 0, FileUpload1.PostedFile.ContentLength);

        p1.Value = bImage;

        Cmd.ExecuteNonQuery();
        Conn.Close();

For viewing the data :

  string str = "select * from blob where id="+Textbox1.Text+"";
        SqlConnection Conn = new SqlConnection(Conn);
        Conn.Open();
        SqlCommand Cmd = new SqlCommand(str, Conn);
        //SqlCommand objCmd = new SqlCommand("blob1", objConn);
        //objCmd.CommandType = CommandType.StoredProcedure;

        SqlDataReader dr = Cmd.ExecuteReader();
        if (dr.Read())
        {

            Response.BinaryWrite((byte[])dr["data"]);

            Conn.Close();

What i need is when i click on view if it is doc file or any other file it should ask me to download or open the file content to view