我正在尝试访问Lotus Domino数据库。可以用C#完成吗?那里有一些我可以看的例子吗?
答案 0 :(得分:2)
有很多例子,只是尝试搜索它。这个例子可以帮助你开始:
//This DLL you've got to add under Project-> Add Reference --> COM Tab --> Lotus Domino Objects
//Standard Path for this DLL is: "C:\Program Files\Notes\domobj.tlb"
using Domino; //domobj.tlb*
...
try
{
//-------------------------------------------
//!!Important!!
//Before you start, you have to check 2 things
//1.) Lotus Notes has to run when you start this application
//2.)The files "notes.ini" and "user.id"
// has to be in the main Lotus Notes folder
//--------------------------------------------
//First, create a new Lotus Notes Session Object
Domino.NotesSession LNSession = new Domino.NotesSession();
//Next add a Database and a Document Object (not new)
Domino.NotesDatabase LNDatabase;
Domino.NotesDocument LNDocument;
//Initialize your Session with your Password
LNSession.Initialize("password");
//Connect to your Notes Server and the path of your
//.nsf File (in my case its in a subfolder 'mail').
LNDatabase = LNSession.GetDatabase("Notes-Server", "mail\\user.nsf", false);
//Create an in memory document in the server database
LNDocument = LNDatabase.CreateDocument();
//-------Assign Field Values-------
//Define Start&End Date+Time of your appointment
//Year, Month, Day, Hour, Minute and Second
System.DateTime StartDate = new DateTime(2008, 3, 19, 8, 2, 0);
System.DateTime EndDate = new DateTime(2008, 3, 19, 8, 5, 0);
//This Defines that it is an Calendar Entry
LNDocument.ReplaceItemValue("Form", "Appointment");
//Type of the appointment, means:
LNDocument.ReplaceItemValue("AppointmentType", "0");
//0 = Date, Appointment
//1 = Anniversary
//2 = All Day Event (Do Not Set Time Here!)
//3 = Meeting
//4 = Reminder
//5 = Date (Special, experimental!)
// Title of your entry
LNDocument.ReplaceItemValue("Subject", "hello world");
// Set Confidential Level (Public=1 or Private=0)
LNDocument.ReplaceItemValue("$PublicAccess","1");
//Add Start&End Time of your event
LNDocument.ReplaceItemValue("CALENDARDATETIME", StartDate);
LNDocument.ReplaceItemValue("StartDateTime", StartDate);
LNDocument.ReplaceItemValue("EndDateTime", EndDate);
LNDocument.ReplaceItemValue("StartDate", StartDate);
LNDocument.ReplaceItemValue("MeetingType", "1");
//Infos in The Body
LNDocument.ReplaceItemValue("Body", "Body Text Body Text ...");
//Add an alarm to your appointment
LNDocument.ReplaceItemValue("$Alarm", 1);
LNDocument.ReplaceItemValue("$AlarmDescription", "hello world (alarm)");
LNDocument.ReplaceItemValue("$AlarmMemoOptions", "" );
//5 = Time (in minutes) before alarm goes on
LNDocument.ReplaceItemValue("$AlarmOffset", 5);
LNDocument.ReplaceItemValue("$AlarmSound", "tada");
LNDocument.ReplaceItemValue("$AlarmUnit", "M");
//This saves your Document in the Notes Calendar
LNDocument.ComputeWithForm(true, false);
LNDocument.Save(true, false, false);
//On success, you'll see an info message;
MessageBox.Show("Calendar Entry Successfully Added!", "Info",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception e1)
{
//On error you'll see an error message
MessageBox.Show(e1.Message);
}
...
答案 1 :(得分:0)
首先,我对您公司强加给您的邮件服务器的选择表示哀悼。
问题是那里确实没有好的例子。只有一小部分用户仍然使用这种死技术。
这是我发现的:
因为这听起来很糟糕..在十六进制编辑器中打开nsf文件 - 有一些"好"用VB(或Lotus Script)编写的例子。 O_O
但据我所知(至少对我自己而言),日历信息不存储在本地nsf文件中。我们面临的问题是:
回答1 :我认为一个空白字符串以某种方式从抓取正确的服务器上帝知道在哪里。
另一种可能性是试试这个..在Lotus Notes上有一个向下箭头,它可以扩展到允许你导航到Mail,Calendar,以及你可能从未使用过的一堆其他垃圾。右键单击日历,然后转到应用程序>属性。它将列出服务器和文件名。从服务器名称中删除尾随/ Garbage / Crap。这将为下面的函数提供服务器名称。同时从文件名中删除前缀\ mail \目录,该文件名将为下面的函数提供数据库。
回答2 :我发现没有比使用Hex编辑器或在互联网上搜索代码段更好的答案了。我怀疑这个字符串不是由IBM设置的,而是在安装期间设置的。因此,如果我们能找到*可能有效的默认值。我再次想要一个更好的答案。对我来说有用的是$ All for E-Mail(对不起,在莲花笔记中没有"电子邮件" Lotus发送"备忘录")和日历用于日历。
回答3 :Lotus Notes API似乎使用上次登录的用户来验证下次登录用户。去看看这可能是为什么Lotus如此安全顺便说一下。
以下函数需要对Domino dll的引用。您可能需要引用它,如果您在64位系统上它仍然无法工作。在32位模式下编译。别忘了Lotus Notes是一个企业级应用程序"远远超过Outlook可以做的事情。这将返回一系列键/值对。是的,你没有看错。它是所有关键值对。很多64位编码的垃圾,颜色代码,guid,看似随机的" 1"和其他无用的垃圾,幸运的是你想要的数据是明文。
using System;
using System.Linq;
using System.Data;
using System.Collections;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using Domino;
using System.Text;
using System.IO;
using System.Collections.Generic;
namespace NotesScraper
{
public class NotesCommunication
{
public KeyValuePair<string, NotesViewResultSet[]>[] PullNotesView(string[] ViewNames, string server, string database, string password )
{
if (ViewNames == null || ViewNames.Length == 0 || ViewNames.ToList().Distinct().Count() != ViewNames.Length )
{
throw new ArgumentException();
}
else
{
List<KeyValuePair<string, NotesViewResultSet[]>> results = new List<KeyValuePair<string, NotesViewResultSet[]>>();
NotesSession notesSession = new Domino.NotesSession();
notesSession.Initialize(password);
NotesDatabase notesDatabase = notesSession.GetDatabase(server, database, false);
for(int i=0; i<ViewNames.Length; i++)
{
List<NotesViewResultSet> result = new List<NotesViewResultSet>();
Domino.NotesView notesView;
string view = ViewNames[i];
notesView = notesDatabase.GetView(view);
NotesViewEntryCollection notesViewCollection = notesView.AllEntries;
for (int rowCount = 1; rowCount <= notesViewCollection.Count; rowCount++)
{
NotesViewEntry viewEntry = notesViewCollection.GetNthEntry(rowCount);
NotesDocument document = viewEntry.Document;
Array notesThings = document.Items as Array;
for (int j = 0; j < notesThings.Length; j++)
{
NotesItem notesItem = (notesThings.GetValue(j) as Domino.NotesItem);
result.Add(new NotesViewResultSet()
{
RecordID = rowCount,
Name = notesItem.Name,
Value = notesItem.Text
});
}
}
results.Add(new KeyValuePair<string,NotesViewResultSet[]>(view, result.ToArray()));
}
return results.ToArray();
}
}
}
public class NotesViewResultSet
{
public int RecordID {get;set;}
public string Name { get; set; }
public string Value { get; set; }
}
}