Vault 2015 C# Get Selected File Properties and Values

Vault 2015 C# Get Selected File Properties and Values

Anonymous
Not applicable
2,574 Views
4 Replies
Message 1 of 5

Vault 2015 C# Get Selected File Properties and Values

Anonymous
Not applicable

This is bit vague or may be i am not understanding,

 

I trying to get the seleted file's properties and it values.

 

Now I am able to get it, but the properties are not matching against the values.

I am gettign the properties values and propdefids. But I am not able to get the correct property using the propdefids.

 

How do I get properties and its values of a selected files in a dictionary format so i have matching property names in keys and the property values in dictionary values.

 

var propDefs = connection.PropertyManager.GetPropertyDefinitions(VDF.Vault.Currency.Entities.EntityClassIds.Files, null, VDF.Vault.Currency.Properties.PropertyDefinitionFilter.IncludeAll);
                var propSvc = connection.WebServiceManager.PropertyService;
                var properties = propSvc.GetPropertiesByEntityIds("FILE", new long[] { selectedFile.Id });

foreach (var item in properties)
{
  string val = item.Val.ToString();

}
0 Likes
2,575 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

Found the solution,

 

public static void PrintProperties(VDF.Vault.Currency.Connections.Connection connection, File selectedFile)
        {
            VDF.Vault.Currency.Entities.FileIteration fileInteration = new FileIteration(connection, selectedFile);
            var propDefs = connection.PropertyManager.GetPropertyDefinitions(VDF.Vault.Currency.Entities.EntityClassIds.Files, null, VDF.Vault.Currency.Properties.PropertyDefinitionFilter.IncludeAll);
            foreach (var key in propDefs.Keys)
            {
                // Print the Name from the Definition and the Value from the Property
                object propValue = connection.PropertyManager.GetPropertyValue(fileInteration, propDefs[key], null);
                logit.logger(string.Format("== LIB 1 DICT == >>   '{0}' = '{1}'", key.ToString(), propValue == null ? "" : propValue.ToString()));
            }
        }
0 Likes
Message 3 of 5

Anonymous
Not applicable

Hello, can you tell me, how did you get 

selectedFile

??? 

0 Likes
Message 4 of 5

colin.holloway
Participant
Participant

Hi Pashin,

Here is the code I use to get the file iteration from a file name.

 

        public FileIteration getFileIteration(string nameOfFile, VDF.Vault.Currency.Connections.Connection conn)
        {
            SrchCond[] conditions = new SrchCond[1];
            long lCode = 1;
            PropDef[] Defs = conn.WebServiceManager.PropertyService.GetPropertyDefinitionsByEntityClassId("FILE");
            PropDef Prop = null;

            foreach (PropDef def in Defs)
            {
                if (def.DispName == "File Name")
                {
                    Prop = def;
                    break;
                }
            }

            SrchCond searchCondition = new SrchCond();
            searchCondition.PropDefId = Prop.Id;

            searchCondition.PropTyp = PropertySearchType.SingleProperty;
            searchCondition.SrchOper = lCode;

            searchCondition.SrchTxt = nameOfFile;

            conditions[0] = searchCondition;

            // search for files
            List<Autodesk.Connectivity.WebServices.File> FileList = new List<Autodesk.Connectivity.WebServices.File>();
            string sBookmark = string.Empty;
            SrchStatus Status = null;


            while (Status == null || FileList.Count < Status.TotalHits)
            {
                Autodesk.Connectivity.WebServices.File[] files = conn.WebServiceManager.DocumentService.FindFilesBySearchConditions(conditions, null, null, true, true, ref sBookmark, out Status);

                if (files != null)
                {
                    FileList.AddRange(files);
                }
            }

            FileIteration oFileIteration = null;
            for (int i = 0; i <= FileList.Count - 1; i++)
            {
                if (FileList[i].Name.Equals(nameOfFile, StringComparison.InvariantCultureIgnoreCase))
                {
                    oFileIteration = new FileIteration(conn, FileList[i]);
                }
            }

            return oFileIteration;

        }

Hope that helps.

Colin Holloway

Message 5 of 5

colin.holloway
Participant
Participant

Hi Raghulan,

 

The only change I needed to make to your code was to extract the Display Name as well because the Key of User Properties is a unique GUID and you need to cross reference that with Display Name to get usable information.

 

foreach (var key in propDefs.Keys)
                                    {
                                        // Print the Name from the Definition and the Value from the Property
                                        object propName = propDefs[key].DisplayName;
                                        object propValue = conn.PropertyManager.GetPropertyValue(MyFileIter, propDefs[key], null);
                                        Console.WriteLine(string.Format("== LIB 1 DICT == >>   '{0}' = '{1}'", propName.ToString(), propValue == null ? "" : propValue.ToString()));
                                    }

Thanks for your solution post, it put me on the right path!

Colin Holloway