Метод NotesSession.GetDataBase возвращает нулевое значение - PullRequest
2 голосов
/ 11 августа 2010

У меня есть класс c #, который был написан, чтобы читать электронные письма лотоса для любых вложений и сохранять их на локальном диске. Он работал нормально, когда я передавал "" в качестве первого параметра методу GetDataBase и полный путь к файлу .nsf моей локальной системы в качестве второго аргумента. Но если я удаляю "" и указываю полное имя локальной системы в качестве первого аргумента, он возвращает нулевое значение.

Это проблема с какими-либо разрешениями? Если это так, он не должен работать, даже если я передал "" в качестве первого параметра. В противном случае, я должен иметь какие-либо другие разрешения на уровне системы / сервера? Пожалуйста, помогите мне в этом вопросе.

1 Ответ

2 голосов
/ 12 августа 2010

Наконец, я мог бы сделать это следующим образом.И я подумал о том, чтобы отправить его кому-нибудь, чтобы не страдать снова.

Следующий код - прочитать вложение из писем лотоса и сохранить его в физическом месте.

string lotusServerName =ConfigurationSettings.AppSettings [ "Lotus_Server"] ToString ().;string lotusDBFilePath = ConfigurationSettings.AppSettings ["Lotus_DB_File_Path"]. ToString ();строка password = ConfigurationSettings.AppSettings ["Пароль"]. ToString ();string sourceFolder = ConfigurationSettings.AppSettings ["Source_Folder"]. ToString ();string targetFolder = ConfigurationSettings.AppSettings ["Target_Folder"]. ToString ();string documentsFolder = ConfigurationSettings.AppSettings ["Documents_Folder"]. ToString ();

        //Creating the notes session and passing password
        NotesSession session = new NotesSession();
        session.Initialize(password);

        //Getting the DB instance by passing the servername and path of the mail file.  
        //third param "false" will try to check the DB availability by opening the connection
        //if it cannot open, then it returns null.
        NotesDatabase NotesDb = session.GetDatabase(lotusServerName, lotusDBFilePath, false);

        //Get the view of the source folder
        NotesView inbox = NotesDb.GetView(sourceFolder);

        //looping through each email/document and looking for the attachments
        //if any attachments found, saving them to the given specified location
        //moving the read mails to the target folder
        NotesDocument docInbox = null;
        int docCnt = inbox.EntryCount;
        for (int currDoc = 0; currDoc < docCnt; currDoc++) {
            docInbox = inbox.GetFirstDocument();
            object[] items = (object[])docInbox.Items;
            foreach (NotesItem nItem in items) {
                if (nItem.Name == "$FILE") {
                    NotesItem file = docInbox.GetFirstItem("$File");
                    string fileName = ((object[])nItem.Values)[0].ToString();
                    NotesEmbeddedObject attachfile = (NotesEmbeddedObject)docInbox.GetAttachment(fileName);

                    if (attachfile != null) {
                        attachfile.ExtractFile(documentsFolder + fileName);
                    }
                }
            }
            docInbox.PutInFolder(targetFolder, true);//"true" creates the folder if it doesn't exists
            docInbox.RemoveFromFolder(sourceFolder);
        }

        //releasing resources
        if (session != null)
            session = null;
        if (NotesDb != null)
            NotesDb = null;
        if (inbox != null)
            inbox = null;
        if (docInbox != null)
            docInbox = null;

Ниже приведены значения, считанные из файла .config.

Приведенный выше код будетработать правильно, если у вас уже есть почтовый клиент lotus в вашей системе, и вы можете получить доступ к почте с вашего почтового сервера.Вам не нужны никакие другие предпочтения.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...