You are viewing limited content. For full access, please sign in.

Question

Question

Failure casting GetDatumAsString to EntryType enum

asked on August 26, 2016

 

I have the following code...

	string serverName = "myServer";
	string repositoryName = "myRepository";

	var repository = new RepositoryRegistration(serverName, repositoryName);
	using (var session = new Session())
	{
		session.LogIn(repository);

		EntryListingSettings settings = new EntryListingSettings();
		settings.AddColumn(SystemColumn.Id);
		settings.AddColumn(SystemColumn.EntryType);
		
		FolderInfo info = Folder.GetFolderInfo("\\MyPath\\MySubPath", session);
	
		var listing = info.OpenFolderListing(settings, 1000);

		foreach (var item in listing)
		{
			var entryString = item.GetDatumAsString(SystemColumn.EntryType);
			EntryType entryType = (EntryType)Enum.Parse(typeof(EntryType), entryString);
		}
	}

 

I would expect the SystemColumn.EntryType to return one of the enum values, but when the entry that is found is an electronic document it returns "Adobe Acrobat Document".  Is this a bug or it is expected that the EntryType value can be something other than one of the enumeration types.

If it is expected to be something other than one of the EntryTypes, any suggestions on how I can write this code to be able to return the EntryType as an enum?

0 0

Answer

APPROVED ANSWER SELECTED ANSWER
replied on August 29, 2016

The string version of the entry type is for display purposes only. Use the bracket operator to retrieve the entry type object from the EntryListingRow:

EntryType entryType = (EntryType)item[SystemColumn.EntryType];

 

5 0
replied on September 1, 2016

Would that be the recommended practice for getting any field value?

0 0
replied on September 1, 2016

Yes, if you just want a string to display you should use the GetDatumAsString method, otherwise use the bracket operator or GetDatum methods and cast the object to the proper type.

2 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.