0

My dilemma is that i need to retrieve the blob data stored in a table in oracle. I have created links with the data using jquery that link to a generic http handler blobHandler.ashx where i query the database for the file and return it to the user. This works for images which open in the browser but when it comes to other file types (pdf, word,excel), the program only downloads the .ashx file itself.

How do i get it to download the file with its extension?

using (OracleConnection objConn = new OracleConnection(conStr))
        {
            using (OracleCommand cmd = new OracleCommand())
            {
                cmd.Connection = objConn;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "SELECT fl.file_content_type, fl.file_data,fl.file_name FROM fnd_lobs fl WHERE fl.file_id = " + mediano;

                try
                {
                    objConn.Open();
                    OracleDataReader dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {

                            OracleBlob blob = dr.GetOracleBlob(1);
                            FileStream FS = new FileStream(dr["file_name"].ToString(), FileMode.Create);
                            Byte[] byteArr = new Byte[blob.Length];
                            int i = blob.Read(byteArr,0,System.Convert.ToInt32(blob.Length));
                            MemoryStream memStream = new MemoryStream(byteArr);

                            context.Response.AddHeader("Content-disposition: inline", "attachment; filename=" + dr["file_name"]);
                            context.Response.ContentType = dr["file_content_type"].ToString();
                            context.Response.OutputStream.Write(byteArr,0,i);



                    }
                    }
                }
                catch(Exception exe)
                {
                    context.Response.Write(exe.Message);
                }
                finally
                {

                    cmd.Dispose();
                    //pcur.Dispose();
                    objConn.Close();
                    objConn.Dispose();
                    context.Response.Flush();
                    context.Response.End();
                }

            }
        }

I am using .net framework 1.1, visual studio 2003, oracle database version 10.3.0.5

thank you in advance for whatever advice you could provide this is my first question here.

user2359298
  • 3
  • 1
  • 5

1 Answers1

1

You need to set the correct content-type header in the response object so the browser knows how to handle the response accordingly.

If you want to set the name of the downloaded file you can take a look here.

Community
  • 1
  • 1
tucaz
  • 6,524
  • 6
  • 37
  • 60
  • thank you for your reply, i made the changes you suggested and now i am getting an "Access to denied" message. have you ever experienced anything like that? – user2359298 May 07 '13 at 18:43
  • What path are u getting access denied? – tucaz May 08 '13 at 16:57
  • the path is c:\windows\system32\inetsrv\* – user2359298 May 08 '13 at 21:48
  • Looks like the "Access Denied" is related to the database access while trying to access some shared DLL or something like that in the Oracle driver. Please post the entire stacktrace – tucaz May 08 '13 at 21:52