C# programatically protect word document readonly at paragraph or range level -


my tool process more 1000 docs. had set readonly @ document level, leads severe performance issue.
_appobject = new microsoft.office.interop.word.application(); microsoft.office.interop.word.document _docobj; string file = @”c:\users\public\public documents\word12.docx”;
_docobj = _appobject.documents.open(ref file, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing); //protect
appobject.activedocument.protect(microsoft.office.interop.word.wdprotectiontype .wdallowonly reading, ref noreset, ref password, ref useirm, ref enforcestylelock);

but want make paragraph or range readonly

foreach (microsoft.office.interop.word.paragraph apar in                      _appobject.activedocument.paragraphs) { microsoft.office.interop.word.range parrng = apar.range; string stext = parrng.text; // want make readonly  here } 

then doc saved.

 _docobj.saveas(filename: targetdir, fileformat: wdsaveformat.wdformatdocumentdefault);             object savechanges = wdsaveoptions.wdsavechanges;             object originalformat = wdoriginalformat.wdoriginaldocumentformat;             object routedocument = true;             islockstatus = true;  var doc_close = (microsoft.office.interop.word._document)_docobj;  doc_close.close(ref savechanges, ref originalformat, ref routedocument); 

hence requirement make portion of word document (especially heading or paragraph or alteast range)

if have range object, can use editors member access list of users allowed edit range.

in case, want enable "everyone" edit entire document, remove permission edit specific paragraphs.

in vba, (i'm sure can translate c#):

' allow access entire doc activedocument.content.editors.add wdeditoreveryone  ' remove access paragraph 1 activedocument.content.paragraphs(1).editors(wdeditoreveryone).delete 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -