public static bool Protect(DocumentCustomProperties props) { Document wordDoc = props._wordDoc; var dirtyState = wordDoc.Saved; try { var pass = SitecoreArticle.GetDocumentPassword(); if (wordDoc.ProtectionType == WdProtectionType.wdNoProtection) { wordDoc.Protect(WdProtectionType.wdAllowOnlyReading, true, pass, false, true); props.DocumentPassword = pass; } } catch (Exception ex) { Globals.SitecoreAddin.LogException("Problem protecting the word document!", ex); return(false); } finally { wordDoc.Saved = dirtyState; } return(true); }
public ArticleDetails() { try { Globals.SitecoreAddin.Log("Initializing the article details window..."); InitializeComponent(); Opacity = 0; _scTree = new SCTree(); _scServer = new SCServer(); // TEMPORARY code to deal with QA login var credCache = new CredentialCache(); var netCred = new NetworkCredential("velir", "ebi3000"); credCache.Add(new Uri(_scTree.Url), "Basic", netCred); credCache.Add(new Uri(_scServer.Url), "Basic", netCred); _scTree.PreAuthenticate = true; _scTree.Credentials = credCache; _scServer.PreAuthenticate = true; _scServer.Credentials = credCache; // end temporary _user = SitecoreUser.GetUser(); _authors = _scTree.GetAuthors().Select(t => new StaffStruct() { ID = t.ID, Name = t.Name, Publications = t.Publications }).ToArray().ToList(); _editors = _scTree.GetEditors().Select(t => new StaffStruct() { ID = t.ID, Name = t.Name, Publications = t.Publications }).ToArray().ToList(); _sitecoreArticle = new SitecoreArticle(); _wordUtils = new WordUtils(); _wordApp = SitecoreAddin.WordApp; _documentCustomProperties = new DocumentCustomProperties(_wordApp, _wordApp.ActiveDocument); try { InitializeDropdowms(); InitializeControllers(); Opacity = 1; SetCheckedOutStatus(); _connectedAtStart = true; } catch (WebException e) { AlertConnectionFailed(); Globals.SitecoreAddin.LogException("Error getting metadata or checked out status!", e); throw new ApplicationException("Error getting metadata or checked out status!", e); } var deleteIcon = new ImageList(); deleteIcon.Images.Add(Resources.delete_icon); uxSelectedAuthors.SmallImageList = deleteIcon; uxSelectedEditors.SmallImageList = deleteIcon; string articleNumber = GetArticleNumber(); if (!articleNumber.IsNullOrEmpty()) { uxArticleNumber.Text = articleNumber; GetArticeDetailsFromSitecore(); } uxLockStatus.Refresh(); Globals.SitecoreAddin.Log("Article details window initialized."); } catch (Exception ex) { Globals.SitecoreAddin.LogException("Error while loading article details!", ex); } }