Rashmi

Rashmi

  • NA
  • 1
  • 0

Problem in uploading text file to oracle database using blob

Jan 21 2010 8:20 AM
While retrieving an uploaded file from oracle database, junk characters are displayed at the start & end of the uploaded content. Also it does not show every line. Part of the code can be found below. Can anyone help or has some different solution??

Upload.aspx.cs (Upload file code) 

filename = filMyFile.PostedFile.FileName;                FileStream fls;

                fls = new FileStream(filename, FileMode.Open, FileAccess.Read);

                blob = new byte[fls.Length];

                fls.Read(blob, 0, System.Convert.ToInt32(fls.Length));

                fls.Close();          

                                

                query = "insert into poemmaster values(" + pid + ",'" + txtTitle.Text + "'," + " :BlobParameter," +uid+",'"+ ddlCategory.SelectedValue.ToString() + "',default)";

                OracleParameter blobParameter = new OracleParameter();

                blobParameter.OracleType = OracleType.Blob;

                blobParameter.ParameterName = "BlobParameter";

                blobParameter.Value = blob;

                cmnd = new OracleCommand(query, conn1);

                cmnd.Parameters.Add(blobParameter);

                cmnd.ExecuteNonQuery();

Retrieve.aspx.cs(Retrieve file code)

FileStream FS = new FileStream("word.doc", FileMode.Create);

            foreach (DataRow dr in dt.Rows)

            {

                lblPoemName.Text = dr[1].ToString();

                byte[] blob = (byte[])dr[2];

                lblCategory.Text = dr[4].ToString();

                lblFName.Text = dr[7].ToString();

                lblLName.Text = dr[8].ToString();

                FS.Write(blob, 0, blob.Length);

                FS.Close();

                FileStream fs2 = new FileStream("word.doc", FileMode.Open, FileAccess.Read);

                StreamReader sReader2 = new StreamReader(fs2, System.Text.Encoding.Default);

                line = sReader2.ReadLine();

                while ((line = sReader2.ReadLine()) != null)

                {

                    txtTitle.Text = txtTitle.Text + "\r\n" + sReader2.ReadLine();

                }

                sReader2.Close();

            }