Advertisement
amironov73

ReadAnyTextFile from IRBIS server

Mar 14th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. public static string ReadAnyTextFile
  2.     (
  3.         [NotNull] this IrbisConnection connection,
  4.         [NotNull] string serverPath,
  5.         [NotNull] Encoding encoding
  6.     )
  7. {
  8.     Code.NotNull(connection, "connection");
  9.     Code.NotNullNorEmpty(serverPath, "serverPath");
  10.     Code.NotNull(encoding, "encoding");
  11.  
  12.     connection.RequireServerVersion("2010.1", true);
  13.  
  14.     string result = connection.FormatRecord
  15.         (
  16.             "&uf('+9J" + serverPath + "')",
  17.             1
  18.         );
  19.  
  20.     if (!string.IsNullOrEmpty(result))
  21.     {
  22.         RecordField field = RecordField.Parse("1", result);
  23.         result = field.GetFirstSubFieldValue('b');
  24.         byte[] bytes = IrbisUtility.DecodePercentString(result);
  25.         result = encoding.GetString(bytes);
  26.     }
  27.  
  28.     return result;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement