<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Trailblazer's Sharepoint Blog : default value for a look-up field</title><link>http://blogs.msdn.com/varun_malhotra/archive/tags/default+value+for+a+look-up+field/default.aspx</link><description>Tags: default value for a look-up field</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>How to set the default value for a look-up field, for an item as it is being created?</title><link>http://blogs.msdn.com/varun_malhotra/archive/2008/06/19/how-to-set-the-default-value-for-a-look-up-field-for-an-item-as-it-is-being-created.aspx</link><pubDate>Thu, 19 Jun 2008 02:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8619075</guid><dc:creator>varunmalhotra</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/varun_malhotra/comments/8619075.aspx</comments><wfw:commentRss>http://blogs.msdn.com/varun_malhotra/commentrss.aspx?PostID=8619075</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;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).&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;And of course when the SharePoint admin drop to their knees and pull their hair from their heads, then come the SharePoint developers, &lt;B style="mso-bidi-font-weight: normal"&gt;the saviours&lt;/B&gt; 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.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&amp;lt;Code&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; LINE-HEIGHT: 115%; mso-ansi-language: EN-US; mso-themecolor: text1"&gt;&lt;FONT face=Calibri&gt;SPList docs = w.Lists["Documents"];&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; LINE-HEIGHT: 115%; mso-ansi-language: EN-US; mso-themecolor: text1"&gt;&lt;FONT face=Calibri&gt;SPFieldLookup fl = (SPFieldLookup)docs.Fields["City"];&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"&gt;&lt;FONT face=Calibri&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; BACKGROUND: yellow; COLOR: black; LINE-HEIGHT: 115%; mso-ansi-language: EN-US; mso-themecolor: text1; mso-highlight: yellow"&gt;fl.DefaultValue = "1;#Mexico City";&lt;/SPAN&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; LINE-HEIGHT: 115%; mso-ansi-language: EN-US; mso-themecolor: text1"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"&gt;&lt;SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; LINE-HEIGHT: 115%; mso-ansi-language: EN-US; mso-themecolor: text1"&gt;&lt;FONT face=Calibri&gt;fl.Update();&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&amp;lt;/Code&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"&gt;&lt;SPAN lang=EN-US style="COLOR: black; mso-ansi-language: EN-US; mso-themecolor: text1"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;And that’s it, Voila! Another SharePoint admin problem beaten to dust by a SharePoint developer code piece.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"&gt;&lt;SPAN lang=EN-US&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8619075" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/varun_malhotra/archive/tags/default+value+for+a+look-up+field/default.aspx">default value for a look-up field</category></item></channel></rss>