Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Oracle (http://www.go4expert.com/forums/oracle-forum/)
-   -   Problem in uploading files to Oracle database using blob (http://www.go4expert.com/forums/uploading-files-oracle-database-using-t20726/)

rashmi_s 21Jan2010 18:08

Problem in uploading files to Oracle database using blob
 
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)

Code: C#

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)

Code: C#

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();
}



All times are GMT +5.5. The time now is 09:01.