tags:

views:

48

answers:

1

Using C#, is there a good way to find and replace a text string in a docx file without having word installed on that machine?

+2  A: 

Yes, using Open XML. Here's an article which addresses your specific question: Creating a Simple Search and Replace Utility for Word 2007 Open XML Format Documents

Otaku
Thanks that definitely got me started. It looks like it is all based on System.IO.Packaging. Since this is fairly simple, can it be done without the Open XML Format SDK?
TimothyAWiseman
Absolutely - I rarely use the SDK myself. I primarily program against PowerPoint (`PresentationML` and `DrawingML` as opposed to Word's `WordProcessingML`) using only `System.IO.Packaging` and Linq-to-XML. So I'll have to point you to a Ken Getz article: http://msdn.microsoft.com/en-us/library/bb738371(office.12).aspx. Look for any more of his articles written in 2006 - they all use `System.IO.Packaging`. After that, he started writing articles with the SDK. You can also check out http://www.openxmldeveloper.org
Otaku
Awesome, thank you. Also, this reference by Vikas Goyal helped me tremendously both in getting the answer I needed and in (mostly) understanding what was going on in the process: http://www.devx.com/dotnet/Article/42221/1954
TimothyAWiseman
@timothyawiseman: the devx article is a really good one. glad to hear this is working out for you.
Otaku