FindSingleLine does not seem to start at top of document

I need to iterate over a single document several times to progressively find and replace content.

My first iteration looks for certain tags and replaces them. I am using document.FindSingleLine(regEx) and

document.FindNextSingleLine(nextParagraph, regEx).

On my second iteration I need to go back through the whole document again finding and replacing different items. However, the first result of the document.FindSingleLine(regEx) in the second iteration is not the first result in the document but the first result after the latest result of the first iteration.


For example, if my document was:

1
A
2
B
3
C
4
5

And my first iteration replaced all letters with @ I would have:

1
@
2
@
3
@
4
5

But when my second iteration replaces all numbers with # I get:

1
@
2
@
3
@
#
#

When I expect to get:

#
@
#
@
#
@
#
#

It seems like there may be an internal cursor or pointer that is not getting reset to the top of the document when FindSingleLine is executed.

Any ideas on how to resolve this?


14 Replies

CR Chris Reddick January 7, 2022 04:45 PM UTC

I found a solution but it is not very clean if you ask me.


I can use:

var firstParagraph = document.Sections[0].Paragraphs[0]


to get the first paragraph in the document. And then I can use:

document.FindNextSingleLine(firstParagraph, regEx)


at the start of my iteration to ensure that the first find starts at the top of the document.


I would have expected document.FindSingleLine(regEx) to do this automatically.



LB Lokesh Baskar Syncfusion Team January 10, 2022 04:32 PM UTC

Hi Chris, 

Currently, we are checking the reported problem and we will share the further details on 11th January 2022.

Regards, 
Lokesh B  



LB Lokesh Baskar Syncfusion Team January 11, 2022 06:18 PM UTC

Hi Chris, 

From the given details, we have found that your requirement is to find all letters or numbers in word document and replace with another text. To achieve your requirement, we suggest you to use FindAll API in DOCIO to find all text or numbers and replace with another text. We have prepared the sample application to achieve your requirement. Please refer to the sample from the below link.
https://www.syncfusion.com/downloads/support/directtrac/general/ze/DocIOSample783253049.zip

Regards, 
Lokesh B 
 



CR Chris Reddick January 12, 2022 07:31 PM UTC

Thanks Lokesh, but my example of simple letters and numbers was just to help explain. The actual template document has complex tags I need to find that can span multiple paragraphs. That is why I needed to use FindSingleLine. My problem is that FindSingleLine does not always seem to start at the top of the document.


I have updated your example with code similar to what I am using and it demonstrates the problem. I am attaching a new MainPage.aspx.cs file.


It produces this result:

1

@

2

@

3

@

#

#


Attachment: MainPage.aspx.cs_e6504734.zip


CR Chris Reddick January 12, 2022 10:28 PM UTC

To add to the weirdness, I inadvertently found that if I call "document.ReplaceSingleLine(new Regex(@"DUMMY TEXT"), "DUMMY TEXT");" before the Replace Numbers section of the code the problem is resolved. The only thing I can think of is that the  ReplaceSingleLine must do some kind of reset that makes the next FindSingleLine call work as expected.

See updated MainPage.aspx.cs file attached.


Attachment: MainPage2.aspx_ef7dee60.zip


CR Chris Reddick January 12, 2022 10:54 PM UTC

I also found a new issue. I am posting it hear because it is somewhat related and I am using the example code you provided to demonstrate the issue.


This issue involves the ReplaceSingleLine injecting extra line returns.

I updated the template doc to look like this:


I have Word showing paragraph marks so it is clear where the line returns are.

My replace code looks like this:


The code should find "#~" followed by anything and then "~#" and replace it with "X". As you can see I have set my RegEx pattern to include line returns when it finds anything by adding the (?s) to the front of the pattern. The RegEx does indeed find the correct text. The problem is that it does not replace it properly.

I should be getting a result that looks like this:

But what I get is what you see below with the extra paragraph mark between the two Xs. Why is that extra paragraph mark there? How do I fix this problem?



Attachment: MainPage3.aspx_2624c6ac.zip


LB Lokesh Baskar Syncfusion Team January 13, 2022 05:09 PM UTC

Hi Chris, 

Thank you for sharing the details.

