How to set the default value for a look-up field, for an item as it is being created?

Actually, it may seem to be a very simple task to achieve. Just go to the specific list in the site and then to the custom look up column and then try setting default value...... Actually, there is no way you can set the default value of a look up field (Custom or OOB).

And of course when the SharePoint admin drop to their knees and pull their hair from their heads, then come the SharePoint developers, the saviours of dire straits. Yes, as a developer you can set the default value of a look-up column. The code is very simple, just need to take care of the highlighted part.

<Code>

SPList docs = w.Lists["Documents"];

SPFieldLookup fl = (SPFieldLookup)docs.Fields["City"];

fl.DefaultValue = "1;#Mexico City";

fl.Update();

</Code>

And that’s it, Voila! Another SharePoint admin problem beaten to dust by a SharePoint developer code piece.