For my company I am currently creating a page which enables users to fill in a form which in turn creates a content node in the umbraco CMS. I am currently using Umbraco v6.1.5.
The problem I have is with one of the values that needs to be inserted into the cms. I gather a number of ISBN numbers(as string values) from the form and try to insert these into the contentnode like so:
ContentService contentService = new ContentService();
var product = contentService.CreateContentWithIdentity(
"Name", // the name of the product
parentNode, // the parent id should be the id of the group node
"Product", // the alias of the product Document Type
0
);
string IsbnNumbers = string.Empty;
foreach (string book in Books)
{
IsbnNumbers += "<value>" + book.ISBNNumber + "</value>";
}
product.SetValue("books", string.Format("<values>{0}</values>", IsbnNumbers));
I generate one giant string and try to insert this into the multiple textstring field(with the alias of "books"), but when I go to the CMS and check what has been inserted I see one string with "<values><value>9065231390</value><value>8888888888</value></values>" in it instead of two rows with each a number in it.
I have already tried to insert the values comma seperated and hardcoded with the xml i find in the umbraco.config but with no result. I have googled for it and the closest i came to someone with the same problem was someone who "suddenly" got the xml in one field.
Does anyone have some pointers as to how i would be capable of saving multiple strings in a "Multiple text string" field? Am I supposed to create an object in which to put these strings maybe? Or am i missing something completely?
It seems my problem is solved by joining all the strings together with a newline, instead of by joining the values through "<value></value>".
A collegue found a post ( I am afraid he did not save the url so i cannot refer to it) in which the same problem was described as the one I had. In that post it was mentioned that the data is saved in the database seperated by a newline.
The code, should someone be interested in how i solved it:
Howto: Save Multiple textstring programmatically
Greetings,
For my company I am currently creating a page which enables users to fill in a form which in turn creates a content node in the umbraco CMS. I am currently using Umbraco v6.1.5.
The problem I have is with one of the values that needs to be inserted into the cms. I gather a number of ISBN numbers(as string values) from the form and try to insert these into the contentnode like so:
I generate one giant string and try to insert this into the multiple textstring field(with the alias of "books"), but when I go to the CMS and check what has been inserted I see one string with "<values><value>9065231390</value><value>8888888888</value></values>" in it instead of two rows with each a number in it.
I have already tried to insert the values comma seperated and hardcoded with the xml i find in the umbraco.config but with no result. I have googled for it and the closest i came to someone with the same problem was someone who "suddenly" got the xml in one field.
Does anyone have some pointers as to how i would be capable of saving multiple strings in a "Multiple text string" field? Am I supposed to create an object in which to put these strings maybe? Or am i missing something completely?
Let me know if you need more information!
Kind regards,
Jeroen
It seems my problem is solved by joining all the strings together with a newline, instead of by joining the values through "<value></value>".
A collegue found a post ( I am afraid he did not save the url so i cannot refer to it) in which the same problem was described as the one I had. In that post it was mentioned that the data is saved in the database seperated by a newline.
The code, should someone be interested in how i solved it:
IsbnNumbers = String.Join(Environment.NewLine, sp.Books.Select(x => x.ISBNNumber));
product.SetValue("books", IsbnNumbers);
Where sp.Books is a simple object containing the ISBN number as a string.
I hope this helps someone!
is working on a reply...