- Code: Select all
...
foreach (Paragraph paragraph in section.Body.Paragraphs)
{
ProcessParagraph(report, paragraph);
}
...
private void ProcessParagraph(DocReport report, Paragraph paragraph)
{
foreach (DocumentObject child in paragraph.Items)
{
Type t = child.GetType();
switch (child.DocumentObjectType)
{
case DocumentObjectType.StructureDocumentTagInline: //checkbox
StructureDocumentTagInline tag = child as StructureDocumentTagInline;
if (tag.SDTProperties.SDTType == SdtType.CheckBox && tag.SDTProperties.Tag != null)
{
SdtCheckBox scb = tag.SDTProperties.ControlProperties as SdtCheckBox;
var result1 = PopulateText(report, tag.SDTProperties.Tag);
bool boolResult1 = false;
bool.TryParse(result1, out boolResult1);
scb.Checked = boolResult1;
}
break;
case DocumentObjectType.CheckBox:
CheckBoxFormField checkBox = child as CheckBoxFormField;
var newCheckboxName = LongToShortName(checkBox.Name);
var result = PopulateText(report, newCheckboxName);
bool boolResult = false;
bool.TryParse(result, out boolResult);
checkBox.Checked = boolResult;
break;
case DocumentObjectType.TextFormField:
TextFormField formField = child as TextFormField;
if (formField.FieldText.Trim().Length > 0)
{
formField.Text = PopulateText(report, formField.FieldText);
}
else if (formField.Name.Trim().Length > 0)
{
var newTextFieldName = LongToShortName(formField.Name);
formField.Text = PopulateText(report, newTextFieldName);
}
//formField.FieldText = formField.Text;
break;
case DocumentObjectType.TextBox:
Debug.WriteLine("TextBox");
break;
default:
Debug.WriteLine("Unknow--" + child.DocumentObjectType.ToString());
break;
}
}
paragraph.Text = PopulateText(report, paragraph.Text);
}
here's the exception:
Collection was modified; enumeration operation may not execute.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
Source Error:
Line 131: private void ProcessParagraph(DocReport report, Paragraph paragraph)
Line 132: {
Line 133: foreach (DocumentObject child in paragraph.Items)
Line 134: {
Line 135: Type t = child.GetType();
Source File: C:\setworks\SW\SetWorks.Reporting\MergeReport\Doc\Services\DocReportingService.cs Line: 133
Stack Trace:
[InvalidOperationException: Collection was modified; enumeration operation may not execute.]
System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) +54
System.Collections.Generic.Enumerator.MoveNextRare() +30
System.Collections.Generic.Enumerator.MoveNext() +65
SetWorks.Reporting.MergeReport.Doc.Services.DocReportingService.ProcessParagraph(DocReport report, Paragraph paragraph) in C:\setworks\SW\SetWorks.Reporting\MergeReport\Doc\Services\DocReportingService.cs:133
SetWorks.Reporting.MergeReport.Doc.Services.DocReportingService.GenerateReport(DocReportConfiguration config) in C:\setworks\SW\SetWorks.Reporting\MergeReport\Doc\Services\DocReportingService.cs:81
SETWorks.Home.Reports.MergeReporting.MergeReport.DoDocReport(DocReportConfiguration config, DocumentViewerControl dvFileViewer) in C:\setworks\SW\SETWorks\Home\Reports\MergeReporting\MergeReport.aspx.cs:185
SETWorks.Home.Reports.MergeReporting.MergeReport.ProcessReport(Object sender, EventArgs eventArgs) in C:\setworks\SW\SETWorks\Home\Reports\MergeReporting\MergeReport.aspx.cs:163
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +109
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +31
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3480
If I traverse section.Body.FormFields to find the TextFormField, I can successfully set the text but it does not appear in the document. Here's the code that I've done that:
- Code: Select all
//foreach(FormField f in section.Body.FormFields)
//{
// if (f.DocumentObjectType == DocumentObjectType.TextFormField)
// {
// if (f.FieldText.Trim().Length > 0)
// {
// var result = PopulateText(report, f.FieldText);
// f.Text = result;
// }
// else if (f.Name.Trim().Length > 0)
// {
// var newTextFieldName = LongToShortName(f.Name);
// var result = PopulateText(report, newTextFieldName);
// f.Text = result;
// //f.Name = result;
// }
// }
//}
Please point me to the right direction. How can I set the text and make it appears in the Word Document.
Thank you very much.
Thao