示例#1
0
 private void button4_Click(object sender, EventArgs e)
 {
     foreach (ListViewItem item in listView1.Items)
     {
         CustomPropertyEntity cProp = new CustomPropertyEntity(item.Text, item.SubItems[1].Text);
         if (document != null)
         {
             document.SetCustomProperty(cProp);
         }
     }
 }
示例#2
0
        private void addListViewItem(CustomPropertyEntity cProp)
        {
            ListViewItem item = new ListViewItem(cProp.Name);

            item.SubItems.Add(cProp.Value);
            int index = ListViewContains(cProp.Name);

            if (index >= 0)
            {
                listView1.Items.RemoveAt(index);
                listView1.Items.Insert(index, item);
            }
            else
            {
                listView1.Items.Add(item);
            }
        }
示例#3
0
        public List <CustomPropertyEntity> GetCustomProperities()
        {
            List <CustomPropertyEntity> allCustomProperities = new List <CustomPropertyEntity>();


            // Given a document name, a property name/value, and the property type,
            // add a custom property to a document. The method returns the original
            // value, if it existed.

            var cPropnewProp = new CustomDocumentProperty();


            // Now that you have handled the parameters, start
            // working on the document.
            //newProp.FormatId = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}";
            //newProp.Name = propertyName;

            using (var document = WordprocessingDocument.Open(this.FileLocation, true))
            {
                var customProps = document.CustomFilePropertiesPart;
                if (customProps == null)
                {
                    // No custom properties? Add the part, and the
                    // collection of properties now.
                    return(null);
                }

                var props = customProps.Properties;
                if (props != null)
                {
                    // This will trigger an exception if the property's Name
                    // property is null, but if that happens, the property is damaged,
                    // and probably should raise an exception.
                    foreach (CustomDocumentProperty p in props)
                    {
                        CustomPropertyEntity cProp = new CustomPropertyEntity();
                        cProp.Name  = p.Name.Value;
                        cProp.Value = p.InnerText;
                        allCustomProperities.Add(cProp);
                    }
                }
            }
            return(allCustomProperities);
        }
示例#4
0
 public string SetCustomProperty(CustomPropertyEntity cProp)
 {
     return(SetCustomProperty(cProp.Name, cProp.Value, PropertyTypes.Text));
 }