<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Adventures in SPWonderland. - AJAX</title>
    <link>http://blogs.flexnetconsult.co.uk/colinbyrne/</link>
    <description>Taking apart and putting back together</description>
    <language>en-us</language>
    <copyright>Colin Byrne</copyright>
    <lastBuildDate>Thu, 27 Mar 2008 08:42:00 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>webparts@flexnetconsult.co.uk</managingEditor>
    <webMaster>webparts@flexnetconsult.co.uk</webMaster>
    <item>
      <trackback:ping>http://blogs.flexnetconsult.co.uk/colinbyrne/Trackback.aspx?guid=f1be83c7-0b1e-4704-9df3-31a306868451</trackback:ping>
      <pingback:server>http://blogs.flexnetconsult.co.uk/colinbyrne/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.flexnetconsult.co.uk/colinbyrne/PermaLink,guid,f1be83c7-0b1e-4704-9df3-31a306868451.aspx</pingback:target>
      <dc:creator>Colin Byrne</dc:creator>
      <wfw:comment>http://blogs.flexnetconsult.co.uk/colinbyrne/CommentView,guid,f1be83c7-0b1e-4704-9df3-31a306868451.aspx</wfw:comment>
      <wfw:commentRss>http://blogs.flexnetconsult.co.uk/colinbyrne/SyndicationService.asmx/GetEntryCommentsRss?guid=f1be83c7-0b1e-4704-9df3-31a306868451</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I'm doing a <a href="http://suguk.org/forums/thread/8918.aspx">presentation tonight
for SUGUK</a> on Silverlight in sharePoint and wanted to demo some of the <a href="http://www.ssblueprints.net/sharepoint/">Silverlight
Blueprints for SharePoint</a>.
</p>
        <p>
Naturally I hit a few issues along the way so I thought I'd pass a few tips on. 
</p>
        <p>
A major requirement is to have .Net 3.5 and AJAX running on your SharePoint site.
If you configure AJAX by hand as I did check this <a href="http://msdn2.microsoft.com/en-us/library/bb861898.aspx">MSDN
article</a> for configuring AJAX but use 3.5.0.0 as the version number. 
</p>
        <p>
I configured AJAX by hand but there is also a <a href="http://www.codeplex.com/features " temp_href="http://www.codeplex.com/features ">CodePlex
feature</a> that can install AJAX on all your WFE.
</p>
        <p>
It will also help to have Visual Studio 2008 and the Silverlight SDk installed on
your dev box.
</p>
        <p>
The first issue is that none of the XAP's as shipped will work on my machine. You'll
get an error like this
</p>
        <p>
 
</p>
        <p>
          <img src="http://blogs.flexnetconsult.co.uk/colinbyrne/content/binary/SL Controls Error 2.JPG" border="0" />
        </p>
        <p>
 
</p>
        <p>
checking the XAP files shows the shipped one has this as the first line of the manifest.
</p>
        <p>
&lt;Deployment xmlns="<a href="http://schemas.microsoft.com/client/2007/deployment">http://schemas.microsoft.com/client/2007/deployment</a>"
xmlns:x="<a href="http://schemas.microsoft.com/winfx/2006/xaml">http://schemas.microsoft.com/winfx/2006/xaml</a>"
EntryPointAssembly="SL.XAML.Navigation" EntryPointType="SL.XAML.Navigation.App"&gt;
</p>
        <p>
but if I recompile the source I get 
</p>
        <p>
&lt;Deployment xmlns="<a href="http://schemas.microsoft.com/client/2007/deployment">http://schemas.microsoft.com/client/2007/deployment</a>"
xmlns:x="<a href="http://schemas.microsoft.com/winfx/2006/xaml">http://schemas.microsoft.com/winfx/2006/xaml</a>"
EntryPointAssembly="SL.XAML.Navigation" EntryPointType="SL.XAML.Navigation.App" RuntimeVersion="2.0.30226.2"&gt;
</p>
        <p>
The missing RuntimeVersion seems the key here, looks like the U2U folks were running
a slightly different build of chiron the XAP compiler and certainly the Silverlight
2 runtime on my machine wont run a XAP without it.
</p>
        <p>
So the fix is to recompile the Silverlight Applications and redeploy the XAP to the
ClientBin directory in your IIS website directory.
</p>
        <p>
Second and more bizarre is the Navigation Sample. If you try to run it you get an
error about being unable to load the Assembly. 
</p>
        <p>
The problem here is that the PublicKey for the SL.Controls.Navigation.Dll is wrong
in the MasterPage.
</p>
        <p>
 
</p>
        <p>
 
</p>
        <p>
          <img src="http://blogs.flexnetconsult.co.uk/colinbyrne/content/binary/SL Controls Error.GIF" border="0" />
        </p>
        <p>
The MasterPage has 4aec304184eb9a69 when the DLL has bb99f30c0098259c. 
</p>
        <p>
The Fix is to change the MasterPage Register TagPrefix line to bb99f30c0098259c. You
can use SharePoint Designer or uninstall the feature change it and then
reinstall, reactivate.
</p>
        <p>
This will happen when you dev with an internal snk file which has your company private
keys in it and then decide you've got to change it before you ship. I've done exactly
the same thing myself, it really helps to test it on a single machine outside your
company first.
</p>
        <p>
And IT LIVES
</p>
        <p>
          <img src="http://blogs.flexnetconsult.co.uk/colinbyrne/content/binary/SSNavDemo.gif" border="0" />
        </p>
        <p>
 
</p>
        <img width="0" height="0" src="http://blogs.flexnetconsult.co.uk/colinbyrne/aggbug.ashx?id=f1be83c7-0b1e-4704-9df3-31a306868451" />
      </body>
      <title>Fix: Getting the Silverlight Blueprints for SharePoint to work</title>
      <guid isPermaLink="false">http://blogs.flexnetconsult.co.uk/colinbyrne/PermaLink,guid,f1be83c7-0b1e-4704-9df3-31a306868451.aspx</guid>
      <link>http://blogs.flexnetconsult.co.uk/colinbyrne/2008/03/27/FixGettingTheSilverlightBlueprintsForSharePointToWork.aspx</link>
      <pubDate>Thu, 27 Mar 2008 08:42:00 GMT</pubDate>
      <description>&lt;p&gt;
