Filestream in sql server and c # for aspx

I am developing a website for an educational domain. I want to save a document (MS Word or text file) in a database in binary format using Filestreamin SQL Server 2008. but I can not get the document in a text box.

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 in the File System, and 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 an error in the line fs = File.OpenText(path); like "Access denied to path."

Please, help!

+3
source share
4 answers

- ​​ , SQL Server 2008.

+1

stream1. StreamReader File.OpenText , T-SQL SqlFileStream.

+1

Windows. SQL Server. Windows , SQL Server .

0

SqlFileStream StreamReader File.OpenText.

StreamReader fs = new StreamReader(stream1);

fs = File.OpenText(path);
string s = fs.ReadToEnd();

File.OpenText , SQL-, . :

StreamReader fs = new StreamReader(stream1);

string s = fs.ReadToEnd();
0

Source: https://habr.com/ru/post/1706701/


All Articles