I am developing a website for educational domain. I want to store a document (MS Word or text file) in database in binary format using Filestream
in SQL Server 2008. but I am unable to retrieve the document in a textbox.
My code is as follows:
string path = reader.GetString(0);
SqlFileStream stream1 = new SqlFileStream(path, (byte[])reader.GetValue(1), FileAccess.Read, FileOptions.SequentialScan, 0);
StreamReader fs = new StreamReader(stream1);
fs = File.OpenText(path);
string s = fs.ReadToEnd();
txtInput.Text = s;
//lblStatus.Text = "File Succesfully Read!"
fs.Close();
This code only works for documents that are stored on the Filesystem not in the database. So I tried the following code:
string path = reader.GetString(0);
SqlFileStream stream1 = new SqlFileStream(path, (byte[])reader.GetValue(1), FileAccess.Read, FileOptions.SequentialScan, 0);
StreamReader fs = new StreamReader(stream1);
fs = File.OpenText(path);
string s = fs.ReadToEnd();
txtInput.Text = s;
//lblStatus.Text = "File Succesfully Read!"
fs.Close();
In this code, it gives error on line fs = File.OpenText(path);
as "Access denied to path".
Please help!