I'm doing a &lt;a href="http://suguk.org/forums/thread/8918.aspx"&gt;presentation tonight
for SUGUK&lt;/a&gt;&amp;nbsp;on Silverlight in sharePoint and wanted to demo some of the &lt;a href="http://www.ssblueprints.net/sharepoint/"&gt;Silverlight
Blueprints for SharePoint&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Naturally I hit a few issues along the way so I thought I'd pass a few tips on. 
&lt;/p&gt;
&lt;p&gt;
A major requirement is to have .Net 3.5 and AJAX running on your SharePoint site.
If you configure AJAX by hand as I did check this &lt;a href="http://msdn2.microsoft.com/en-us/library/bb861898.aspx"&gt;MSDN
article&lt;/a&gt;&amp;nbsp;for configuring AJAX but use 3.5.0.0 as the version number. 
&lt;/p&gt;
&lt;p&gt;
I configured AJAX by hand but there is also a &lt;a href="http://www.codeplex.com/features " temp_href="http://www.codeplex.com/features "&gt;CodePlex
feature&lt;/a&gt; that can install AJAX on all your WFE.
&lt;/p&gt;
&lt;p&gt;
It will also help to have Visual Studio 2008 and the Silverlight SDk installed on
your dev box.
&lt;/p&gt;
&lt;p&gt;
The first issue is that none of the XAP's as shipped will work on my machine. You'll
get an error like this
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://blogs.flexnetconsult.co.uk/colinbyrne/content/binary/SL Controls Error 2.JPG" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
checking the XAP files shows the shipped one has this as the first line of the manifest.
&lt;/p&gt;
&lt;p&gt;
&amp;lt;Deployment xmlns="&lt;a href="http://schemas.microsoft.com/client/2007/deployment"&gt;http://schemas.microsoft.com/client/2007/deployment&lt;/a&gt;"
xmlns:x="&lt;a href="http://schemas.microsoft.com/winfx/2006/xaml"&gt;http://schemas.microsoft.com/winfx/2006/xaml&lt;/a&gt;"
EntryPointAssembly="SL.XAML.Navigation" EntryPointType="SL.XAML.Navigation.App"&amp;gt;
&lt;/p&gt;
&lt;p&gt;
but if I recompile the source I get 
&lt;/p&gt;
&lt;p&gt;
&amp;lt;Deployment xmlns="&lt;a href="http://schemas.microsoft.com/client/2007/deployment"&gt;http://schemas.microsoft.com/client/2007/deployment&lt;/a&gt;"
xmlns:x="&lt;a href="http://schemas.microsoft.com/winfx/2006/xaml"&gt;http://schemas.microsoft.com/winfx/2006/xaml&lt;/a&gt;"
EntryPointAssembly="SL.XAML.Navigation" EntryPointType="SL.XAML.Navigation.App" RuntimeVersion="2.0.30226.2"&amp;gt;
&lt;/p&gt;
&lt;p&gt;
The missing RuntimeVersion seems the key here, looks like the U2U folks were running
a slightly different build of chiron the XAP compiler and certainly the Silverlight
2 runtime on my machine wont run a XAP without it.
&lt;/p&gt;
&lt;p&gt;
So the fix is to recompile the Silverlight Applications and redeploy the XAP to the
ClientBin directory in your&amp;nbsp;IIS website directory.
&lt;/p&gt;
&lt;p&gt;
Second and more bizarre is the Navigation Sample. If you try to run it you get an
error about being unable to load the Assembly. 
&lt;/p&gt;
&lt;p&gt;
The problem here is that the PublicKey for the SL.Controls.Navigation.Dll is wrong
in the MasterPage.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://blogs.flexnetconsult.co.uk/colinbyrne/content/binary/SL Controls Error.GIF" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
The MasterPage has 4aec304184eb9a69 when the DLL has bb99f30c0098259c. 
&lt;/p&gt;
&lt;p&gt;
The Fix is to change the MasterPage Register TagPrefix line to bb99f30c0098259c.&amp;nbsp;You
can use SharePoint Designer or&amp;nbsp;uninstall the feature&amp;nbsp;change it and then
reinstall, reactivate.
&lt;/p&gt;
&lt;p&gt;
This will happen when you dev with an internal snk file which has your company private
keys in it and then decide you've got to change it before you ship. I've done exactly
the same thing myself, it really helps to test it on a single machine outside your
company first.
&lt;/p&gt;
&lt;p&gt;
And IT LIVES
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://blogs.flexnetconsult.co.uk/colinbyrne/content/binary/SSNavDemo.gif" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blogs.flexnetconsult.co.uk/colinbyrne/aggbug.ashx?id=f1be83c7-0b1e-4704-9df3-31a306868451" /&gt;</description>
      <comments>http://blogs.flexnetconsult.co.uk/colinbyrne/CommentView,guid,f1be83c7-0b1e-4704-9df3-31a306868451.aspx</comments>
      <category>AJAX</category>
      <category>Bugs</category>
      <category>Sharepoint 2007</category>
      <category>Silverlight</category>
      <category>WebParts</category>
    </item>
    <item>
      <trackback:ping>http://blogs.flexnetconsult.co.uk/colinbyrne/Trackback.aspx?guid=67e085b5-e328-4b3c-b814-9db550b99d82</trackback:ping>
      <pingback:server>http://blogs.flexnetconsult.co.uk/colinbyrne/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.flexnetconsult.co.uk/colinbyrne/PermaLink,guid,67e085b5-e328-4b3c-b814-9db550b99d82.aspx</pingback:target>
      <dc:creator>Colin Byrne</dc:creator>
      <wfw:comment>http://blogs.flexnetconsult.co.uk/colinbyrne/CommentView,guid,67e085b5-e328-4b3c-b814-9db550b99d82.aspx</wfw:comment>
      <wfw:commentRss>http://blogs.flexnetconsult.co.uk/colinbyrne/SyndicationService.asmx/GetEntryCommentsRss?guid=67e085b5-e328-4b3c-b814-9db550b99d82</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Sometimes when working in client-side javascript you'd like to know your Windows username
for instance to add to the root Outlook Web Access URL for say a contacts search
i.e. <a href="http://flexnetowa/exchange/colinb/contacts/?cmd=search">http://flexnetowa/exchange/colinb/contacts/?cmd=search</a> 
</p>
        <p>
Now the stock answer whenever this comes up in the SharePoint newsgroups is: it can't
be done, use server side code to render it out.
</p>
        <p>
Thats fair enough and easy to do, I've created a WebPart that stores a users details
as a JavaScript object so it can be referenced in code. But what if I don't want to
install yet another server-side Web Part. 
</p>
        <p>
In the interests of providing code you won't get anywhere else here's the tip.
</p>
        <p>
