Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find words in document SP URL

I have a sample code, it works well if the document is locally, but if I point the way to the link, then immediately the error, how to win?

using DocumentFormat.OpenXml.Packaging;
using OpenXmlPowerTools;

using (WordprocessingDocument doc = WordprocessingDocument.Open(@"http://sp-test/sites/test/Documents/Base.docx", true))
TextReplacer.SearchAndReplace(wordDoc: doc, search: "Tags", replace: "Test", matchCase: false);

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in DocumentFormat.OpenXml.dll

Additional information: Could not find document

like image 513
Mikhail Zhuikov Avatar asked Jan 22 '26 08:01

Mikhail Zhuikov


1 Answers

WordprocessingDocument.Open looks for the fileHandle or Stream but you are providing URL which doesn't make sense.

you first need to use HttpClient to download file as Stream then process it with WordprocessingDocument.Open(stream) accordingly

like image 113
Derviş Kayımbaşıoğlu Avatar answered Jan 23 '26 21:01

Derviş Kayımbaşıoğlu