Regarding issue in “FindSingleLine does not always seem to start at the top of the document
” and “ReplaceSingleLine injecting extra line returns

We have reproduced the reported problem in our end and we suspect that it to be a defect. We will validate this issue and share the details on 18th January 2022.

Regards, 
Lokesh B 
 



LB Lokesh Baskar Syncfusion Team January 18, 2022 03:46 PM UTC

Hi Chris,  
 
RegardingFindSingleLine does not find text from top of the document” and “Text is not replaced properly after calling the ReplaceSingleLine” 
We have confirmed that the mentioned “FindSingleLine does not find text from top of the document” and “Text is not replaced properly after calling the ReplaceSingleLine” is issues and we have logged a defect report. From the given details, we have found that you are using our weekly NuGet version. We will include the fix for this defect in our weekly NuGet release which is estimated to be available on 1st February 2022.   

The status of this bug report can be tracked through the below link: 
 

Note: If you are using any other Essential Studio version then kindly let us know the currently installed version, so that we can provide patch in that version based on our SLA policy.  
 
 
Regards,  
Lokesh B   



CR Chris Reddick January 25, 2022 09:48 PM UTC

Thanks for the update. Sorry I did not reply right away. Is it possible to add another email address to this thread for notifications? If so, please add andrew.hawes@claritymis.com. Thanks

I don't think I am using your "weekly NuGet version". I don't really know how I would use the weekly version.

As far as I know, I am using version 19.2.0.44.



I would like to test the fix when it comes out. How would I do that?



MR Manikandan Ravichandran Syncfusion Team January 27, 2022 04:28 PM UTC

Hi Chris,

Thank you for your update.

We will check and add the mentioned email id with this account. We will prepare the patch with this fix in your version (19.2.0.44) and update you on 31st January 2022.

Regards,
Manikandan Ravichandran 



LB Lokesh Baskar Syncfusion Team January 31, 2022 03:58 PM UTC

Hi Chris,

We will share the patch for these fix(“FindSingleLine does not find text from top of the document” and “Text is not replaced properly after calling the ReplaceSingleLine”) in your version (19.2.0.44) on 1st February 2022.

Regards,
Lokesh B
 



LB Lokesh Baskar Syncfusion Team February 1, 2022 09:00 AM UTC


Advanced approach – use only if you have specific needs and can directly replace existing assemblies for your build environment
Please find the patch assemblies alone from below location:
https://syncfusion.com/Installs/support/patch/19.2.0.44/837870/F171754/SyncfusionPatch_19.2.0.44_837870_2012022122249919_F171754.zip  
Installation Directions:
This patch should replace the files such as “Syncfusion.DocIO.Base.dll” under the following folder.
$system drive: \ Files\Syncfusion\Essential Studio\$Version # \precompiledassemblies\$Version#\4.0
Eg : $system drive:\Program Files\Syncfusion\Essential Studio\ 19.2.0.44 \precompiledassemblies\ 19.2.0.44 \4.0

To automatically run the Assembly Manager, please check the Run assembly manager checkbox option while installing the patch. If this option is unchecked, the patch will replace the assemblies in precompiled assemblies’ folder only. Then, you will have to manually copy and paste them to the preferred location or you will have to run the Syncfusion Assembly Manager application (available from the Syncfusion Dashboard, installed as a shortcut in the Application menu) to re-install assemblies.

Note:
To change how you receive bug fixes, ask your license management portal admin to change your project’s patch delivery mode.
https://www.syncfusion.com/account/license

If you have received other patches for the same version for other products, please apply all patches in the order received.

This fix will be included in our 2022 Volume 1 release which will be available at mid of March, 2022 tentatively.

The status of this bug task can be tracked through the below feedback link:
https://www.syncfusion.com/feedback/31956/findsingleline-does-not-find-text-from-top-of-the-document  
 



CR Chris Reddick February 1, 2022 09:47 PM UTC

Thank you. I will review and get back with you.



CR Chris Reddick February 1, 2022 10:58 PM UTC

Both issues seem to be addressed. At least they are in the sample project. I will also be testing in the real project to make sure. I will update you all in the next few days.



Loader.
Up arrow icon