Helper methods that deal with reading and writing word files using OpenXML.
$ dotnet add package CommonNetFuncs.Word.OpenXmlThis lightweight project contains helper methods related to MS Word formatted documents (.doc & .docx).
Helpers that search for and change URLs in .doc and .docx files.
Look for specific URLs in a word document and change them to a different URL.
FileStream stream = new(@"C:\Documents\UrlTest.docx");
bool success = ChangeUrls.ChangeUrlsInWordDoc(stream, "http://google.com", "http://yahoo.com", true); // Replaces all "yahoo.com" URLs in the document with "google.com"
// Alternatively, use a dictionary for replacements
Dictionary<string, string> urlsToUpdate = new()
{
{ "http://google.com", "http://yahoo.com" },
{ "http://facebook.com", "http://meta.com" },
{ "http://tumblr.com", "http://imgr.com" }
};
bool success = ChangeUrls.ChangeUrlsInWordDoc(stream, urlsToUpdate); // Replaces all key URLs in the dictionary with their associated value
Look for URLs that match a regex pattern in a word document and replace the matched string with a new one.
FileStream stream = new(@"C:\Documents\UrlTest.docx");
bool success = ChangeUrls.ChangeUrlsInWordDoc(stream, @"^(http:\/\/)", "https://", true); // Replaces "http://" with "https://" in all URLs in the document
// Alternatively, use a dictionary for replacements
Dictionary<string, string> urlsToUpdate = new()
{
{ @"^(http:\/\/)", "https://" },
{ @"(yahoo\.com)", "google.com" }
};
bool success = ChangeUrls.ChangeUrlsInWordDoc(stream, urlsToUpdate); // Replaces all regex matches with the keys in the dictionary with their associated values
Install via NuGet:
dotnet add package CommonNetFuncs.Word.OpenXml
This project is licensed under the MIT License - see the LICENSE file for details.