Can't get newlines in Notes document created in C#

Go To StackoverFlow.com

0

I have C# code that I am using to write entries in a Notes database. Below is a simple example of the kind of thing I am doing.

var text = "Line 1\r\nLine 2\r\nLine 3";
doc.ReplaceItemValue("Body", text);
doc.Save(false, false);

I would expect that when I view the document in Notes, I would see the body formatted as follows:

Line 1
Line 2
Line 3

However, Notes seems to eat up the newline characters, and what I actually see is this:

Line 1Line 2Line 3

I have tried using Environment.Newline and \n as well, but that doesn't make any difference in the formatting I observe in Notes.

I don't do a lot of Notes programming, so I'm a little confused as to why this is not working for me, since every example I have come across is similar to my code.

2012-04-03 20:39
by EricRRichards
do you mean Louts/IBM Notes? are you viewing the created document on the same machine as you are creating it - Stuart 2012-04-03 20:46
Did you try CHAR(10) : var text = "Line 1" + CHAR(10) + "Line 2" + CHAR(10) + "Line 3" - Anurag Ranjhan 2012-04-03 21:26
Is this a richtext field, or a normal text field? If it's a textfield, also check if it's single-value, or multi-value field. multi-value fields work a bit different - Jeroen Jacobs 2012-04-04 11:03
What version of the server are you using? Before 8.5 there was a bug that caused problems with newlines in text items that looked exactly like this - Kerr 2012-04-05 19:12


2

If you want to add new lines in the body of a document, you can use the NotesRichTextItem methods as follows:

//(note this is pseudo-code as I'm typing this from memory)
var richTextItem = new NotesRichTextItem(doc, "Body")
richTextItem.AppendText("Line 1");
richTextItem.AddNewLine(1);

doc.Save(false,false);
2012-04-03 21:18
by Ken Pespisa
Just want to add that Ken's answer is assuming that the Body field of your document is a rich text field. That's the usual convention, but not necessarily true - Richard Schwartz 2012-04-04 00:15
This is the only thing that has worked for me thus far. I am a little concerned that this may break other applications, if they are using the database and expect a Text field rather than RichText. I just find it odd, as this was almost a direct port of some Java code, (which is presumably using the same COM interface to the Notes API) which worked with no problems - EricRRichards 2012-04-04 13:32
@EricRRichards, not sure what your concern is exactly, but my code assumes the Body item is a RichText item. It won't work if the field type is not RichText. But if another app treats the Body field as a plain text field, that should be fine too. The NotesRichTextItem class inherits from NotesItem - Ken Pespisa 2012-04-05 13:39
@KenPespisa In that case, I should be fine. I was just concerned because we are dealing with a third-party database, and I was worried that changing the field type might introduce some rich-text markup that might cause problems with the external compliance tool our customer uses to read the databas - EricRRichards 2012-04-05 15:23
@EricRRichards, You're not changing the field type in this case. You're just accessing the item as a NotesRichTextItem object. On the form the field itself is set as a richtext type, and in the document properties you should see it as a richtext type. However, if you use the GetFirstItem or ReplaceItemValue methods, they operate as if you're working on a basic NotesItem - Ken Pespisa 2012-04-05 17:03


0

If it is a simple text field, define it as a multivaluefield in the notes form and then you could do something like

dim item as notesitem
set item = doc.replaceitemvalue("Body","Line 1")
call item.appendToTextlist("Line 2")
call item.appendToTextList("Line 3")
2012-04-04 13:27
by umeli


0

This looks a lot like the newline issue that the java API had before 8.5. You should be able to add newlines into any text item, not just RichText and not using hacks like messing about with lists.

Prior to the fix in 8.5 one workaround was to use the session.evaluate to manipulate the text in formula language.

2012-04-05 19:16
by Kerr