private void btnOpen_Click(object sender, EventArgs e) { string cs = @"Data Source=<your server="">;Initial Catalog=MyFsDb;Integrated Security=TRUE"; using (SqlConnection con = new SqlConnection(cs)) { con.Open(); SqlTransaction txn = con.BeginTransaction(); string sql = "SELECT fData.PathName(), GET_FILESTREAM_TRANSACTION_CONTEXT(), fName FROM MyFsTable"; SqlCommand cmd = new SqlCommand(sql, con, txn); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { string filePath = rdr[0].ToString(); byte[] objContext = (byte[])rdr[1]; string fName = rdr[2].ToString(); SqlFileStream sfs = new SqlFileStream(filePath, objContext, System.IO.FileAccess.Read); byte[] buffer = new byte[(int)sfs.Length]; sfs.Read(buffer, 0, buffer.Length); sfs.Close(); // Just write all files in the table to the temp direcotory. // This is probably not how you would do it in the real world. But this is just an example. string filename = @"C:\Temp\" + fName; System.IO.FileStream fs = new System.IO.FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.Write); fs.Write(buffer, 0, buffer.Length); fs.Flush(); fs.Close(); } rdr.Close(); txn.Commit(); con.Close(); } }
string sql = "SELECT fData.PathName(), dbo.GET_FILESTREAM_TRANSACTION_CONTEXT(), fName FROM MyFsTable";
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)