public void ChangeFieldUpdateCultureSource()
{
// We will test this functionality creating a document with two fields with date formatting
// field where the set language is different than the current culture, e.g German.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert content with German locale.
builder.Font.LocaleId = 1031;
builder.InsertField("MERGEFIELD Date1 \\@ \"dddd, d MMMM yyyy\"");
builder.Write(" - ");
builder.InsertField("MERGEFIELD Date2 \\@ \"dddd, d MMMM yyyy\"");
// Make sure that English culture is set then execute mail merge using current culture for
// date formatting.
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
doc.MailMerge.Execute(new string[] { "Date1" }, new object[] { new DateTime(2011, 1, 01) });
//ExStart
//ExFor:Document.FieldOptions
//ExFor:FieldOptions
//ExFor:FieldOptions.FieldUpdateCultureSource
//ExFor:FieldUpdateCultureSource
//ExId:ChangeFieldUpdateCultureSource
//ExSummary:Shows how to specify where the culture used for date formatting during field update and mail merge is chosen from.
// Set the culture used during field update to the culture used by the field.
doc.FieldOptions.FieldUpdateCultureSource = FieldUpdateCultureSource.FieldCode;
doc.MailMerge.Execute(new string[] { "Date2" }, new object[] { new DateTime(2011, 1, 01) });
//ExEnd
// Verify the field update behaviour is correct.
Assert.AreEqual("Saturday, 1 January 2011 - Samstag, 1 Januar 2011", doc.Range.Text.Trim());
// Restore the original culture.
Thread.CurrentThread.CurrentCulture = currentCulture;
}