SHARE
TWEET

Untitled

a guest Jun 24th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static Image SelectPhoto(int photoId, out string desc)
  2.     {
  3.         const string SelectTSql = @"
  4.             SELECT
  5.             descripcion, Archivo.PathName(), GET_FILESTREAM_TRANSACTION_CONTEXT()
  6.             FROM Fuentes
  7.             WHERE Id = @PhotoId";
  8.  
  9.         Image photo;
  10.         string serverPath;
  11.         byte[] serverTxn;
  12.  
  13.         using (TransactionScope ts = new TransactionScope())
  14.         {
  15.             using (SqlConnection conn = new SqlConnection(ConnStr))
  16.             {
  17.                 conn.Open();
  18.                 using (SqlCommand cmd = new SqlCommand(SelectTSql, conn))
  19.                 {
  20.                     cmd.Parameters.Add("@PhotoId", SqlDbType.Int).Value = photoId;
  21.                     using (SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.
  22.                     SingleRow))
  23.                     {
  24.                         rdr.Read();
  25.                         desc = rdr.GetSqlString(0).Value;
  26.                         serverPath = rdr.GetSqlString(1).Value;
  27.                         serverTxn = rdr.GetSqlBinary(2).Value;
  28.                         rdr.Close();
  29.                     }
  30.                 }
  31.                 photo = LoadPhotoImage(serverPath, serverTxn);
  32.             }
  33.             ts.Complete();
  34.         }
  35.  
  36.         return photo;
  37.     }
  38.  
  39.     private static Image LoadPhotoImage(string filePath, byte[] txnToken)
  40.     {
  41.         Image photo;
  42.         using (SqlFileStream sfs =
  43.         new SqlFileStream(filePath, txnToken, FileAccess.Read))
  44.         {
  45.             photo = Image.FromStream(sfs);
  46.         }
  47.  
  48.         return photo;
  49.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top