Now its true the SharePoint Web Services provide no method to tell you who you are
(side-note: I suspect you may be able to do this by creating a CAML query against
the userinfo table but I've not managed to get that working) but you can get your
username by using the FrontPage RPC and calling author.dll, this is how Word displays
who you are on its TaskPane when you open a Word document in a document library. 
</p>
        <p>
When you call the author.dll ISAPI DLL with the 'open service' method name it returns
a host of information about the server and the services it provides.
</p>
        <p>
I'm using the XmlHttpRequest object again which despite the name can also be used
to retrieve a text document not just an XML one.
</p>
        <p>
heres the returned information
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&lt;html&gt;&lt;head&gt;&lt;title&gt;vermeer
RPC packet&lt;/title&gt;&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;p&gt;method=open service:6.0.2.6356<br />
&lt;p&gt;service=<br />
&lt;ul&gt;<br />
&lt;li&gt;service_name=<br />
&lt;li&gt;meta_info=<br />
&lt;ul&gt;<br />
&lt;li&gt;vti_defaultlanguage<br />
&lt;li&gt;SW|en-us<br />
&lt;li&gt;vti_usernames<br />
&lt;li&gt;VR|<br />
&lt;li&gt;vti_servercharsets<br />
&lt;li&gt;VX|windows-1257 big5 windows-1252 windows-874 utf-8 windows-1251 windows-1256
euc-kr gb2312 windows-1253 windows-1258 koi8-r iso-8859-1 gb18030 iso-2022-jp ks_c_5601-1987
windows-1250 windows-1255 us-ascii euc-jp unicode unicodeFFFE windows-1254 iso-8859-2
iso-8859-15 shift_jis<br />
&lt;li&gt;vti_scnoprompt<br />
&lt;li&gt;IX|1<br />
&lt;li&gt;vti_toolpaneurl<br />
&lt;li&gt;SX|http:<span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//sharepoint.flexnet.ds/_layouts/1033/toolpane.aspx</span><br />
&lt;li&gt;vti_assemblyversion<br />
&lt;li&gt;SX|Microsoft.SharePoint, Version&amp;#61;11.0.0.0, Culture&amp;#61;neutral,
PublicKeyToken&amp;#61;71e9bce111e9429c<br />
&lt;li&gt;vti_webtemplate<br />
&lt;li&gt;IR|1<br />
&lt;li&gt;vti_hasonetlayoutfiles<br />
&lt;li&gt;BR|<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">true</span><br />
&lt;li&gt;vti_navbuttonnextlabel<br />
&lt;li&gt;SR|Next<br />
&lt;li&gt;vti_casesensitiveurls<br />
&lt;li&gt;IX|0<br />
&lt;li&gt;vti_htmlextensions<br />
&lt;li&gt;SX|.html.htm.shtml.shtm.stm.htt.htx.asp.aspx.alx.asa.hta.htc.jsp.cfm.odc.dwt.php.phtml.php2.php3.php4.<br />
&lt;li&gt;vti_approvallevels<br />
&lt;li&gt;VR|Approved Denied Pending&amp;#92; Review<br />
&lt;li&gt;vti_themedefault<br />
&lt;li&gt;SR|none<br />
&lt;li&gt;vti_welcomenames<br />
&lt;li&gt;VX|<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">default</span>.htm <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">default</span>.aspx<br />
&lt;li&gt;vti_servertz<br />
&lt;li&gt;SX|+0100<br />
&lt;li&gt;vti_adminurl<br />
&lt;li&gt;SX|http:<span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//sharepoint.flexnet.ds/_layouts/1033/settings.aspx</span><br />
&lt;li&gt;vti_showhiddenpages<br />
&lt;li&gt;IW|1<br />
&lt;li&gt;vti_categories<br />
&lt;li&gt;VR|Business Competition Expense&amp;#92; Report Goals/Objectives Ideas In&amp;#92;
Process Miscellaneous Planning Schedule Travel VIP Waiting<br />
&lt;li&gt;vti_featurelist<br />
&lt;li&gt;VX|vti_RulesScript vti_ServerIndexServer vti_TimedDocEvents vti_ServiceMarkUrlDirExec
vti_DocSaveToDB vti_ServiceMarkUrlDirBrowse vti_ACAll vti_ServerODBC vti_ServerASP
vti_ServiceMarkUrlDirScript<br />
&lt;li&gt;vti_hasfulltextsearch<br />
&lt;li&gt;IX|1<br />
&lt;li&gt;vti_defaultcharset<br />
&lt;li&gt;SR|windows-1252<br />
&lt;li&gt;vti_navbuttonuplabel<br />
&lt;li&gt;SR|Up<br />
&lt;li&gt;vti_httpdversion<br />
&lt;li&gt;SX|Microsoft-IIS/6.0<br />
&lt;li&gt;vti_serverlanguages<br />
&lt;li&gt;VX|en-us<br />
&lt;li&gt;vti_sourcecontrolproject<br />
&lt;li&gt;SX|&amp;#60;STS-based Locking&amp;#62;<br />
&lt;li&gt;vti_doclibwebviewenabled<br />
&lt;li&gt;IX|1<br />
&lt;li&gt;vti_extenderversion<br />
&lt;li&gt;SR|6.0.2.6361<br />
&lt;li&gt;vti_ignorekeyboard<br />
&lt;li&gt;IR|0<br />
&lt;li&gt;vti_navbuttonprevlabel<br />
&lt;li&gt;SR|Back<br />
&lt;li&gt;vti_longfilenames<br />
&lt;li&gt;IX|1<br />
&lt;li&gt;vti_sourcecontrolsystem<br />
&lt;li&gt;SX|lw<br />
&lt;li&gt;vti_username<br />
&lt;li&gt;SX|FLEXNET&amp;#92;colinb<br />
&lt;li&gt;vti_navbuttonhomelabel<br />
&lt;li&gt;SR|Home<br />
&lt;li&gt;vti_sourcecontrolcookie<br />
&lt;li&gt;SX|fp_internal<br />
&lt;li&gt;vti_sitecollectionurl<br />
&lt;li&gt;SX|/<br />
&lt;li&gt;vti_language<br />
&lt;li&gt;IR|1033<br />
&lt;/ul&gt;<br />
&lt;/ul&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br /></span>
        </p>
        <p>
 
</p>
        <p>
Notice my windows username is listed against the vti_username item.
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">Using
the XmlHttpRequest object to call author.dll s<span style="FONT-SIZE: 10pt; COLOR: #003300; mso-bidi-font-family: 'Courier New'">ynchronously
(we're going to wait for the call to return)</span></font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">xmlrequest <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"method=open
service:6.0.2.6356&amp;service_name="</span>;<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span> (!xmlhttp)
xmlhttp=GetHTTPObject();<br /><br />
xmlhttp.open(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"POST"</span>, <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"/_vti_bin/_vti_aut/author.dll
"</span>,<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">false</span>); 
<br />
xmlhttp.setRequestHeader(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Content-Type"</span>,<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"application/x-www-form-urlencoded"</span>);<br />
xmlhttp.setRequestHeader(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"X-Vermeer-Content-Type"</span>,<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"application/x-www-form-urlencoded"</span>);<br /><br />
xmlhttp.send(xmlrequest);<br /></span>
        </p>
        <p>
The responseText property on xmlhttp contains the returned document.
</p>
        <p>
The hardest bit is parsing the result to extract the username.
</p>
        <p>
Once that is done I show the username in a DIV element.
</p>
        <p>
So the next time someone asks this question we'll be able to give them some options.
</p>
        <p>
          <a href="http://blogs.flexnetconsult.co.uk/colinbyrne/content/binary/ClientSideUsername.dwp">ClientSideUsername.dwp
(2.92 KB)</a>
        </p>
        <img width="0" height="0" src="http://blogs.flexnetconsult.co.uk/colinbyrne/aggbug.ashx?id=67e085b5-e328-4b3c-b814-9db550b99d82" />
      </body>
      <title>Client Side: Who am I?</title>
      <guid isPermaLink="false">http://blogs.flexnetconsult.co.uk/colinbyrne/PermaLink,guid,67e085b5-e328-4b3c-b814-9db550b99d82.aspx</guid>
      <link>http://blogs.flexnetconsult.co.uk/colinbyrne/2006/04/02/ClientSideWhoAmI.aspx</link>
      <pubDate>Sun, 02 Apr 2006 15:43:59 GMT</pubDate>
      <description>&lt;p&gt;
Sometimes when working in client-side javascript you'd like to know your Windows username
for instance to add to the root Outlook Web Access URL for say&amp;nbsp;a contacts search
i.e. &lt;a href="http://flexnetowa/exchange/colinb/contacts/?cmd=search"&gt;http://flexnetowa/exchange/colinb/contacts/?cmd=search&lt;/a&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Now the stock answer whenever this comes up in the SharePoint newsgroups is: it can't
be done, use server side code to render it out.
&lt;/p&gt;
&lt;p&gt;
Thats fair enough and easy to do, I've created a WebPart that stores a users details
as a JavaScript object so it can be referenced in code. But what if I don't want to
install yet another server-side Web Part. 
&lt;/p&gt;
&lt;p&gt;
In the interests of providing code you won't get anywhere else here's&amp;nbsp;the tip.
&lt;/p&gt;
&lt;p&gt;
Now its true the SharePoint Web Services provide no method to tell you who you are
(side-note: I suspect&amp;nbsp;you may be able to do this by creating a CAML query against
the userinfo table but I've not managed to get that working) but you can get your
username by using the FrontPage RPC and calling author.dll, this is how Word displays
who you are on its TaskPane when you open a Word document in a document library. 
&lt;/p&gt;
&lt;p&gt;
When you call the author.dll ISAPI DLL with the 'open service' method name it returns
a host of information about the server and the services it provides.
&lt;/p&gt;
&lt;p&gt;
I'm using the XmlHttpRequest object again which despite the name can also be used
to retrieve a text document not just an XML one.
&lt;/p&gt;
&lt;p&gt;
heres the returned information
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;vermeer
RPC packet&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;&lt;br&gt;
&amp;lt;body&amp;gt;&lt;br&gt;
&amp;lt;p&amp;gt;method=open service:6.0.2.6356&lt;br&gt;
&amp;lt;p&amp;gt;service=&lt;br&gt;
&amp;lt;ul&amp;gt;&lt;br&gt;
&amp;lt;li&amp;gt;service_name=&lt;br&gt;
&amp;lt;li&amp;gt;meta_info=&lt;br&gt;
&amp;lt;ul&amp;gt;&lt;br&gt;
&amp;lt;li&amp;gt;vti_defaultlanguage&lt;br&gt;
&amp;lt;li&amp;gt;SW|en-us&lt;br&gt;
&amp;lt;li&amp;gt;vti_usernames&lt;br&gt;
&amp;lt;li&amp;gt;VR|&lt;br&gt;
&amp;lt;li&amp;gt;vti_servercharsets&lt;br&gt;
&amp;lt;li&amp;gt;VX|windows-1257 big5 windows-1252 windows-874 utf-8 windows-1251 windows-1256
euc-kr gb2312 windows-1253 windows-1258 koi8-r iso-8859-1 gb18030 iso-2022-jp ks_c_5601-1987
windows-1250 windows-1255 us-ascii euc-jp unicode unicodeFFFE windows-1254 iso-8859-2
iso-8859-15 shift_jis&lt;br&gt;
&amp;lt;li&amp;gt;vti_scnoprompt&lt;br&gt;
&amp;lt;li&amp;gt;IX|1&lt;br&gt;
&amp;lt;li&amp;gt;vti_toolpaneurl&lt;br&gt;
&amp;lt;li&amp;gt;SX|http:&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//sharepoint.flexnet.ds/_layouts/1033/toolpane.aspx&lt;/span&gt;
&lt;br&gt;
&amp;lt;li&amp;gt;vti_assemblyversion&lt;br&gt;
&amp;lt;li&amp;gt;SX|Microsoft.SharePoint, Version&amp;amp;#61;11.0.0.0, Culture&amp;amp;#61;neutral,
PublicKeyToken&amp;amp;#61;71e9bce111e9429c&lt;br&gt;
&amp;lt;li&amp;gt;vti_webtemplate&lt;br&gt;
&amp;lt;li&amp;gt;IR|1&lt;br&gt;
&amp;lt;li&amp;gt;vti_hasonetlayoutfiles&lt;br&gt;
&amp;lt;li&amp;gt;BR|&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;true&lt;/span&gt;
&lt;br&gt;
&amp;lt;li&amp;gt;vti_navbuttonnextlabel&lt;br&gt;
&amp;lt;li&amp;gt;SR|Next&lt;br&gt;
&amp;lt;li&amp;gt;vti_casesensitiveurls&lt;br&gt;
&amp;lt;li&amp;gt;IX|0&lt;br&gt;
&amp;lt;li&amp;gt;vti_htmlextensions&lt;br&gt;
&amp;lt;li&amp;gt;SX|.html.htm.shtml.shtm.stm.htt.htx.asp.aspx.alx.asa.hta.htc.jsp.cfm.odc.dwt.php.phtml.php2.php3.php4.&lt;br&gt;
&amp;lt;li&amp;gt;vti_approvallevels&lt;br&gt;
&amp;lt;li&amp;gt;VR|Approved Denied Pending&amp;amp;#92; Review&lt;br&gt;
&amp;lt;li&amp;gt;vti_themedefault&lt;br&gt;
&amp;lt;li&amp;gt;SR|none&lt;br&gt;
&amp;lt;li&amp;gt;vti_welcomenames&lt;br&gt;
&amp;lt;li&amp;gt;VX|&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;default&lt;/span&gt;.htm &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;default&lt;/span&gt;.aspx&lt;br&gt;
&amp;lt;li&amp;gt;vti_servertz&lt;br&gt;
&amp;lt;li&amp;gt;SX|+0100&lt;br&gt;
&amp;lt;li&amp;gt;vti_adminurl&lt;br&gt;
&amp;lt;li&amp;gt;SX|http:&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//sharepoint.flexnet.ds/_layouts/1033/settings.aspx&lt;/span&gt;
&lt;br&gt;
&amp;lt;li&amp;gt;vti_showhiddenpages&lt;br&gt;
&amp;lt;li&amp;gt;IW|1&lt;br&gt;
&amp;lt;li&amp;gt;vti_categories&lt;br&gt;
&amp;lt;li&amp;gt;VR|Business Competition Expense&amp;amp;#92; Report Goals/Objectives Ideas In&amp;amp;#92;
Process Miscellaneous Planning Schedule Travel VIP Waiting&lt;br&gt;
&amp;lt;li&amp;gt;vti_featurelist&lt;br&gt;
&amp;lt;li&amp;gt;VX|vti_RulesScript vti_ServerIndexServer vti_TimedDocEvents vti_ServiceMarkUrlDirExec
vti_DocSaveToDB vti_ServiceMarkUrlDirBrowse vti_ACAll vti_ServerODBC vti_ServerASP
vti_ServiceMarkUrlDirScript&lt;br&gt;
&amp;lt;li&amp;gt;vti_hasfulltextsearch&lt;br&gt;
&amp;lt;li&amp;gt;IX|1&lt;br&gt;
&amp;lt;li&amp;gt;vti_defaultcharset&lt;br&gt;
&amp;lt;li&amp;gt;SR|windows-1252&lt;br&gt;
&amp;lt;li&amp;gt;vti_navbuttonuplabel&lt;br&gt;
&amp;lt;li&amp;gt;SR|Up&lt;br&gt;
&amp;lt;li&amp;gt;vti_httpdversion&lt;br&gt;
&amp;lt;li&amp;gt;SX|Microsoft-IIS/6.0&lt;br&gt;
&amp;lt;li&amp;gt;vti_serverlanguages&lt;br&gt;
&amp;lt;li&amp;gt;VX|en-us&lt;br&gt;
&amp;lt;li&amp;gt;vti_sourcecontrolproject&lt;br&gt;
&amp;lt;li&amp;gt;SX|&amp;amp;#60;STS-based Locking&amp;amp;#62;&lt;br&gt;
&amp;lt;li&amp;gt;vti_doclibwebviewenabled&lt;br&gt;
&amp;lt;li&amp;gt;IX|1&lt;br&gt;
&amp;lt;li&amp;gt;vti_extenderversion&lt;br&gt;
&amp;lt;li&amp;gt;SR|6.0.2.6361&lt;br&gt;
&amp;lt;li&amp;gt;vti_ignorekeyboard&lt;br&gt;
&amp;lt;li&amp;gt;IR|0&lt;br&gt;
&amp;lt;li&amp;gt;vti_navbuttonprevlabel&lt;br&gt;
&amp;lt;li&amp;gt;SR|Back&lt;br&gt;
&amp;lt;li&amp;gt;vti_longfilenames&lt;br&gt;
&amp;lt;li&amp;gt;IX|1&lt;br&gt;
&amp;lt;li&amp;gt;vti_sourcecontrolsystem&lt;br&gt;
&amp;lt;li&amp;gt;SX|lw&lt;br&gt;
&amp;lt;li&amp;gt;vti_username&lt;br&gt;
&amp;lt;li&amp;gt;SX|FLEXNET&amp;amp;#92;colinb&lt;br&gt;
&amp;lt;li&amp;gt;vti_navbuttonhomelabel&lt;br&gt;
&amp;lt;li&amp;gt;SR|Home&lt;br&gt;
&amp;lt;li&amp;gt;vti_sourcecontrolcookie&lt;br&gt;
&amp;lt;li&amp;gt;SX|fp_internal&lt;br&gt;
&amp;lt;li&amp;gt;vti_sitecollectionurl&lt;br&gt;
&amp;lt;li&amp;gt;SX|/&lt;br&gt;
&amp;lt;li&amp;gt;vti_language&lt;br&gt;
&amp;lt;li&amp;gt;IR|1033&lt;br&gt;
&amp;lt;/ul&amp;gt;&lt;br&gt;
&amp;lt;/ul&amp;gt;&lt;br&gt;
&amp;lt;/body&amp;gt;&lt;br&gt;
&amp;lt;/html&amp;gt;&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Notice my windows username is listed against the vti_username item.
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;Using
the XmlHttpRequest object&amp;nbsp;to call author.dll s&lt;span style="FONT-SIZE: 10pt; COLOR: #003300; mso-bidi-font-family: 'Courier New'"&gt;ynchronously
(we're going to wait for the call to return)&lt;/span&gt;
&lt;/p&gt;
&gt;&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;xmlrequest &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"method=open
service:6.0.2.6356&amp;amp;service_name="&lt;/span&gt;;&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt; (!xmlhttp)
xmlhttp=GetHTTPObject();&lt;br&gt;
&lt;br&gt;
xmlhttp.open(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"POST"&lt;/span&gt;, &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"/_vti_bin/_vti_aut/author.dll
"&lt;/span&gt;,&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;false&lt;/span&gt;); 
&lt;br&gt;
xmlhttp.setRequestHeader(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Content-Type"&lt;/span&gt;,&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"application/x-www-form-urlencoded"&lt;/span&gt;);&lt;br&gt;
xmlhttp.setRequestHeader(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"X-Vermeer-Content-Type"&lt;/span&gt;,&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"application/x-www-form-urlencoded"&lt;/span&gt;);&lt;br&gt;
&lt;br&gt;
xmlhttp.send(xmlrequest);&lt;br&gt;
&lt;/p&gt;
&gt; 
&lt;p&gt;
The responseText property on xmlhttp contains the returned document.
&lt;/p&gt;
&lt;p&gt;
The hardest bit is parsing the result to extract the username.
&lt;/p&gt;
&lt;p&gt;
Once that is done I show the username&amp;nbsp;in&amp;nbsp;a DIV element.
&lt;/p&gt;
&lt;p&gt;
So the next time someone asks this question we'll be able to give them some options.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blogs.flexnetconsult.co.uk/colinbyrne/content/binary/ClientSideUsername.dwp"&gt;ClientSideUsername.dwp
(2.92 KB)&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blogs.flexnetconsult.co.uk/colinbyrne/aggbug.ashx?id=67e085b5-e328-4b3c-b814-9db550b99d82" /&gt;</description>
      <comments>http://blogs.flexnetconsult.co.uk/colinbyrne/CommentView,guid,67e085b5-e328-4b3c-b814-9db550b99d82.aspx</comments>
      <category>AJAX</category>
      <category>SharePoint</category>
    </item>
    <item>
      <trackback:ping>http://blogs.flexnetconsult.co.uk/colinbyrne/Trackback.aspx?guid=0b043e21-c672-4558-a8e5-db526e1799ea</trackback:ping>
      <pingback:server>http://blogs.flexnetconsult.co.uk/colinbyrne/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.flexnetconsult.co.uk/colinbyrne/PermaLink,guid,0b043e21-c672-4558-a8e5-db526e1799ea.aspx</pingback:target>
      <dc:creator>Colin Byrne</dc:creator>
      <wfw:comment>http://blogs.flexnetconsult.co.uk/colinbyrne/CommentView,guid,0b043e21-c672-4558-a8e5-db526e1799ea.aspx</wfw:comment>
      <wfw:commentRss>http://blogs.flexnetconsult.co.uk/colinbyrne/SyndicationService.asmx/GetEntryCommentsRss?guid=0b043e21-c672-4558-a8e5-db526e1799ea</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In <a href="http://blogs.flexnetconsult.co.uk/colinbyrne/PermaLink,guid,932884be-2276-4236-8df4-f360149b5fd1.aspx">part
1</a> we have got to the point where we have called the SharePoint lists.asmx Web
Service and retrieved the list of all Lists on our SharePoint site.<br />
We now need to filter down to only those lists that are based on the links list template,
this is template type 103, we can use an Xpath expression to filter the items. 
<br /></p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Filter for the Links lists items </span>
            <br />
links_lists=ajaxsp_GetSoapResponseItems(xmlhttpLists.responseXML, <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"//sp:List[@ServerTemplate='"</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> ListTemplate <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"']"</span>,
moz_NSResolver1 );</span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          </span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" size="2">We
loop through the list items and use the getAttribute of the XML Dom node to retrieve
the fields we are interested in and concatenate a string of &lt;LI&gt; items which
we then set to the innerHTML property of a DIV element.</font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" size="2">Each
list item on the left is a hyperlink that calls the javascript function GetLinkItems
when clicked.<br />
This function is passed three parameters - the list Guid, list Title and the Default
View URL which normally is the full list of links.</font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">function
GetLinkItems(ListGuid, ListName, ListDefaultView)</span>
        </p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <p>
            <br />
            <font face="Verdana" size="2">To get the list items we need to call the GetListItems
method and pass it the listName parameter.</font>
          </p>
          <font face="Verdana" size="2">
            <p>
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Create SOAP Request</span>
                <br />
xmlrequest <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> SoapPrefix <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> '&lt;GetListItems
xmlns=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"http://schemas.microsoft.com/sharepoint/soap/"</span>&gt;'<br />
xmlrequest <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> xmlrequest <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> '&lt;listName&gt;' <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> ListGuid <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> '&lt;/listName&gt;&lt;/GetListItems&gt;' <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span> SoapPostfix;<br /></span>
            </p>
          </font>
          <p>
            <font face="Verdana" size="2">To send the SOAP request we do the same as before only
this time we set the GetListItems SOAP method</font>
          </p>
          <p>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">xmlhttpItems.open(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"POST"</span>, <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"_vti_bin/Lists.asmx?op=GetListItems
"</span>,<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">true</span>);
xmlhttpItems.setRequestHeader(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Content-Type"</span>,<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"text/xml;
charset=utf-8"</span>); xmlhttpItems.setRequestHeader(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"SOAPAction"</span>,<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"http://schemas.microsoft.com/sharepoint/soap/GetListItems
"</span>); 
<br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Set event handler </span><br />
xmlhttpItems.onreadystatechange=ajaxsp_GetLinkItemsEvent; 
<br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Post request</span><br />
xmlhttpItems.send(xmlrequest);</span>
          </p>
          <p>
            <font face="Verdana" size="2">Our GetLinkItemsEvent parses the XML and formats the
data into a TABLE element with the ms-summarycustombody style to match the theme of
the SharePoint site.<br />
Each hyperlink has the target=”_blank” attribute which causes the links to open in
a new window, my preferred method of opening links. This can easily be changed.</font>
            <br />
            <br />
          </p>
          <p>
            <font face="Verdana" size="2">
              <strong>Creating a new Item Form</strong>
            </font>
          </p>
          <p>
            <font face="Verdana" size="2">Now we have displayed our list of links we need to look
at adding a new item.<br />
In the Web Part after the script blocks I have some HTML that contains a DIV element.
The DIV element has a style that sets its position to be absolute and hidden.<br />
Inside the DIV I’ve create a HTML table that sets the layout of the AddNew form.<br />
To render the URL editing and Notes fields I use the built-in functions provided in
the SharePoint javascript file ows.js to handle input fields on SharePoint forms. 
<br />
The complete list of fields type that can be used are:</font>
          </p>
          <p>
            <font face="Verdana" size="2">DateField<br />
URLField<br />
NumberField<br />
BooleanField<br />
NoteField<br />
RichTextField<br />
TextField<br />
FileNameField<br />
GridChoiceField<br />
ChoiceField</font>
          </p>
          <p>
            <font face="Verdana" size="2">I only need to use the URLField and NoteField type. </font>
          </p>
          <p>
            <br />
            <font face="Verdana" size="2">These functions are called in javascript like this 
<br />
var fld = new URLField(frm,"URL","URL", "","");<br />
fld.fRequired = true;<br />
fld.IMEMode="";fld.BuildUI();</font>
          </p>
          <p>
            <font face="Verdana" size="2">The URLField function takes parameters of a OWSForm,
Internal Field Name, Display Name, Default URL Value , Default Description.<br />
BuildUI takes care of creating the input HTML which is great as it automatically creates
two input fields, one for the URL and one for the description. </font>
          </p>
          <p>
            <font face="Verdana" size="2">I create a NoteField object like this.</font>
          </p>
          <p>
            <font face="Verdana" size="2">fld = new NoteField(frm,"Comments","Notes","");<br />
fld.stNumLines = "6";<br />
fld.IMEMode="";<br />
fld.BuildUI();</font>
          </p>
          <p>
            <font face="Verdana" size="2">The NoteField functions parameters are a OWSForm, Internal
Field Name, Display Name, Default Note Field Value</font>
          </p>
          <p>
            <br />
            <font face="Verdana" size="2">Heres the function prototype for creating a OWSForm
object:<br /></font>
          </p>
          <p>
            <font face="Verdana" size="2">function OWSForm(stName, fUseDHTMLOverride, stPagePath)</font>
          </p>
          <p>
            <font face="Verdana" size="2">Creating the OWSForm is tricky in that it’s easy to
create the OWSForm object in itself but it expects the name of the onpage form used
in the WebPart page postbacks, that’s fine but it overwrites the onsubmit function
which causes problems for any other component like the Web Part settings toolbar that
need to post to the server. The way around this is to pass it a dummy name and then
after the call set the Form name to the genuine article.<br />
The second parameter is fUseDHTMLOverride which is used to force the use of DHTML
when rendering the controls.<br />
stPagePath is used to locate any extra files needed such as the datepicker’s template
htm page.</font>
          </p>
          <p>
            <font face="Verdana" size="2">Heres how its called in code</font>
          </p>
          <font face="Verdana" size="2">
            <p>
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Pass a dummy form name so it does not overwrite the Submit event </span>
                <br />
var _WPQ_frm= <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> OWSForm(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"DummyName"</span> , <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">true</span>, <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"_layouts/"</span>); 
<br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Now assign the proper form name it as it’s needed for the fields to locate their values </span><br />
_WPQ_frm.stName=MSOWebPartPageFormName; 
<br /></span>
            </p>
          </font>
          <p>
            <font face="Verdana" size="2">We use the global variable MSOWebPartPageFormName here
which is defined in ows.js and available on all WebPartPages and gives the name of
the FORM element used for postback. Note we don’t postback ourselves but the OWS Field
elements think that they might.</font>
          </p>
          <p>
            <font face="Verdana" size="2">I’ve laid out the new item form with the Javascript
to create the edit fields embedded in a HTML table. This table is wrapped in a DIV
which is initially hidden. The code to show and center the DIV element is Javascript
101 so I won’t go into details but check the function ajaxsp_DisplayNewForm if you’re
interested.</font>
          </p>
          <p>
            <font face="Verdana" size="2">I want to set focus to the Http edit field so we need
to a reference to the Edit fields. 
<br />
We can use getElementById for this but we need to know the name of the field on the
form.<br />
The key to this is to understand how the OWS form elements name themselves.</font>
          </p>
          <p>
            <font face="Verdana" size="2">Fields are named by the internal function FrmStFieldNameFactory
which does this: 
<br />
return "OWS:" + name + ":" + stPart;<br />
This concatenates OWS with the name of the field and the subfield name. </font>
          </p>
          <p>
            <font face="Verdana" size="2">The URL field type is composed of two sub fields named
URL and Desc. In this case we’re referencing the URL field and the URL subpart of
that field. </font>
          </p>
          <p>
            <font face="Verdana" size="2">So to reference the URL sub part of the URL field we
can use this code.</font>
          </p>
          <p>
            <font face="Verdana" size="2">var fldURL=document.getElementById("OWS:URL:URL"); 
<br />
if (fldURL) fldURL.focus();</font>
          </p>
          <p>
            <font face="Verdana" size="2">
            </font> 
</p>
          <p>
            <font face="Verdana" size="2">
              <strong>Adding a new record via SOAP services</strong>
            </font>
          </p>
          <p>
            <font face="Verdana" size="2">Now that we can get the URL, Description and Notes field
values we use the UpdateListItems method of the Lists.asmx web service to add the
new record. 
<br />
This method takes a CAML string to do adds, updates and deletes. 
<br />
This is an example CAML batch string we send:</font>
          </p>
          <p>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&lt;Batch&gt;<br />
&lt;Method ID='1' Cmd='New'&gt;<br />
&lt;Field Name='URL'&gt;http/www.google.com, Description here <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">-</span> note
comma and space&lt;/Field&gt;<br />
&lt;Field Name='Comments'&gt;My Comment String&lt;/Field&gt;<br />
&lt;Method&gt;<br />
&lt;/Batch&gt;</span>
          </p>
          <p>
            <font face="Verdana" size="2">The ajaxsp_AddListItem routine assembles this string,
places it inside the UpdateListItems SOAP string and sends it to the web service.  
<br />
The ajaxsp_AddListItemEvent handles the returned SOAP string which may include a faultstring
node if the SOAP call fails or an ErrorText node if the new record fails to add in
SharePoint. Once the insert succeeds we hide the new item form and refresh the list. </font>
          </p>
          <p>
            <font face="Verdana" size="2">Thats almost it, there is some extra code where I store
the last displayed list in a cookie so if the page refreshes I can display the list
items again. This cookie is designed to only last for the browser session.</font>
          </p>
          <p>
            <font face="Verdana" size="2">
              <br />
 
</font>
          </p>
          <p>
            <font face="Verdana" size="2">
              <strong>Summary</strong>
            </font>
          </p>
          <p>
            <font face="Verdana" size="2">This has been a deep dive into calling the SharePoint
Web Services from client side javascript but the actual methods involved are pretty
basic and simple to use, most of the complications and extra code come from handling
non IE browsers.</font>
          </p>
          <p>
            <font face="Verdana" size="2">Some of the other ways that Web Services could be used
include adding field by field server-side validation, filling comboboxes from SQL
Server tables, getting unread email counts information from Exchange via WebDav.</font>
            <br />
            <br />
          </p>
          <p>
            <font face="Verdana" size="2">Feel free to download the DWP file and browse the code
for yourselves.
</font>
          </p>
          <p>
          </p>
        </span>
        <a href="http://blogs.flexnetconsult.co.uk/colinbyrne/content/binary/LinksLists.dwp">LinksLists.dwp
(16.2 KB)</a>
        <img width="0" height="0" src="http://blogs.flexnetconsult.co.uk/colinbyrne/aggbug.ashx?id=0b043e21-c672-4558-a8e5-db526e1799ea" />
      </body>
      <title>Cross-Browser AJAX for SharePoint Lists Part 2</title>
      <guid isPermaLink="false">http://blogs.flexnetconsult.co.uk/colinbyrne/PermaLink,guid,0b043e21-c672-4558-a8e5-db526e1799ea.aspx</guid>
      <link>http://blogs.flexnetconsult.co.uk/colinbyrne/2006/04/02/CrossBrowserAJAXForSharePointListsPart2.aspx</link>
      <pubDate>Sun, 02 Apr 2006 14:55:49 GMT</pubDate>
      <description>&lt;p&gt;
In &lt;a href="http://blogs.flexnetconsult.co.uk/colinbyrne/PermaLink,guid,932884be-2276-4236-8df4-f360149b5fd1.aspx"&gt;part
1&lt;/a&gt; we have got to the point where we have called the SharePoint lists.asmx Web
Service and retrieved the list of all Lists on our SharePoint site.&lt;br&gt;
We now need to filter down to only those lists that are based on the links list template,
this is template type 103, we can use an Xpath expression to filter the items. 
&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Filter for the Links lists items &lt;/span&gt;
&lt;br&gt;
links_lists=ajaxsp_GetSoapResponseItems(xmlhttpLists.responseXML, &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"//sp:List[@ServerTemplate='"&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; ListTemplate &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"']"&lt;/span&gt;,
moz_NSResolver1 );&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana size=2&gt;We
loop through the list items and use the getAttribute of the XML Dom node to retrieve
the fields we are interested in and concatenate a string of &amp;lt;LI&amp;gt; items which
we then set to the innerHTML property of a DIV element.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana size=2&gt;Each
list item on the left is a hyperlink that calls the javascript function GetLinkItems
when clicked.&lt;br&gt;
This function is passed three parameters - the list Guid, list Title and the Default
View URL which normally is the full list of links.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;function
GetLinkItems(ListGuid, ListName, ListDefaultView)&lt;/span&gt;
&lt;/p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt; 
&lt;p&gt;
&lt;br&gt;
&lt;font face=Verdana size=2&gt;To get the list items we need to call the GetListItems method
and pass it the listName parameter.&lt;/font&gt;
&lt;/p&gt;
&lt;font face=Verdana size=2&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Create SOAP Request&lt;/span&gt;
&lt;br&gt;
xmlrequest &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; SoapPrefix &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; '&amp;lt;GetListItems
xmlns=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"http://schemas.microsoft.com/sharepoint/soap/"&lt;/span&gt;&amp;gt;'&lt;br&gt;
xmlrequest &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; xmlrequest &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; '&amp;lt;listName&amp;gt;' &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; ListGuid &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; '&amp;lt;/listName&amp;gt;&amp;lt;/GetListItems&amp;gt;' &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; SoapPostfix;&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;/font&gt; 
&lt;p&gt;
&lt;font face=Verdana size=2&gt;To send the SOAP request we do the same as before only this
time we set the GetListItems SOAP method&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;xmlhttpItems.open(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"POST"&lt;/span&gt;, &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"_vti_bin/Lists.asmx?op=GetListItems
"&lt;/span&gt;,&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;true&lt;/span&gt;);
xmlhttpItems.setRequestHeader(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Content-Type"&lt;/span&gt;,&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"text/xml;
charset=utf-8"&lt;/span&gt;); xmlhttpItems.setRequestHeader(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"SOAPAction"&lt;/span&gt;,&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"http://schemas.microsoft.com/sharepoint/soap/GetListItems
"&lt;/span&gt;); 
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Set event handler &lt;/span&gt;
&lt;br&gt;
xmlhttpItems.onreadystatechange=ajaxsp_GetLinkItemsEvent; 
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Post request&lt;/span&gt;
&lt;br&gt;
xmlhttpItems.send(xmlrequest);&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;Our GetLinkItemsEvent parses the XML and formats the data
into a TABLE element with the ms-summarycustombody style to match the theme of the
SharePoint site.&lt;br&gt;
Each hyperlink has the target=”_blank” attribute which causes the links to open in
a new window, my preferred method of opening links. This can easily be changed.&lt;/font&gt;
&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;&lt;strong&gt;Creating a new Item Form&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;Now we have displayed our list of links we need to look
at adding a new item.&lt;br&gt;
In the Web Part after the script blocks I have some HTML that contains a DIV element.
The DIV element has a style that sets its position to be absolute and hidden.&lt;br&gt;
Inside the DIV I’ve create a HTML table that sets the layout of the AddNew form.&lt;br&gt;
To render the URL editing and Notes fields I use the built-in functions provided in
the SharePoint javascript file ows.js to handle input fields on SharePoint forms. 
&lt;br&gt;
The complete list of fields type that can be used are:&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;DateField&lt;br&gt;
URLField&lt;br&gt;
NumberField&lt;br&gt;
BooleanField&lt;br&gt;
NoteField&lt;br&gt;
RichTextField&lt;br&gt;
TextField&lt;br&gt;
FileNameField&lt;br&gt;
GridChoiceField&lt;br&gt;
ChoiceField&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;I only need to use the URLField and NoteField type. &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
&lt;font face=Verdana size=2&gt;These functions are called in javascript like this 
&lt;br&gt;
var fld = new URLField(frm,"URL","URL", "","");&lt;br&gt;
fld.fRequired = true;&lt;br&gt;
fld.IMEMode="";fld.BuildUI();&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;The URLField function takes parameters of a OWSForm, Internal
Field Name, Display Name, Default URL Value , Default Description.&lt;br&gt;
BuildUI takes care of creating the input HTML which is great as it automatically creates
two input fields, one for the URL and one for the description. &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;I create a NoteField object like this.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;fld = new NoteField(frm,"Comments","Notes","");&lt;br&gt;
fld.stNumLines = "6";&lt;br&gt;
fld.IMEMode="";&lt;br&gt;
fld.BuildUI();&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;The NoteField functions parameters are a OWSForm, Internal
Field Name, Display Name, Default Note Field Value&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
&lt;font face=Verdana size=2&gt;Heres the function prototype for creating a OWSForm object:&lt;br&gt;
&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;function OWSForm(stName, fUseDHTMLOverride, stPagePath)&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;Creating the OWSForm is tricky in that it’s easy to create
the OWSForm object in itself but it expects the name of the onpage form used in the
WebPart page postbacks, that’s fine but it overwrites the onsubmit function which
causes problems for any other component like the Web Part settings toolbar that need
to post to the server. The way around this is to pass it a dummy name and then after
the call set the Form name to the genuine article.&lt;br&gt;
The second parameter is fUseDHTMLOverride which is used to force the use of DHTML
when rendering the controls.&lt;br&gt;
stPagePath is used to locate any extra files needed such as the datepicker’s template
htm page.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;Heres how its called in code&lt;/font&gt;
&lt;/p&gt;
&lt;font face=Verdana size=2&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Pass a dummy form name so it does not overwrite the Submit event &lt;/span&gt;
&lt;br&gt;
var _WPQ_frm= &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; OWSForm(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"DummyName"&lt;/span&gt; , &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;true&lt;/span&gt;, &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"_layouts/"&lt;/span&gt;); 
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//
Now assign the proper form name it as it’s needed for the fields to locate their values &lt;/span&gt;
&lt;br&gt;
_WPQ_frm.stName=MSOWebPartPageFormName; 
&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;/font&gt; 
&lt;p&gt;
&lt;font face=Verdana size=2&gt;We use the global variable MSOWebPartPageFormName here which
is defined in ows.js and available on all WebPartPages and gives the name of the FORM
element used for postback. Note we don’t postback ourselves but the OWS Field elements
think that they might.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;I’ve laid out the new item form with the Javascript to create
the edit fields embedded in a HTML table. This table is wrapped in a DIV which is
initially hidden. The code to show and center the DIV element is Javascript 101 so
I won’t go into details but check the function ajaxsp_DisplayNewForm if you’re interested.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;I want to set focus to the Http edit field so we need to
a reference to the Edit fields. 
&lt;br&gt;
We can use getElementById for this but we need to know the name of the field on the
form.&lt;br&gt;
The key to this is to understand how the OWS form elements name themselves.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;Fields are named by the internal function FrmStFieldNameFactory
which does this: 
&lt;br&gt;
return "OWS:" + name + ":" + stPart;&lt;br&gt;
This concatenates OWS with the name of the field and the subfield name. &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;The URL field type is composed of two sub fields named URL
and Desc. In this case we’re referencing the URL field and the URL subpart of that
field. &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;So to reference the URL sub part of the URL field we can
use this code.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;var fldURL=document.getElementById("OWS:URL:URL"); 
&lt;br&gt;
if (fldURL) fldURL.focus();&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;&lt;strong&gt;Adding a new record via SOAP services&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;Now that we can get the URL, Description and Notes field
values we use the UpdateListItems method of the Lists.asmx web service to add the
new record. 
&lt;br&gt;
This method takes a CAML string to do adds, updates and deletes. 
&lt;br&gt;
This is an example CAML batch string we send:&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;lt;Batch&amp;gt;&lt;br&gt;
&amp;lt;Method ID='1' Cmd='New'&amp;gt;&lt;br&gt;
&amp;lt;Field Name='URL'&amp;gt;http/www.google.com, Description here &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;-&lt;/span&gt; note
comma and space&amp;lt;/Field&amp;gt;&lt;br&gt;
&amp;lt;Field Name='Comments'&amp;gt;My Comment String&amp;lt;/Field&amp;gt;&lt;br&gt;
&amp;lt;Method&amp;gt;&lt;br&gt;
&amp;lt;/Batch&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;The ajaxsp_AddListItem routine assembles this string, places
it inside the UpdateListItems SOAP string and sends it to the web service.&amp;nbsp; 
&lt;br&gt;
The ajaxsp_AddListItemEvent handles the returned SOAP string which may include a faultstring
node if the SOAP call fails or an ErrorText node if the new record fails to add in
SharePoint. Once the insert succeeds we hide the new item form and refresh the list. &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;Thats almost it, there is some extra code where I store
the last displayed list in a cookie so if the page refreshes I can display the list
items again. This cookie is designed to only last for the browser session.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;
&lt;br&gt;
&amp;nbsp;
&lt;/p&gt;
&gt; 
&lt;p&gt;
&lt;font face=Verdana size=2&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;This has been a deep dive into calling the SharePoint Web
Services from client side javascript but the actual methods involved are pretty basic
and simple to use, most of the complications and extra code come from handling non
IE browsers.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;Some of the other ways that Web Services could be used include
adding field by field server-side validation, filling comboboxes from SQL Server tables,
getting unread email counts information from Exchange via WebDav.&lt;/font&gt;
&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;Feel free to download the DWP file and browse the code for
yourselves.
&lt;/p&gt;
&lt;p&gt;
&gt;
&lt;/span&gt;&lt;a href="http://blogs.flexnetconsult.co.uk/colinbyrne/content/binary/LinksLists.dwp"&gt;LinksLists.dwp
(16.2 KB)&lt;/a&gt;&gt;
&lt;img width="0" height="0" src="http://blogs.flexnetconsult.co.uk/colinbyrne/aggbug.ashx?id=0b043e21-c672-4558-a8e5-db526e1799ea" /&gt;</description>
      <comments>http://blogs.flexnetconsult.co.uk/colinbyrne/CommentView,guid,0b043e21-c672-4558-a8e5-db526e1799ea.aspx</comments>
      <category>AJAX</category>
      <category>SharePoint</category>
    </item>
  </channel>
</rss>