If its a pick list, you will have to provide the index value. Assuming that you have an enum called TargetValues.Contact having value 1, then it would go like:
map.targetentity = new Picklist();
//map.targetentity.name = "Contact"
map.targetentity.Value = Convert.ToInt32(TargetEntities.Contact);
-- Edit --
I believe for what you are trying to achieve you will have to somehow retrieve the target entity and only then you will be able to enumerate them.
See this, probably this would help.
If above is of no use, then following is how you can do it:
- Opened picklist, from the UI, write down the number of indices and their cooresponding values.
- Created an enum in code, and assign those values/indices to it.
- Use enum at runtime(given in example above), to set the picklist.
But then somehow indices may change over a period of time, so in that case you can create an enumerated xml with those values/indices, and load them on runtime. But the problem with this approach is that:
- Everytime anyone is going to change the index, which is very rare, the administrator shall also have to change the xml file.
- Load an external xml file is an overhead.
Not-so-good approach, but running against a ticking deadline this is what you can do; this is never going to break or cause trouble. Just that xml loading part is not good.
Btw, if you would go through the CRM SDK, you will find the examples of similar sort.