Find and Replace Text in Visio Files in C#

Find Replace Visio csharp

Visio files are used to create diagrams like organizational charts, flow charts, etc. Such diagrams comprise different shapes which can also contain text information. In some use cases, you may need to update the text in any shape of a Visio diagram. In accordance with such requirements, this article covers how to find and replace text in Visio drawings programmatically in C#.

Search and Replace Text in Visio Diagram – C# API Installation

Aspose.Diagram for .NET API supports creating, editing, and manipulating Visio files. You can easily configure the API by downloading the DLL file from the New Releases section. Alternatively, you can install the API from the NuGet gallery with the below installation command in Microsoft Visual Studio:

PM> Install-Package Aspose.Diagram

Find and Replace Text in Visio Diagram Programmatically in C#

Visio files can contain multiple shapes in a diagram. You can find and replace text by following the steps below:

  1. Prepare a collection of old and new text strings.
  2. Load the input diagram and iterate through each shape.
  3. Save the output Visio diagram.

The following code snippet demonstrates how to find and replace text in VSD or VSDX format Visio file programmatically using C#:

Conclusion

In conclusion, you have learned how to find and replace text in Visio diagrams. Moreover, you can update the sample code to the other overloads for replacing the text. For example, replacing only the first occurrence or all of the occurrences of matching text based on your requirements. You may learn several other features of the API by visiting the documentation. Furthermore, in case of any queries please feel free to write to us at the forum.

See Also

Insert or Remove Header and Footer in VSD VSDX Files in C#