示例#1
0
文件: Program.cs 项目: sk00538811/POC
        /// <summary>
        /// Description: its works for DOC,PPT,XLS
        /// </summary>
        /// <param name="filepath"></param>
        /// <returns></returns>
        public static void ApplyMetaDataInComments(string filepath, List <DocumentData> lstmetadata)
        {
            OleDocumentProperties myFile = new DSOFile.OleDocumentProperties();

            myFile.Open(filepath, false, DSOFile.dsoFileOpenOptions.dsoOptionDefault);

            /*
             * bool ispropfound = false;
             * foreach (var metadata in lstmetadata)
             * {
             *  ispropfound = false;
             *  foreach (DSOFile.CustomProperty property in myFile.CustomProperties)
             *  {
             *      if (property.Name.ToUpper() == metadata.Text.ToUpper())
             *      { ispropfound = true; break; }
             *
             *  }
             *  if (!ispropfound)//add property
             *  {
             *      object objValue = metadata.Value;
             *      myFile.CustomProperties.Add(metadata.Text, ref objValue);
             *  }
             * }*/
            myFile.SummaryProperties.Comments = JsonConvert.SerializeObject(lstmetadata);
            myFile.SummaryProperties.Title    = JsonConvert.SerializeObject(lstmetadata);
            myFile.Save();
            myFile.Close(true);
        }
示例#2
0
 public void AñadirIdAlfrescoLocal(string idRemoto)
 {
     try
     {
         List <string> extOfficeDocs = new List <string> {
             ".docx", ".docm", ".dotx", ".dotm",
             ".docb", ".xlsx", ".xlsm", ".xltx", ".xltm", ".pptx", "pptm", ".potx", "potm",
             ".ppam", ".ppsm", ".sldx", ".sldm"
         };
         if (extOfficeDocs.Contains(Path.GetExtension(PathLocal)))
         {
             SetCustomProperty(PathLocal, "IdAlfresco", idRemoto, PropertyTypes.Text, Path.GetExtension(PathLocal));
         }
         else
         {
             OleDocumentProperties myFile = new DSOFile.OleDocumentProperties();
             myFile.Open(PathLocal, false, DSOFile.dsoFileOpenOptions.dsoOptionDefault);
             myFile.CustomProperties.Add("IdAlfresco", idRemoto);
             myFile.Save();
             myFile.Close(true);
         }
     }
     catch (System.Runtime.InteropServices.COMException)
     {
         Console.WriteLine("Error de escritura del id");
     }
 }
示例#3
0
文件: Program.cs 项目: sk00538811/POC
        public static void ApplyMetaData(string filepath, List <DocumentData> lstmetadata)
        {
            bool ispropfound             = false;
            OleDocumentProperties myFile = new DSOFile.OleDocumentProperties();

            myFile.Open(filepath, false, DSOFile.dsoFileOpenOptions.dsoOptionDefault);
            foreach (var metadata in lstmetadata)
            {
                ispropfound = false;
                foreach (DSOFile.CustomProperty property in myFile.CustomProperties)
                {
                    if (property.Name.ToUpper() == metadata.Key.ToUpper())
                    {
                        ispropfound = true; break;
                    }
                }
                if (!ispropfound)//add property
                {
                    object objValue = metadata.Text;
                    myFile.CustomProperties.Add(metadata.Key, ref objValue);
                }
            }
            myFile.Save();
            myFile.Close(true);
        }
示例#4
0
        public static void FillKeywords(string item, IEnumerable <string> words)
        {
            OleDocumentProperties dso = new DSOFile.OleDocumentProperties();

            dso.Open(item);
            dso.SummaryProperties.Keywords = ConcatStrings(words);
            dso.Save();
            dso.Close(true);
        }
示例#5
0
        private void metroButton1_Click(object sender, EventArgs e)
        {
            var dsa = UsingFile.SearchAndFindFilesName(textBox1.Text);

            foreach (var item in dsa)
            {
                OleDocumentProperties dso = new DSOFile.OleDocumentProperties();
                dso.Open(item);
                MessageBox.Show(dso.SummaryProperties.Keywords);
                dso.Save();
                dso.Close(true);
            }
        }
