We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Words: UpdateFields for some fields- but keep some other fields untouched for next run

Hi,

My problem is, I generate a word document from a dot file, and replace several dynamic fields(DOCPROPERY). Then I save the document. The reult is that all dynaic field fields are chanhed and not dynamic anymore.

Some days after the generation I need to put a signature, date of the letter on the document, wherefor I also use dynamic fields (for the original dot file)

How can I update fields, but keep some fields untouched (the fields with DOCPROPERTY DatumDocument, TekenenFuleName and Tekenen (is a link to a bitmap) needed to be untouched)

Most of the fields are in the same textfield of the Range.

My code is:

Aspose.Words.Document doc = new Aspose.Words.Document(template);

foreach (DocumentProperty prop in doc.CustomDocumentProperties)
{
string wordPropertyName = prop.Name;
string fileNetPropertyName;
WordPropertyMapping mapping = FindMapping(mappings, wordPropertyName);

if (mapping.FileNetPropertyName != null)
{
fileNetPropertyName = mapping.FileNetPropertyName;
}
else
{
fileNetPropertyName = wordPropertyName;
}

if (props.ContainsKey(fileNetPropertyName) && (props[fileNetPropertyName] != null))
{
if (doc.CustomDocumentProperties.Contains(fileNetPropertyName))
doc.CustomDocumentProperties[fileNetPropertyName].Value = props[fileNetPropertyName].ToString();
//else
// doc.CustomDocumentProperties.Add(fileNetPropertyName, props[fileNetPropertyName].ToString());

//Word.DocumentPropertyHelper.SetPropertyValue(doc.CustomDocumentProperties, wordPropertyName, props[fileNetPropertyName].ToString());
}
else if (mapping.Default != null)
{
if (doc.CustomDocumentProperties.Contains(fileNetPropertyName))
doc.CustomDocumentProperties[fileNetPropertyName].Value = mapping.Default.ToString();
//else
// doc.CustomDocumentProperties.Add(fileNetPropertyName, mapping.Default.ToString());

//Word.DocumentPropertyHelper.SetPropertyValue(doc.CustomDocumentProperties, wordPropertyName, mapping.Default.ToString());
}
if (!fileNetPropertyName.Contains(ConfigurationManager.AppSettings["SignatureDocumentProperty"]))
doc.Range.UpdateFields();
//if (unlink )
}
//doc.UpdateFields();

Thanks

Ernst


Hi Ernst,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. As I can see in your code, you reset value of document property to some default value if there is no value for this property in the map. I think, you should just leave such properties untouched. In this case, you will not lost values of already updated properties.

Best regards.

I don’t update the property ‘Tekenen’ (SignatureDocumentProperty) by not executing doc.Range.UpdateFields, but this property has changed!
What mistake do I make?

if (!fileNetPropertyName.Contains(ConfigurationManager.AppSettings[“SignatureDocumentProperty”]))
doc.Range.UpdateFields();

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Range.UpdateFields method updates all fields in a document. So if you call this method somewhere before saving document, fields will be updated. Also, fields in a document can be updated when you open this document in MS Word.

However, I cannot understand what the problem is. I suppose document properties should contain actual values, so if you update fields in a document, fields will show actual information. IF you do not need to update value of some of document properties, you should just keep its old value, i.e. do not change Document.CustomDocumentProperties[“propname”] value.

Best regards.

Thank you for your answer.

When I generate the document, I want some fields to be updated, but I need some fields that are not updated , because I need them for a second action to be changed.

After the generation of the document the UpdateField update al the fields. Is it possible not all the fields are changed, and some fields stay dynamic fields. For the second action some fields have to be updated for the first time. At the moment these fields aren't dynamic anymore, so can not been changed in this action.

Example:

At generation I need to change all the fields except Tekenen, TekeneFullName and DatumDocument. It will be a document which is almost ready to send to a customer, but we need to controle some things. The last step of the workflow will sign and date this document.

This last step will automatic sign the document, therefor I need these fields to be dynamic fields, so at this moment I can update these fields with the values of the moment. But after the generation of the document (first step) all fields are 'text' and not defined as 'DOCPROPERTY fields (update fields)' anymore.

Can I put fields in a different range? How do I do that?

When the fields are in a different range, I can UpdateFields for the first range, and for the seconds action the other range. Maybe that is a possible solution?

How do I achieve to keep fields as DOCPROPERTY-fields in a word document, after UpdateFields!

Thanks,

Ernst

Hi Ernst,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. Actually, UpdateFields method does not remove fields, this method just updates values of fields. I suppose in you code you use your own method to unlink fields in your document, i.e. convert field to simple text. That is why your problem occurs.

If you really need to unlink fields in your document, I think, you should do that only when all fields are filled with data.

Best regards.

Thanks.

I solved the problem. My new document was protected, so I couldn't exit the fields. I didn't get a message the document was protected.

I have one issue left.

On the forum I concluded that INCLUDEPICTURE fields are not displayed after update. You should update it in Word.

My solotion to get an updated document with the signature is:

NodeCollection shapes = null;
DocumentBuilder builder = new DocumentBuilder(doc);
ArrayList shapesToRemove = new ArrayList();

shapes = doc.GetChildNodes(NodeType.Shape, true);
foreach (Shape shape in shapes)
{
if (shape.ImageData != null || shape.HasImage)
{
if (shape.ImageData.IsLink)
{
string naam = shape.Name;
builder.MoveTo(shape);
builder.InsertImage(signatureFileName);
builder.InsertNode(shape);
shapesToRemove.Add(shape);
break;
}
}
}
//verwijderen linked images
foreach (Shape shape in shapesToRemove)
{
shape.Remove();
}

When i execute this, my document doesn't show the signature. When I update the field in Word, the signature is displayed. How can I show the signature, without update de documnet in Word.

Thanks

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. It seems the problem occurs because image is inside IF field. I managed to reproduce this problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.

Best regards.

The issues you have found earlier (filed as 10961) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.