Author Archives: Stu

Working with Word and OpenXML

When working with Word documents using the OpenXML SDK, it’s not obvious how to remove document protection. The following code shows you how: using (WordprocessingDocument wordDocument = WordprocessingDocument.Open("[path to Word document]", true)) { DocumentFormat.OpenXml.OpenXmlElement protectedDocElement = wordDocument.MainDocumentPart.DocumentSettingsPart.ChildElements.FirstOrDefault(el => el.XmlQualifiedName.Name.Equals("documentProtection")); if … Continue reading

Posted in Office, SharePoint | Tagged , , | Leave a comment

Web Config Updates

The SPWebConfigModification class for SharePoint provides an easy way of updating the web config for a web application. Sometimes, however, I’ve seen it used incorrectly. For example, it’s not advisable to try and write to the web config on Web … Continue reading

Posted in Configuration, SharePoint | Tagged , | Leave a comment

Merry Christmas

Happy Christmas and a prosperous New Year, I hope 2013 is everything you expect and more!

Posted in General | Leave a comment

Get Default Database Infomation

SharePoint Short #15 Looking for a quick an easy way of retrieving the default content database information, like the SQL instance (i.e. servername\instance)? string sqlServerInstance = SPWebService.ContentService.DefaultDatabaseInstance.NormalizedDataSource;string sqlServerInstance = SPWebService.ContentService.DefaultDatabaseInstance.NormalizedDataSource; or individually string sqlInstance = SPWebService.ContentService.DefaultDatabaseInstance.Instance; string sqlServer = SPWebService.ContentService.DefaultDatabaseInstance.Server;string … Continue reading

Posted in SharePoint Shorts | Tagged | Leave a comment

Impersonating Current App Pool User

Using SharePoint it’s easy to run a block of code with elevated permissions: SPSecurity.RunWithElevatedPrivileges(()=> { using (SPSite elevatedSite = new SPSite(siteId)) { using (SPWeb elevatedWeb = elevatedSite.OpenWeb(wedId)) { // operations using elevated SPWeb object… } } });SPSecurity.RunWithElevatedPrivileges(()=> { using (SPSite … Continue reading

Posted in General | Tagged | Leave a comment