public string GetTemplateFilePath() { using (JetTask t = new JetTask()) { t.CommandText = "SELECT FilePath FROM Templates WHERE TemplateID = @TemplateID"; t.AddParameter("@TemplateID", ID); object obj = t.ExecuteScalar(); if (obj == null) { return(""); } if (Path.IsPathRooted(obj.ToString()) == false) { obj = Path.Combine(Program.Configuration.NetworkPath, obj.ToString()); } return(obj.ToString()); } }
public void PopulateFields() { // fill hashTable Fields.Clear(); Aspose.Word.Document doc; string filePath = this.SavedPath == "" ? this.FilePath : this.SavedPath; if (File.Exists(filePath) == false) { return; } using (FileStreamManager fs = new FileStreamManager(filePath, true)) { fs.OpenFileStream(); if (fs.Abort == true) { TemplateValid = false; return; } doc = null; try { doc = new Aspose.Word.Document(fs.FileStream); } catch (Exception ex) { ErrorManager.WriteTraceInfo("TemplateStruct.PopulateFields().openDocument", ex, true, String.Format("The following document failed to open...\n{0}", filePath)); TemplateValid = false; return; } } using (JetTask t = new JetTask()) { object str; foreach (DocumentProperty property in doc.CustomDocumentProperties) { if (property.Name.StartsWith("pA_")) { t.CommandText = "SELECT [Default] FROM FieldNames WHERE FieldKey = '" + property.Name + "'"; str = t.ExecuteScalar(); if (str == null) { str = ""; } this.Fields.Add(property.Name, str); } } } // sync dataTable if (this.DataTable != null) { Hashtable ht = new Hashtable(); foreach (DictionaryEntry entry in this.Fields) { ht.Add(entry.Key, entry.Value); // check to see if its already in the datatable if (this.DataTable != null && this.DataTable.IsInitialized) { if (this.DataTable.FindByKey(entry.Key.ToString()) == null) { this.DataTable.AddChildKeyValueRow(entry.Key.ToString(), DatabaseOptimizer.GetKeyName(entry.Key.ToString()), true, "", true); } } } // update visibility if (this.DataTable.Count > 0) { foreach (MasterDS.ChildKeyValueRow row in DataTable) { row.IsVisible = ht.ContainsKey(row.Key); row.KeyName = DatabaseOptimizer.GetKeyName(row.Key); } } } }