Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Description: its works for DOC,PPT,XLS
        /// </summary>
        /// <param name="filepath"></param>
        /// <returns></returns>
        public static List <DocumentData> ReadMetaDataInComments(string filepath)
        {
            List <DocumentData> lstmetadata = new List <DocumentData>();

            OleDocumentProperties myFile = new DSOFile.OleDocumentProperties();

            myFile.Open(filepath, true, DSOFile.dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess);

            /* foreach (DSOFile.CustomProperty property in myFile.CustomProperties)
             * {
             *   lstmetadata.Add(new DocumentData { Text = property.Name, Value = Convert.ToString(property.get_Value()) });
             * }
             */
            string data = "";

            if (!string.IsNullOrEmpty(myFile.SummaryProperties.Comments))
            {
                data = myFile.SummaryProperties.Comments;
            }
            if (!string.IsNullOrEmpty(myFile.SummaryProperties.Title))
            {
                data = myFile.SummaryProperties.Title;
            }
            lstmetadata = JsonConvert.DeserializeObject <List <DocumentData> >(data);
            myFile.Close();


            return(lstmetadata);
        }
Exemplo n.º 3
0
        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);
        }
        public IHttpActionResult uploadFile()
        {
            try
            {
                if (HttpContext.Current.Request.Files.AllKeys.Any())
                {
                    //string fileName = HttpContext.Current.Request.Form["fileName"];

                    // Upload file
                    string path = HttpContext.Current.Request.Form["path"];
                    if (!path.EndsWith("\\"))
                    {
                        path = path + "\\";
                    }
                    var file = HttpContext.Current.Request.Files[0];
                    file.SaveAs(path + file.FileName);

                    // Add custom property
                    DSOFile.OleDocumentProperties file1 = new DSOFile.OleDocumentProperties();
                    file1.Open(path + file.FileName, false, DSOFile.dsoFileOpenOptions.dsoOptionDefault);
                    object createdBy = HttpContext.Current.Request.Form["createdBy"];
                    file1.CustomProperties.Add("createdBy", createdBy);
                    file1.Close(true);

                    return(Ok());
                }
                return(BadRequest());
            }
            catch (Exception e)
            {
                throw;
            }
        }
Exemplo n.º 5
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");
     }
 }
        public IHttpActionResult createNewFolder()
        {
            try
            {
                string path          = HttpContext.Current.Request.Form["path"];
                string directoryName = HttpContext.Current.Request.Form["directoryName"];
                string createdBy     = HttpContext.Current.Request.Form["createdBy"];

                if (!path.EndsWith("\\"))
                {
                    path = path + "\\";
                }
                Directory.CreateDirectory(path + directoryName);

                // Add custom property
                DSOFile.OleDocumentProperties file1 = new DSOFile.OleDocumentProperties();
                file1.Open(path + directoryName, false, DSOFile.dsoFileOpenOptions.dsoOptionDefault);
                file1.CustomProperties.Add("createdBy", createdBy);
                file1.Close(true);

                return(Ok());
            }
            catch (Exception e)
            {
                throw;
            }
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
        public static string GetCustomFileProperty(string filename)
        {
            OleDocumentProperties myFile = new DSOFile.OleDocumentProperties();

            myFile.Open(filename, false, DSOFile.dsoFileOpenOptions.dsoOptionDefault);
            foreach (DSOFile.CustomProperty property in myFile.CustomProperties)
            {
                if (property.Name == "MyPlugin")
                {
                    string pluginname = property.get_Value();
                    myFile.Close(true);
                    return(pluginname);
                }
            }
            return(null);
        }
Exemplo n.º 11
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);
            //}
        }
Exemplo n.º 12
0
        public static List <DocumentData> ReadMetaData(string filepath)
        {
            List <DocumentData> lstmetadata = new List <DocumentData>();

            OleDocumentProperties myFile = new DSOFile.OleDocumentProperties();

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

            foreach (DSOFile.CustomProperty property in myFile.CustomProperties)
            {
                lstmetadata.Add(new DocumentData {
                    Key = property.Name, Text = Convert.ToString(property.get_Value())
                });
            }


            myFile.Close();

            return(lstmetadata);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
        private async Task <List <string> > ReadMetadata(string filePath)
        {
            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. */

            // Check if file has a certain property set
            var metadata = new List <string>();

            foreach (DSOFile.CustomProperty p in file.CustomProperties)
            {
                if (p.Name == key)
                {
                    string value = p.get_Value();
                    metadata = JsonConvert.DeserializeObject <List <string> >(value);
                }
            }

            file.Close(true);
            return(metadata);
        }
        public IHttpActionResult GetFolderContents(string path)
        {
            dt = new DataTable();
            dt.Columns.Add("title");
            dt.Columns.Add("type");
            dt.Columns.Add("path");
            dt.Columns.Add("createdBy");
            dt.Columns.Add("lastModified");
            string basePath = "D:\\";

            System.Collections.IEnumerable subDirectories;
            //System.Collections.IEnumerable files;
            //string[] files;
            List <string> files;

            try
            {
                if (path != null)
                {
                    basePath = path;
                }
                //subDirectories = Directory.GetDirectories(basePath);
                subDirectories = Directory.GetDirectories(basePath);
                files          = Directory.GetFiles(basePath).ToList();

                DSOFile.OleDocumentProperties file1 = new DSOFile.OleDocumentProperties();
                foreach (var item in files)
                {
                    DataRow  dr          = dt.NewRow();
                    string[] titleTokens = item.ToString().Split(new[] { '\\' }, StringSplitOptions.None);
                    string   title       = titleTokens[titleTokens.Length - 1];

                    dr["title"]        = title;
                    dr["type"]         = "FILE";
                    dr["path"]         = item;
                    dr["lastModified"] = Directory.GetLastWriteTime(item.ToString());


                    // Get Custom Property
                    file1.Open(@item, false, DSOFile.dsoFileOpenOptions.dsoOptionDefault);

                    foreach (DSOFile.CustomProperty property in file1.CustomProperties)
                    {
                        if (property.Name == "createdBy")
                        {
                            //Property exists
                            dr["createdBy"] = property.get_Value();
                        }
                    }
                    file1.Close();


                    dt.Rows.Add(dr);
                }
                foreach (var item in subDirectories)
                {
                    DataRow  dr          = dt.NewRow();
                    string[] titleTokens = item.ToString().Split(new[] { '\\' }, StringSplitOptions.None);
                    string   title       = titleTokens[titleTokens.Length - 1];

                    dr["title"]        = title;
                    dr["type"]         = "DIR";
                    dr["path"]         = item;
                    dr["lastModified"] = Directory.GetLastWriteTime(item.ToString());

                    if (!IsSystemDir(item.ToString()))
                    {
                        // Get Custom Property
                        file1.Open(@item.ToString(), false, DSOFile.dsoFileOpenOptions.dsoOptionDefault);

                        foreach (DSOFile.CustomProperty property in file1.CustomProperties)
                        {
                            if (property.Name == "createdBy")
                            {
                                //Property exists
                                dr["createdBy"] = property.get_Value();
                            }
                        }
                        file1.Close();
                    }

                    dt.Rows.Add(dr);
                }

                return(Ok(dt));
            }
            catch (Exception e)
            {
                throw;
            }
        }