/* Demo.cs * part of zaaReloaded2 * * Copyright 2015-2017 Daniel Kraus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System.IO; using Microsoft.Office.Interop.Word; namespace zaaReloaded2.Demo { /// /// Static class that serves to load an embedded Word document /// into a temporary file and open that temporary file in Word. /// static class Demo { #region Public methods /// /// Opens a demo document. The document's Saved property is set to /// false so that a user who wants to save changes will be prompted /// for a file name. /// public static void OpenDemoDocument() { string tempFile = CreateTempFileFromResource(); Document demoDoc = Globals.ThisAddIn.Application.Documents .Add(Template: tempFile); File.Delete(tempFile); Globals.ThisAddIn.Ribbon.ActivateZaaTab(); } #endregion #region Private methods /// /// Copies the built-in demo file from a resource stream to a /// temporary file and returns the path to that file. /// /// Path to the newly created temporary file. static string CreateTempFileFromResource() { string resourceName = "zaaReloaded2.Demo.Demo.docx"; Stream resourceStream = typeof(Demo).Assembly .GetManifestResourceStream(resourceName); if (resourceStream == null) { throw new IOException("Unable to open stream " + resourceName); } string fileName = Path.GetTempFileName() + ".docx"; Stream tempStream = File.Create(fileName); resourceStream.CopyTo(tempStream); tempStream.Close(); return fileName; } #endregion } }