示例#6
0
        private void button1_Click(object sender, EventArgs e)
        {
            //FileInfo oFileInfo = new FileInfo("C:\\Users\\Solomon\\Downloads\\Files\\testdoc.docx");

            //if (oFileInfo != null || oFileInfo.Length == 0)
            //{
            //    MessageBox.Show("My File's Name: \"" + oFileInfo.Name + "\"");
            //    // For calculating the size of files it holds.
            //    MessageBox.Show("myFile total Size: " + oFileInfo.Length.ToString());
            //}

            //string user = System.IO.File.GetAccessControl("C:\\Users\\Solomon\\Downloads\\Files\\atext.txt").GetOwner(typeof(System.Security.Principal.NTAccount)).ToString();
            //MessageBox.Show(user);
            //var myObject = ShellObject.FromParsingName("C:\\Users\\Solomon\\Downloads\\Files\\atext.txt");
            //IShellProperty prop = myObject.Properties.GetProperty("Type");

            object yourValue             = "I LOVE AOA";
            OleDocumentProperties myFile = new DSOFile.OleDocumentProperties();

            myFile.Open(@"C:\\Users\\Solomon\\Downloads\\Files\\new.txt", false, DSOFile.dsoFileOpenOptions.dsoOptionDefault);
            foreach (DSOFile.CustomProperty property in myFile.CustomProperties)
            {
                if (property.Name == "ACE OF ANGELS")
                {
                    //Property exists
                    //End the task here (return;) oder edit the property
                    property.set_Value(yourValue);
                }
            }
            myFile.CustomProperties.Add("ACE OF ANGELS", ref yourValue);
            myFile.Save();
            myFile.Close(true);
            MessageBox.Show("Saved!");
            //DbClass dbCon = new DbClass();

            //List<string> dataDisplay = new List<string>();

            //dataDisplay = dbCon.DbRetrieve("Userinfo", "sh_9513");

            //foreach(string i in dataDisplay)
            //{
            //    Console.WriteLine(i);
            //    MessageBox.Show(i);
            //}
        }
示例#7
0
        public static void SetCustomFileProperty(string filename, string pluginname)
        {
            OleDocumentProperties myFile = new DSOFile.OleDocumentProperties();

            myFile.Open(filename, false, DSOFile.dsoFileOpenOptions.dsoOptionDefault);
            object Value = pluginname;

            foreach (DSOFile.CustomProperty property in myFile.CustomProperties)
            {
                if (property.Name == "MyPlugin")
                {
                    property.set_Value(Value);
                    myFile.Close(true);
                    return;
                }
            }
            myFile.CustomProperties.Add("MyPlugin", ref Value);
            myFile.Save();
            myFile.Close(true);
        }
示例#8
0
        private async Task AddMetadata(string filePath, string tags)
        {
            OleDocumentProperties file = new DSOFile.OleDocumentProperties();

            file.Open(filePath, false, DSOFile.dsoFileOpenOptions.dsoOptionDefault); /*this path can be grabbed from the connecter database and the associated tags also*/
            string key   = "3dom";                                                   /* Use any key you want, these will be saved in the file. */
            object value = tags;
            // Check if file has a certain property set
            bool hasProperty = false;

            foreach (DSOFile.CustomProperty p in file.CustomProperties)
            {
                if (p.Name == key)
                {
                    hasProperty = true;
                }
            }
            // If it doesn't have the property, add it, otherwise set it.
            // This is the only way I found to loop through the properties
            if (!hasProperty)
            {
                file.CustomProperties.Add(key, ref value);
            }
            else
            {
                foreach (DSOFile.CustomProperty p in file.CustomProperties)
                {
                    if (p.Name == key)
                    {
                        p.set_Value(value);
                    }
                }
            }
            // Go through existing custom properties.
            foreach (DSOFile.CustomProperty p in file.CustomProperties)
            {
                Console.WriteLine("{0}:{1}", p.Name, p.get_Value().ToString());
            }
            file.Save();
            file.Close(true);
        }