) C # Calling dominoapi to connect to Lotus Domino

Source: Internet
Author: User

Http://hi.baidu.com/xuehuaweb/blog/item/4af7d212f7e83a866438dbe1.html

   1:  using System;
   2:  using System.Data;
   3:   
   4:  namespace LotusDbLink
   5:  {
   6:      public class LotusDB
   7:      {
   8:          private string _userName;
   9:          private string _password;
  10:          private string _server;
  11:          private string _databaseName;
  12:          private string _lotusView;
  13:   
  14:          private string _fieldSet;
  15:   
  16:   
  17:          public string UserName
  18:          {
  19:              get { return _userName; }
  20:              set { _userName = value; }
  21:          }
  22:   
  23:          public string Password
  24:          {
  25:              get { return _password; }
  26:              set { _password = value; }
  27:          }
  28:   
  29:          public string Server
  30:          {
  31:              get { return _server; }
  32:              set { _server = value; }
  33:          }
  34:   
  35:          public string DatabaseName
  36:          {
  37:              get { return _databaseName; }
  38:              set { _databaseName = value; }
  39:          }
  40:   
  41:          public string LotusView
  42:          {
  43:              get { return _lotusView; }
  44:              set { _lotusView = value; }
  45:          }
  46:   
  47:          public string FieldSet
  48:          {
  49:              get { return _fieldSet; }
  50:              set { _fieldSet = value; }
  51:          }
  52:   
  53:   
  54:          public DataTable GetDataTable()
  55:          {
  56:              DataTable dataTable = new DataTable(_lotusView);
  57:              Domino.NotesSession s = new Domino.NotesSession();
  58:   
  59:              s.InitializeUsingNotesUserName(_userName, _password);
  60:              Domino.NotesDatabase db;
  61:              Domino.NotesView vw;
  62:              Domino.NotesDocument doc;
  63:              db = s.GetDatabase(_server, _databaseName, false);
  64:              if (db != null)
  65:              {
  66:                  vw = db.GetView(_lotusView);
  67:                  doc = vw.GetFirstDocument();
  68:                  string[] FieldSetTemp = FieldSet.Split(',');
  69:                  for (int i = 0; i < FieldSetTemp.Length; i++)
  70:                  {
  71:                      DataColumn dc = new DataColumn(FieldSetTemp[i], Type.GetType("System.String"));
  72:                      dataTable.Columns.Add(dc);
  73:                  }
  74:   
  75:                  while (doc != null)
  76:                  {
  77:                      DataRow dr = dataTable.NewRow();
  78:                      for (int i = 0; i < FieldSetTemp.Length; i++)
  79:                      {
  80:                          dr[FieldSetTemp[i]] = doc.GetFirstItem(FieldSetTemp[i]).Text;
  81:                      }
  82:                      dataTable.Rows.Add(dr);
  83:                      doc = vw.GetNextDocument(doc);
  84:                  }
  85:              }
  86:   
  87:              return dataTable;
  88:          }
  89:   
  90:          public DataTable GetDataTable(int index, int count)
  91:          {
  92:              DataTable dataTable = new DataTable(_lotusView);
  93:              Domino.NotesSession s = new Domino.NotesSession();
  94:   
  95:              s.InitializeUsingNotesUserName(_userName, _password);
  96:              Domino.NotesDatabase db;
  97:              Domino.NotesView vw;
  98:              Domino.NotesDocument doc;
  99:              db = s.GetDatabase(_server, _databaseName, false);
 100:              if (db != null)
 101:              {
 102:                  vw = db.GetView(_lotusView);
 103:                  doc = vw.GetFirstDocument();
 104:                  string[] FieldSetTemp = FieldSet.Split(',');
 105:                  for (int i = 0; i < FieldSetTemp.Length; i++)
 106:                  {
 107:                      DataColumn dc = new DataColumn(FieldSetTemp[i], Type.GetType("System.String"));
 108:                      dataTable.Columns.Add(dc);
 109:                  }
 110:   
 111:                  int c = 0;
 112:                  while (doc != null)
 113:                  {
 114:                      if (c < index)
 115:                      {
 116:                          doc = vw.GetNextDocument(doc);
 117:                          continue;
 118:                      }
 119:                      DataRow dr = dataTable.NewRow();
 120:                      for (int i = 0; i < FieldSet.Length; i++)
 121:                      {
 122:                          dr[FieldSetTemp[i]] = doc.GetFirstItem(FieldSetTemp[i]).Text;
 123:                      }
 124:                      dataTable.Rows.Add(dr);
 125:                      doc = vw.GetNextDocument(doc);
 126:                      c++;
 127:                      if (c > count) break;
 128:                  }
 129:              }
 130:   
 131:              return dataTable;
 132:          }
 133:   
 134:      }
 135:  }
 136:   
 137:   
138: usage (the instance is in WebService)
 139:   
140: [webmethod (description = "<br> the method used to obtain the view. a datatable structure is returned. The following describes the parameters: <br> username = user name <br> Password = PASSWORD <br> databasename = Document Database Name <br> Lotus view = view name <br> fieldset = view field (separated by commas) <br> ")]
 141:      public System.Data.DataTable GetLotusTable(string username, string password, string server, string databasename, string lotusview, string fieldset)
 142:      {
 143:          LotusDbLink.LotusDB ldb = new LotusDbLink.LotusDB();
 144:          ldb.UserName = username;
 145:          ldb.Password = password;
 146:          ldb.Server = server;
 147:          ldb.DatabaseName = databasename;
 148:          ldb.LotusView = lotusview;
 149:          ldb.FieldSet = fieldset;
 150:          return ldb.GetDataTable();
 151:      }
 152:   
153: [webmethod (description = "<br> obtain the first n items of a view. a datatable structure is returned. The following describes the parameters: <br> username = user name <br> Password = PASSWORD <br> databasename = Document Database Name <br> Lotus view = view name <br> fieldset = view field (separated by commas) <br> Index = start index <br> COUNT = Top N items <br> ")]
 154:      public System.Data.DataTable GetLotusTableCount(string username, string password, string server, string databasename, string lotusview, string fieldset, int index, int count)
 155:      {
 156:          LotusDbLink.LotusDB ldb = new LotusDbLink.LotusDB();
 157:          ldb.UserName = username;
 158:          ldb.Password = password;
 159:          ldb.Server = server;
 160:          ldb.DatabaseName = databasename;
 161:          ldb.LotusView = lotusview;
 162:          ldb.FieldSet = fieldset;
 163:          return ldb.GetDataTable(index, count);
 164:      }
 165:   
 166:   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.