Example #1
0
        /// <summary>
        /// Creates a new empty document
        /// </summary>
        /// <param name="templatePath">Path to the project template</param>
        /// <param name="filePath">Path where to save the new doc</param>
        /// <param name="overwrite">If true overwrites existing files with same name</param>
        /// <returns></returns>
        public static Document CreateNewDoc(string templatePath, string filePath, bool overwrite = true)
        {
            Assert.NotNull(Uiapp);
            Document doc = null;

            try
            {
                if (overwrite && File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
            }
            catch { }

            //OpenAndActivateDocument only works if run from the current context
            UiContext.Send(x =>
            {
                //if already open, just use it
                if (!File.Exists(filePath))
                {
                    doc = Uiapp.Application.NewProjectDocument(templatePath);
                    doc.SaveAs(filePath);
                    doc.Close();
                }

                doc = Uiapp.OpenAndActivateDocument(filePath).Document;
            }
                           , null);
            Assert.NotNull(doc);
            return(doc);
        }
Example #2
0
        /// <summary>
        /// Opens and activates a document if not open already
        /// </summary>
        /// <param name="filePath">Path to the file to open</param>
        public static Document OpenDoc(string filePath)
        {
            Assert.NotNull(Uiapp);
            Document doc = null;

            //OpenAndActivateDocument only works if run from the current context
            UiContext.Send(x => { doc = Uiapp.OpenAndActivateDocument(filePath).Document; }, null);
            Assert.NotNull(doc);
            return(doc);
        }