<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ProgTips &#187; SharePoint</title>
	<atom:link href="http://tips.naivist.net/category/net-pasaule/sharepoint/feed/" rel="self" type="application/rss+xml" />
	<link>http://tips.naivist.net</link>
	<description>Kodējot radušās domeles</description>
	<lastBuildDate>Tue, 19 Jan 2010 14:46:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Restoring the top navigation bar of a SharePoint site</title>
		<link>http://tips.naivist.net/2009/12/01/restoring-the-top-navigation-bar-of-a-sharepoint-site/</link>
		<comments>http://tips.naivist.net/2009/12/01/restoring-the-top-navigation-bar-of-a-sharepoint-site/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 16:14:10 +0000</pubDate>
		<dc:creator>Krišs Rauhvargers</dc:creator>
				<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://tips.naivist.net/?p=149</guid>
		<description><![CDATA[It&#8217;s a known issue that if you delete the &#8220;Top Navigation&#8221; menu through the API in SharePoint 2007, you cannot restore it easily. I came across this problem in one of my development sites. When looking for a solution, I found this article, saying you have to do it through the database. 

The code below [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a known issue that if you delete the &#8220;Top Navigation&#8221; menu through the API in SharePoint 2007, you cannot restore it easily. I came across this problem in one of my development sites. When looking for a solution, I found <a href="http://statto1974.wordpress.com/2008/04/09/beware-of-deleting-global-navigation-nodes-in-spwebnavigationglobalnodes/">this article</a>, saying you have to do it through the database. </p>

<p>The code below solves the problem programmatically (and yes, it changes the database directly). Of course, it&#8217;s an unsupported solution &#8211; if you use it, you may get in trouble with Microsoft official support. 
<pre>
string sSiteUrl = "http://moss/sites/yoursite/";
//after the code gets executed, we have to dispose the 
//spweb object, since the Navigation object of the current SPWeb instance will contain wrong information
using (SPSite oSite = new SPSite(sSiteUrl))
{
    using (SPWeb oWeb = oSite.RootWeb)
    {
        //check if the top navigation bar is already there
        SPNavigationNode oTopnav = null;
        try
        {
            oTopnav = oWeb.Navigation.GetNodeById(1002);
        }
        catch (Exception)
        {
            oTopnav = null;
        }</p>

<pre><code>    if (oTopnav == null)
    {
        //we've found out there is no top navigation bar. Let's create one;

        //we create a temporary navigation node pointing back to web site root
        Microsoft.SharePoint.Navigation.SPNavigationNode oTempNode = new Microsoft.SharePoint.Navigation.SPNavigationNode("Navigation", oWeb.ServerRelativeUrl);
        //we add this node to the "global" collection (where quick launch and top nav bar normally live)
        oWeb.Navigation.GlobalNodes.AddAsLast(oTempNode);

        //now the dirty work - go to the database and change the ID of the navigation node
        System.Data.SqlClient.SqlConnection oConn = new System.Data.SqlClient.SqlConnection(oSite.ContentDatabase.DatabaseConnectionString);
        System.Data.SqlClient.SqlCommand oCmd = new System.Data.SqlClient.SqlCommand();
        oCmd.Connection = oConn;
        oCmd.CommandType = System.Data.CommandType.Text;
        //we only update the node which has the same ID as the one we just created, but, to be completely sure that 
        //nothing else gets changed, we add a requirement to have the same siteid and webid
        oCmd.CommandText = @"UPDATE NavNodes SET Eid=1002 WHERE (Eid=" + oTempNode.Id.ToString() + 
             @") AND (SiteId='" + oSite.ID.ToString("D") + "') AND (WebId='" + oWeb.ID.ToString("D") + "')"; ;
        oConn.Open();
        oCmd.ExecuteNonQuery();
        //closing the connection
        oConn.Dispose();
    }
}
</code></pre>

<p>}    //the oSite object is disposed here
</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://tips.naivist.net/2009/12/01/restoring-the-top-navigation-bar-of-a-sharepoint-site/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;_vti_bin&#8221; folder defined</title>
		<link>http://tips.naivist.net/2009/09/11/vtibin-folder-defined/</link>
		<comments>http://tips.naivist.net/2009/09/11/vtibin-folder-defined/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 11:34:28 +0000</pubDate>
		<dc:creator>Krišs Rauhvargers</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Tīmeklis]]></category>

		<guid isPermaLink="false">http://tips.naivist.net/?p=137</guid>
		<description><![CDATA[Ever wondered why SharePoint &#8220;lists web service&#8221; (i.e., lists.asmx) lives in an interesting address of http://mossserver/sites/somesite/&#95;vti&#95;bin/lists.asmx ?

This is actually not the only place where you can see the magic &#95;vti&#95;something. I remember myself deleting such directories from &#8220;wwwroot&#8221; quite often back in the days &#8220;everyone&#8221; used MS FrontPage. FrontPage used to create the folders &#8220;&#95;vti&#95;bin&#8221;, [...]]]></description>
			<content:encoded><![CDATA[<p>Ever wondered why SharePoint &#8220;lists web service&#8221; (i.e., <em>lists.asmx</em>) lives in an interesting address of http://mossserver/sites/somesite/<strong>&#95;vti&#95;bin</strong>/lists.asmx ?</p>

<p>This is actually not the only place where you can see the magic &#95;vti&#95;<em>something</em>. I remember myself deleting such directories from &#8220;wwwroot&#8221; quite often back in the days &#8220;everyone&#8221; used MS FrontPage. FrontPage used to create the folders &#8220;&#95;vti&#95;bin&#8221;, &#8220;&#95;vti&#95;cnf&#8221; on your computer locally as you developed a website .. and also on the server, if you used &#8220;Frontpage Extensions&#8221; for publishing. The <em>&#95;bin</em> folder would normally contain executables required for FP server components (as far as I understand, something like <em>cgi&#95;bin</em>).</p>

<p>So, even though FP is <a href="http://office.microsoft.com/en-us/frontpage/HA101205221033.aspx">announced dead</a>, guys from the SharePoint team apparently like the idea of puting executables in the <em>&#95;vti&#95;bin</em> folder which was used by FrontPage Extensions. </p>

<p>Anyway, the question is, what does the acronym &#8220;VTI&#8221; mean. Apparently, Microsoft did not develop MS FrontPage from scratch, they <a href="http://www.seoconsultants.com/frontpage/history/">acquired</a> &#8220;<strong>V</strong>ermeer <strong>T</strong>echnologies <strong>I</strong>nc&#8221;. Thus the name of &#8220;bin&#8221; folder in FrontPage. Thus the URL for <em>lists.asmx</em> in SharePoint. </p>
]]></content:encoded>
			<wfw:commentRss>http://tips.naivist.net/2009/09/11/vtibin-folder-defined/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MOSS &amp; custom master pages</title>
		<link>http://tips.naivist.net/2008/08/05/moss-custom-master/</link>
		<comments>http://tips.naivist.net/2008/08/05/moss-custom-master/#comments</comments>
		<pubDate>Tue, 05 Aug 2008 07:19:22 +0000</pubDate>
		<dc:creator>Krišs Rauhvargers</dc:creator>
				<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://tips.naivist.net/?p=128</guid>
		<description><![CDATA[I just found an interesting &#8220;feature&#8221; in MOSS publishing infrastructure. We&#8217;re designing a custom master page for our MOSS portal solution. If I recall correctly, we started with Heather Solomon&#8217;s minimal master page, but I&#8217;m not really sure.

We swiped out all of the built-in styles and layouts to achieve maximum flexibility and stylability of MOSS [...]]]></description>
			<content:encoded><![CDATA[<p>I just found an interesting &#8220;feature&#8221; in MOSS publishing infrastructure. We&#8217;re designing a custom master page for our MOSS portal solution. If I recall correctly, we started with Heather Solomon&#8217;s <em><a href="http://www.heathersolomon.com/blog/archive/2007/01/26/6153.aspx">minimal</a></em> master page, but I&#8217;m not really sure.</p>

<p>We swiped out all of the built-in styles and layouts to achieve maximum flexibility and stylability of MOSS infrastructure. I believe this is the best choice when you have to adapt your portal to custom tailored design layout.</p>

<p>Well, the result was, the portal worked fine with our master page, BUT the content query web part failed. It failed every time we enabled the RSS feed feature. Instead of seeing the actual content, it showed only an error message (in Latvian, since we&#8217;re using the latvian language pack) &#8220;Šo Web daļu nevar parādīt. Lai novērstu problēmu, atveriet šo Web lapu ar Windows SharePoint Services saderīgā HTML redaktorā, piemēram, Microsoft Office SharePoint Designer. Ja problēma netiek novērsta, sazinieties ar Web servera administratoru.&#8221;</p>

<p>No traces could be found in the ULS log nor in the event log of the server. After setting the diagnostic logging of all categories to <em>verbose</em>, finally an exception was written to the logfile:</p>

<pre><code> Error while executing web part: System.Xml.Xsl.XslTransformException: An error occurred during a
 call to extension function 'RegisterFeedUrl'. See InnerException for a complete description of the error. ---&gt; 
 System.Web.HttpException: The control collection cannot be modified during DataBind, 
 Init, Load, PreRender or Unload phases.     at System.Web.UI.ControlCollection.Add(Control 
 child)     at Microsoft.SharePoint.Publishing.WebControls.WebPartRuntime.RegisterFeedUrl(String url, String type)    
 --- End of inner exception stack trace ---     at ....
</code></pre>

<p>When looking at the RegisterFeedUrl in .Net Reflector, we found out that the code actually accesses the <em>Header</em> property of the <em>Page</em> object that is being rendered and adds HtmlLink control to the collection. It gave us a hint that probably there is something wrong with the <em>page</em> and <em>header</em> objects. And &#8211; yes, we had left out the <code>runat="server"</code> part of the HTML and HEAD tags.  So, this is the absolute minimum you must have:</p>

<pre><code>&lt;HTML runat="server"&gt;
    &lt;HEAD runat="server"&gt;
....
</code></pre>

<p>.. and, of course, the name space references and other stuff you usually put in the HTML element tag.</p>
]]></content:encoded>
			<wfw:commentRss>http://tips.naivist.net/2008/08/05/moss-custom-master/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sharepoint &#8211; LOC?</title>
		<link>http://tips.naivist.net/2007/12/20/sharepoint-loc/</link>
		<comments>http://tips.naivist.net/2007/12/20/sharepoint-loc/#comments</comments>
		<pubDate>Thu, 20 Dec 2007 10:43:55 +0000</pubDate>
		<dc:creator>Krišs Rauhvargers</dc:creator>
				<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://tips.naivist.net/2007/12/20/sharepoint-loc/</guid>
		<description><![CDATA[This is rather a question or an idea for a discussion than a regular blog post. 

I&#8217;m  just wondering how does one count LOC in Sharepoint? Or, to be more general, how do you measure the amount of work that has been invested in creating a solution in Sharepoint. 

A solution can consist of [...]]]></description>
			<content:encoded><![CDATA[<p>This is rather a question or an idea for a discussion than a regular blog post. </p>

<p>I&#8217;m  just wondering how does one count LOC in Sharepoint? Or, to be more general, how do you measure the amount of work that has been invested in creating a solution in Sharepoint. </p>

<p>A solution can consist of </p>

<ul>
<li>content type definitions (XML files), </li>
<li>list definitions (XML files again)</li>
<li>feature definitions (XML), </li>
<li>Solution manifests (XML), </li>
<li>CAB file descriptors (&#8220;code&#8221;), </li>
<li>ASPX pages (ASP.net code), </li>
<li>ASPX code-behind files (finally, VB.net, countable!), </li>
<li>Event handlers code (VB.net, cool), </li>
<li>Workflow diagrams (generated VB.net code), </li>
<li>Workflow code-behind files (VB.Net files), </li>
<li>Workflow rules (XML),  </li>
<li>&#8230; and many more things which are not crurrently the case for me;-)</li>
</ul>

<p>So how do you put it all together? In my opinion, a line in feature.xml file has much more value than a table-tr-td line in ASPX page (the former can break &#8220;everything&#8221; in your site while the latter cannot). Some lines in list definitions are valuable, some are not. Should one assign values to LOCs of each file type? 
Seems like LOC is no answer at all. For instance, workflow designer generated code has kind of &#8220;no value&#8221; as a VB.Net code and LOC measurement wouldn&#8217;t tell you much about the effort made to create the particular workflow.</p>
]]></content:encoded>
			<wfw:commentRss>http://tips.naivist.net/2007/12/20/sharepoint-loc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sharepoint Workflow modificēšanas formas izveide ar InfoPath</title>
		<link>http://tips.naivist.net/2007/08/23/sharepoint-workflow-modificesanas-formas-izveide-ar-infopath/</link>
		<comments>http://tips.naivist.net/2007/08/23/sharepoint-workflow-modificesanas-formas-izveide-ar-infopath/#comments</comments>
		<pubDate>Thu, 23 Aug 2007 07:00:53 +0000</pubDate>
		<dc:creator>Krišs Rauhvargers</dc:creator>
				<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://tips.naivist.net/2007/08/23/sharepoint-workflow-modificesanas-formas-izveide-ar-infopath/</guid>
		<description><![CDATA[Iesākumam

Workflow modificēšanas formas jāveido kā InfoPath XSN formas, nevis kā ASPX formas. InfoPath ir dabūjams pilnajā MSOffice paketē, oficiāli tas piederas pie &#8220;Microsoft Office Suites and Applications 2007&#8243; pakas

Pašas formas izveide

Jāveido jauna forma, to veidojot uzreiz vēlams uzstādīt ķeksi &#8220;hide features that do not work in InfoPath Forms Services&#8221; (saucas kaut kā citādi, bet ideja [...]]]></description>
			<content:encoded><![CDATA[<h4>Iesākumam</h4>

<p>Workflow modificēšanas formas jāveido kā InfoPath XSN formas, nevis kā ASPX formas. InfoPath ir dabūjams pilnajā MSOffice paketē, oficiāli tas piederas pie &#8220;Microsoft Office Suites and Applications 2007&#8243; pakas</p>

<h4>Pašas formas izveide</h4>

<p>Jāveido jauna forma, to veidojot uzreiz vēlams uzstādīt ķeksi &#8220;hide features that do not work in InfoPath Forms Services&#8221; (saucas kaut kā citādi, bet ideja ir tā). </p>

<p>Svarīgi ir uzlikt sekojošus atribūtus iekš &#8220;Tools-&gt;Form options&#8221;:</p>

<h5>Browser</h5>

<ul>
<li>Izvācam ķeķšus pie &#8220;Show toolbar at top of form; show toolbar at bottom of form.<br />
Modifikācijas formā šie toolbari nav būtiski, jo formas submitošanai visticamāk izmantosim pogu. Savukārt &#8220;Save&#8221;, &#8220;Update&#8221; utt darbības vispār šeit ir liekas.</li>
</ul>

<h5>Security and trust</h5>

<ul>
<li>Security level: Domain (neļaujam automātiski noteikt)</li>
<li>Security and trust -&gt; Sign this form template. Ja ir administratoru piešķirts sertifikāts, var parakstīt ar to, bet šīm vajadzībām pietiek arī ar &#8220;Create certificate&#8221; (pats priekš sevis izveidos sertifikātu)</li>
</ul>

<h5>Compatibility</h5>

<ul>
<li>Design a form template that can be opened in a browser or InfoPath</li>
</ul>

<p>Datu submitēšanai jāizveido datu konekcija, kas nodos atpakaļ informāciju uz &#8220;hosting environment&#8221; (mūsu gadījumā &#8211; sharepoint workflow-am). To dara zem Tools-&gt;Data Connections. Jāspiež &#8220;Add&#8221;, jāizvēlas &#8220;Create new connection to: Submit data&#8221;. Nākamajā logā &#8211; &#8220;To the hosting environment&#8230;&#8221; un jāiedod konekcijai vārds.</p>

<p>Tai pogai, kas būs kā &#8220;submit&#8221; attiecīgi jāiekonfigurē, ka vai nu: </p>

<ul>
<li>tā ir submit poga &#8211; tad prasīs, pa kuru datu konekciju sazināties ar formu. Tad jāuzstāda, ka pie submitēšanas lietotājam nerāda paziņojumu, ka submits ir veiksmīgs un pēc submitēšanas aizver formu</li>
<li>tā ir parasta poga, kas darbojas uz likumu (rules) pamata. Tad jāizveido likums, kas uzstāda formas vērtības un beigās nosubmitē formu un to aizver</li>
</ul>

<p>Formas datu shēmai būtu vēlams iedot sakarīgu nosaukumu, pēc noklusējuma tas ir &#8220;myFields&#8221; &#8211; ja negribam ar tādu turpmāk strādāt, jāpārsauc un jāizveido normāli.</p>

<p>Kad viss gatavs, dodamies File-&gt;Publish. 
  * Izvēlamies &#8220;To a network location&#8221;. Norādām vietu uz c:, kur vēlamies formu &#8220;publicēt&#8221;, norādām formas nosaukumu vai, ja apmierina piedāvātais, atstājam to pašu.
  * Pēc tam wizardā ir jautājums &#8220;If all form users can access the location that you entered in the previous step, Click next&#8221;. Šeit ir svarīgi atstāt to teksta lauku TUKŠU, citādi forma nestrādās worklfowā! 
  * Izmetīs warningu, ka tas var būt slikti &#8211; spiežam OK.</p>

<p>Paņemam File-&gt;Properties un apskatāmies/nokopējam automātiski noģenerēto &#8220;ID&#8221; lauka vērtību, kas izskatās apmēram kā &#8220;urn:schemas-microsoft-com:office:infopath:ReviewModForm:-myXSD-2007-08-22T06-32-52&#8243;</p>

<h4>Formas lietošana worklfowā</h4>

<p>Lai formu piesaistītu workflovam, kas aprakstīts kā Sharepoint Feature. </p>

<p>Iekopējam publicēto XSN failu blakus feature.xml failam. Instalējot featuri, šim XSN jānokļūst zem c:\program files&#8230;.\12\template\features\ManaFeature</p>

<h5>Feature.XML:</h5>

<ul>
<li><p>Feature tagā:<br />
svarīgas ir šādas rindas (&lt;Feature&gt; taga iekšpusē, To rezultātā, pie feature aktivizēšanas, izpildīsies kods, kas aktivizē arī workflow-am piesaistītās formas):<br />
<em>ReceiverAssembly=&#8221;Microsoft.Office.Workflow.Feature, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&#8221;
ReceiverClass=&#8221;Microsoft.Office.Workflow.Feature.WorkflowFeatureReceiver&#8221;</em></p></li>
<li><p>ElementManifests tagā:<br />
Visi XSN faili jāpiemin arī ElementManifests tagā. Manā gadījumā bija:<br />
<em>&lt;ElementFile Location=&#8221;ReviewModForm.xsn&#8221;/&gt;</em> </p></li>
<li><p>Properties tagā:<br />
Lai tiktu aktivizētas šīs formas, papildus vēl arī &lt;Properties&gt; tagā jāieliek šāda rinda:<br />
<em>&lt;Property Key=&#8221;RegisterForms&#8221; Value=&#8221;*.xsn&#8221; /&gt;</em></p></li>
</ul>

<h5>Workflow.xml (vai kā nu saucas XMLs, kas apraksta workflowu:</h5>

<ul>
<li><p>Workflow tagā:<br />
Uztādām noklusēto WorkflowModifications:<br />
<em>ModificationUrl=&#8221;&#95;layouts/ModWrkflIP.aspx&#8221;</em></p></li>
<li><p>MetaData tagā:<br />
Jāveido jauns modifikācijas apraksts, kas atsaucas uz formu. Manā gadījumā bija:<br />
&lt;Modification<em>&#95;d03867f5-99f7-469e-94af-7fcefe476a22</em>&#95;FormURN&gt;<br />
<em>urn:schemas-microsoft-com:office:infopath:ReviewModForm:-myXSD-2007-08-22T06-32-52</em><br />
&lt;/Modification<em>&#95;d03867f5-99f7-469e-94af-7fcefe476a22</em>&#95;FormURN&gt;<br />
&lt;Modification<em>&#95;d03867f5-99f7-469e-94af-7fcefe476a22</em>&#95;Name&gt;<br />
Atsaukt saskaņošanu<br />
&lt;/Modification<em>&#95;d03867f5-99f7-469e-94af-7fcefe476a22</em>&#95;Name&gt;  </p></li>
</ul>

<p>Ar slīprakstu atzīmēju tās vietas, kas katram gadījumam ir citādi. Kā redzams, šeit FormURN tagā iekšpusē esošais sakrīt ar to formas ID, kas tika nokopēts InfoPath-ā. 
Jaunu GUID ģenerējam ar GuidGen, UZMANĪGI &#8211; tam guidgen uzģenerēs ar lielajiem burtiem. VisualStudio izmantojot, tas automātiski pārtaisa uz mazajiem burtiem. Tāpēc ērtāk būs arī šeit izmantot ar mazajiem, jo citādi tas netiks atpazīts.</p>

<p>Pašā workflowā, vietā, kur šāda modifikācija ir pieļaujama, jāievieto EnableModification aktivitāte, kurai ModificationID uzstāda uz iepriekšējā solī ģenerēto GUIDu (ar mazajiem burtiem). Pēc tam vēlams ieveitot &#8220;EventHandlingScope&#8221;, kur normālajā zarā veic normālo darbu, bet eventu ķērājā ieliek EventDriven aktivitāti, kas gaida OnWorkflowModified notikumu (šeit atkal sasaiste notiek pēc ModificationID). </p>

<p>Šajā brīdī vēl nekas nestrādās, jo nav izveidota datu apmaiņa starp InfoPath formu un Workflow. No WF puses tā tiek nodrošināta, izmantojot ContextData atribūtu &#8211; tur tiek sagaidīts XMLs kas atbilst InfoPath formas aprakstītajai shēmai. Tieši tādu  pašu ContextData piedāvā arī OnWorkflowModified aktivitāte, tikai šeit saņemam no formas atpakaļ pienākušos datus.</p>

<p>XMLu, protams, var sacerēt pats, bet var arī iegūt automātiski.</p>

<h4>XSD shēmas ģenerēšana</h4>

<p>InfoPath formu atveram dizainēšanas režīmā, izvēlamies tai &#8220;Save as Source files&#8221; un izvēlas, kur saglabās. Izvēlētajā folderī uzradīsies vairāki faili, no kuriem svarīgākais: myschema.xsd &#8211; tas satur mūsu InfoPath formas shēmu.</p>

<p>Pēc tam no šīs shēmas var uzģenerēt VB vai C# klasi, kas &#8220;apkalpo&#8221; šādu shēmu. To darām ar komandrindas rīku &#8220;xsd.exe&#8221;:</p>

<pre><code>  cd c:\manataka
  xsd.exe myschema.xsd /C /o:.\ /L:VB
</code></pre>

<p>Uzģenerējas fails myschema.vb, kurā iekšā klase ar nosaukumu tādu, kā iedevām savam datasetam 1. solī. Manā gadījumā &#8211; <em>ReviewModDataSet</em></p>

<p>Šo klases failu iekļaujam savā projektā. Lai sagatavotu aktivitātei nepieciešamo XML stringu, var lietot šādu koda fragmentu: </p>

<pre><code>        Dim oFormData As New ReviewModDataSet
        Using stream As New IO.MemoryStream
            Dim serializer As New Xml.Serialization.XmlSerializer(GetType(ReviewModDataSet))
            serializer.Serialize(stream, oFormData)
            Me.enableRecall_ContextData = Encoding.UTF8.GetString(stream.GetBuffer())
        End Using
</code></pre>

<p>Ar slīprakstu iezīmēju atribūtu, kurā nepieciešams uzstādīt iegūto XML vērtību.</p>
]]></content:encoded>
			<wfw:commentRss>http://tips.naivist.net/2007/08/23/sharepoint-workflow-modificesanas-formas-izveide-ar-infopath/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sharepoint un yyyy.MM.dd</title>
		<link>http://tips.naivist.net/2007/07/31/114/</link>
		<comments>http://tips.naivist.net/2007/07/31/114/#comments</comments>
		<pubDate>Tue, 31 Jul 2007 19:17:35 +0000</pubDate>
		<dc:creator>Krišs Rauhvargers</dc:creator>
				<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://tips.naivist.net/2007/07/31/114/</guid>
		<description><![CDATA[Kad uzinstalēsiet Sharepoint valodu paku, par kuru rakstīju iepriekšējā ierakstā un gribēsiet, lai &#8220;viss būtu pavisam latviski&#8221;, var gadīties vilties tāpat kā man. 

SPPS ļauj glīti nomainīt gan &#8220;Sort order&#8221;, gan &#8220;Locale&#8221; katram atsevišķam Web vai Site objektam. To dara apmēram šādi. Varam uzstādīt latviešu lokāli un latviešu kārtošanas secību. Rezultātā iegūstam, ka konkrētā vietne [...]]]></description>
			<content:encoded><![CDATA[<p>Kad uzinstalēsiet Sharepoint valodu paku, par kuru rakstīju iepriekšējā ierakstā un gribēsiet, lai &#8220;viss būtu pavisam latviski&#8221;, var gadīties vilties tāpat kā man. </p>

<p>SPPS ļauj glīti nomainīt gan &#8220;Sort order&#8221;, gan &#8220;Locale&#8221; katram atsevišķam Web vai Site objektam. To dara apmēram <a href="http://www.microsoft.com/resources/documentation/wss/2/all/adminguide/en-us/stse17.mspx?mfr=true">šādi</a>. Varam uzstādīt latviešu lokāli un latviešu kārtošanas secību. Rezultātā iegūstam, ka konkrētā vietne tiešām izmanto 1062 lokāli (&amp;H426 vai lv-LV, var saukt dažādi).</p>

<p>Pēc vērtības nomainīšanas, varam, skatot kādu ierakstu, pamanīt: &#8220;Izveidots: 2007.07.31 , 11:30. Autors: TādsUnTāds&#8221;.<br />
Rodas jautājums, kas gan tas par interesantu datuma formātu, kurā sākumā raksta gadu, tad mēnesi un tad datumu (yyyy.MM.dd.) Skolā taču mums ir mācīts izmantot formātu dd.MM.yyyy, tātad šodien es gribētu rakstīt 31.07.2007.</p>

<p>Pēc nelādzīgi plašas izpētes esmu noskaidrojis, ka <em>tā tas ir paredzēts</em>! Microsoft darinātais (bet acīmredzot taču kādas latviešu komisijas ieteiktais) formāts ir tieši tāds.</p>

<p>Neliels VB.Net koda fragments parāda, ka tā ir:</p>

<pre><code>    Dim oLoc As New Globalization.CultureInfo( _ 
                    culture:=1062, _ 
                    useUserOverride:=False)
    Debug.WriteLine(oLoc.Name &amp; ": " &amp; _
                    oLoc.DisplayName &amp; ":" &amp; _
                    oLoc.DateTimeFormat.ShortDatePattern)
</code></pre>

<p>Izejā tiek izdrukāts</p>

<pre><code>   lv-LV: Latvian (Latvia):yyyy.MM.dd.
</code></pre>

<p>Sharepoint to ņem vērā un tieši tā arī parāda datumus. Kāpēc mēs to ikdienā neredzam? Visticamāk, tāpēc, ka vai nu paši vai sistēmu administratori pēc operētājsistēmas instalēšanas esam atvēruši Control Panel un nomainījuši datuma formātu sadaļā &#8220;Regional Settings&#8221;. 
Koda piemērā bija redzams, ka parametrs &#8220;useUserOverride&#8221; tiek nodots kā &#8220;False&#8221;, tātad &#8211; ignorējot lietotāja veiktos pielāgojumus. Protams, savā datorā veicot pārbaudi un šo parametru norādot kā &#8220;True&#8221;, ieraudzīju jau sagaidāmo datuma formātu. </p>

<p>Sharepoint, kas ir servera produkts, nedrīkstētu izmantot atsevišķa lietotāja veiktus pielāgojumus, lai rādītu saturu citiem lietotājiem &#8211; un tā tas arī dara.</p>

<p>Pašlaik diemžēl neredzu labu apkārtceļu. Vienkāršākais ir uzstādīt, ka izmantosim vācu lokāli (1032), bet tad vietās, kur uz ekrāna parādās garais datums, parādīsies &#8220;Diensdag, 31. Juli&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://tips.naivist.net/2007/07/31/114/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Sharepoint runā latviski</title>
		<link>http://tips.naivist.net/2007/07/31/sharepoint-runa-latviski/</link>
		<comments>http://tips.naivist.net/2007/07/31/sharepoint-runa-latviski/#comments</comments>
		<pubDate>Tue, 31 Jul 2007 07:26:29 +0000</pubDate>
		<dc:creator>Krišs Rauhvargers</dc:creator>
				<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://tips.naivist.net/2007/07/31/sharepoint-runa-latviski/</guid>
		<description><![CDATA[Šodien (31.07.2007) ir nopublicēta latviešu valodas paka, kas paredzēta Microsoft Office Sharepoint Server. 
Tā pieejama Microsoft lejupielāžu centrā &#8220;par velti&#8221;, tas ir, licencēšanas noteikumi tie paši vecie. Ļoti ceru, ka tulkojums būs pilnīgs un bez īpaši pamanāmām kļūdām.
Lejupielāde: MOSS2007 valodu paka.

Ja nepieciešama valodu paka &#8220;plikajam&#8221; Windows Sharepoint Services, tā pieejama jau ilgāku laiku.Te gan uzreiz [...]]]></description>
			<content:encoded><![CDATA[<p>Šodien (31.07.2007) ir nopublicēta latviešu valodas paka, kas paredzēta Microsoft Office Sharepoint Server. 
Tā pieejama Microsoft lejupielāžu centrā &#8220;par velti&#8221;, tas ir, licencēšanas noteikumi tie paši vecie. Ļoti ceru, ka tulkojums būs pilnīgs un bez īpaši pamanāmām kļūdām.<br />
Lejupielāde: <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=2447426b-8689-4768-bff0-cbb511599a45&amp;DisplayLang=en">MOSS2007 valodu paka.</a></p>

<p>Ja nepieciešama valodu paka &#8220;plikajam&#8221; Windows Sharepoint Services, tā pieejama jau ilgāku laiku.Te gan uzreiz gribu brīdināt, ka šis latviskojums ir nepilnīgs. Publiskajā daļā redzamie teksti ir nolatviskoti, administrācijas daļā vietām redzami arī angliski teksti, vietām vispār parādās resursu identifikatori (izskatās apmēram kā $Resources:UberAdminLink$).<br />
Lejupielāde: <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=36EE1BF0-652C-4E38-B247-F29B3EEFA048&amp;displaylang=en">WSS 3.0 valodu paka</a>  </p>
]]></content:encoded>
			<wfw:commentRss>http://tips.naivist.net/2007/07/31/sharepoint-runa-latviski/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Sharepoint, MOSS un WSS &#8211; 2007. versija</title>
		<link>http://tips.naivist.net/2006/11/22/sharepoint-moss-un-wss-2007-versija/</link>
		<comments>http://tips.naivist.net/2006/11/22/sharepoint-moss-un-wss-2007-versija/#comments</comments>
		<pubDate>Wed, 22 Nov 2006 21:02:22 +0000</pubDate>
		<dc:creator>Krišs Rauhvargers</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Tīmeklis]]></category>

		<guid isPermaLink="false">http://naivist.net/tips/index.php/2006/11/22/sharepoint-moss-un-wss-2007-versija/</guid>
		<description><![CDATA[Šķiet, esmu viens no retajiem LV, kuram šīs lietas vispār interesē, tomēr pastāstīšu &#8211; lai jau saglabājas nākotnei.

Kopš šī gada sākuma tīmeklī it bieži tiek pieminēts &#8220;jaunais Sharepoint&#8221; &#8211; visvairāk kā apjūsmojoši ieraksti dažādos blogos, cik ērts gan tas būs. Runa ir par Sharepoint 2007, precīzāk, diviem Sharepoint saimes produktiem &#8211; Windows Sharepoint Services (WSS) [...]]]></description>
			<content:encoded><![CDATA[<p>Šķiet, esmu viens no retajiem LV, kuram šīs lietas vispār interesē, tomēr pastāstīšu &#8211; lai jau saglabājas nākotnei.</p>

<p>Kopš šī gada sākuma tīmeklī it bieži tiek pieminēts &#8220;jaunais Sharepoint&#8221; &#8211; visvairāk kā apjūsmojoši ieraksti dažādos blogos, cik ērts gan tas būs. Runa ir par Sharepoint 2007, precīzāk, diviem Sharepoint saimes produktiem &#8211; Windows Sharepoint Services (WSS) 3.0 un Microsoft Office Sharepoint Server (MOSS) 2007. Ar ko tie atšķiras? Apmēram ar to pašu, ar ko Notepad atšķiras no Wordpad &#8211; ar iespēju bagātību. Ja WSS iedomājamies kā skudrupūzni, tad MOSS ir skudrupūznis ar centrālapkuri, četriem skursteņiem un peldbaseinu pagrabā. Vārdu sakot, MOSS ir daudz papildus lietu &#8211; unificēta meklēšanas sistēma, lietotāju individuālie saiti, papildus saitu templeiti, papildus darba plūsmu realizācijas, biznesam svarīgo indikatoru (KPI, key performance indicators) monitorēšana, Excel web servisi utt utt. Vēl viena atšķirība &#8211; WSS ir &#8220;par velti&#8221;, tas ir, kopā ar Windows Server 2003, bet MOSS ir maksas produkts&#8230; un dārgs maksas produkts.</p>

<p>Atpakaļ pie pamatstāsta. Solīja jau kādu laiku, šī gada sākumā iznāca pirmā beta versija, kas bija patiešām ar īstu &#8220;betas&#8221; garšu, šī gada maijā &#8211; otrā Beta, augustā &#8211; Beta2TR versija.
Pagājušajā nedēļā Microsoft <a href="http://www.microsoft.com/presspass/press/2006/nov06/11-062007OfficeRTMPR.mspx">paziņoja par galaversijas iznākšanu</a>, pašlaik jebkuram ir pieejama <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=2e6e5a9c-ebf6-4f7f-8467-f4de6bd6b831&amp;DisplayLang=en">180 dienu trial versija MOSS</a> un, protams, jebkuram Windows Server 2003 īpašniekam &#8211; <a href="http://www.microsoft.com/technet/windowsserver/sharepoint/download.mspx">WSS 3.0 RTW</a>
Instalēšanai būs noderīgs <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=10CC340B-F857-4A14-83F5-25634C3BF043&amp;displaylang=en">.NET Framework 3.0</a>, kas arī tika izziņots pagājušajā nedēļā.</p>

<p>Par jaunumiem šajā versijā. Vēl joprojām Sharepoint kā datu glabātuvi izmanto Microsoft SQL Server, tagad varam lietot gan 2000., gan 2005. versiju. Joprojām tas darbojas kā IIS webservera process (bet, atšķirībā no iepriekšējās versijas, tagad kā normāla ASP.Net aplikācija, nevis ISAPI filtrs). 
Ir krietni uzlabota <a href="http://www.microsoft.com/windowsserver2003/technologies/directory/activedirectory/default.mspx">Active Directory</a> integrācija, tagad varam precīzāk definēt attiecību &#8220;domēna lietotājs:portāla lietotājs&#8221;, piemēram, nosakot, kurus portāla lietotāja atribūtus nolasīt no kuriem domēna lietotāja konta atribūtiem (šī atkal laikam tikai mani interesējoša nianse). </p>

<p>Piekļuves tiesību granularitātes līmenis (ak, svešvārdi&#8230;). 2003. versijā nebija daudz iespēju &#8211; piekļuvi varēja definēt vai nu visam saitam kopā, vai katrai dokumentu bibliotēkai vai sarakstam atsevišķi. Un viss. Jaunajā variantā piekļuves tiesības varam definēt līdz pat ieraksta līmenim, kas ir daudz loģiskāk, ja nepieciešams izveidot koplietošanas dokumentu glabātvi. 
Šī iemesla dēļ gan sanācis tā, ka tiesību administrēšana ir kļuvusi ķēpīgāka. Ja līdz šim šķita, ka normālā prakse būtu &#8211; 
1) Sharepoint saita līmenī sadefinēt loģiskas lietotāju grupas
2) Šīm grupām piešķirt tiesības skatīt to vai citu dokumentu bibliotēku, sarakstu, darīt to vai citu darbību
3) Šajās grupās ievietot cilvēkus vai grupas no domēna
&#8230; tad tagad rodas sajūta, ka &#8220;ai, vai tad nu es šī viena dokumenta dēļ taisīšu speciālu grupu?&#8221;, tātad tiesības tiek izmētātas pa visu saitu.</p>

<p>Audiences (šķiet, šī ir MOSS, nevis WSS iespēja). Katram ierakstam varam norādīt mērķauditoriju (target audiences), t.i., grupas, kam tas varētu būt interesants. Tāpat &#8211; lapā ievietotam webpart-am var norādīt auditoriju. Ja pareizi saprotu, piekļuve šādā veidā netiek aizliegta, bet attiecīgais ieraksts vai webparts tiek aizvākts no to lietotāju acīm, kam tas nebūs vajadzīgs. Un tas ir ērti.</p>

<p>Navigācijas sistēma. Jau noklusētajā shēmā tā ir stipri sakarīga.
1) katram saitam var veidot savu augšējo navigācijas paneli, sastāvošu no atsevišķām cilnēm (tabs). Ir izvēle, vai mantot &#8220;parent&#8221; saita tabus, vai izmantot savējos.
2) stipri labāks &#8216;quick launch&#8217; menu saita kreisajā malā. Ir izvēle, vai nu automātiski ģenerēt no visām dokumentu bibliotēkām un sarakstiem, vai veidot pašam savējo
3) breadcrumbs pasākums, kas parāda vertikālo navigāciju saitu struktūrās. 
Visumā ir sajūta, ka apmaldīties nevarēs.</p>

<p>Darba plūsmu programmēšana. Kopā ar <a href="http://wf.netfx3.com/">Windows Workflow Foundation</a> ir atnākusi iespēja strādāt ar darba plūsmām arī no Sharepoint. Ir sajūta, ka te ir savāktas vienkāršākās un nepieciešamākās lietas no Biztalk Server un palaistas plašākās tautās. Līdz ar to tādi procesi kā dažādu veidu vīzēšana, atsauksmju savākšana, atbilžu sagatavošana un citi darbiņi, ko cilvēki veic nelielās komandās, ir aprakstāmi un programmējami arī šajā vidē.</p>

<p>Multiple lookups. Iepriekšējā Sharepoint versijā sarakstam bija iespējams izveidot lauku, kurš norāda uz cita tajā pašā saitā esoša saraksta konkrētu ierakstu. Piemēram, cilvēku tabulā varētu būt lauks, kas ir norāde uz struktūrvienību sarakstu. Līdz šim nebija iespējams apskatīt situāciju, kad cilvēks strādātu vairākās struktūrvienībās vienlaicīgi. Tagad ir.</p>

<p>Custom field types. Šis ir interesants. Pēc noklusējuma Sharepoint sarakstiem var pievienot laukus ar tipiem kā &#8220;text&#8221;, &#8220;multiline text&#8221;, &#8220;number&#8221;, &#8220;date&#8221;, &#8220;choice&#8221;, &#8220;lookup&#8221;&#8230; tagad varam veidot savus tipus. Nu, kaut vai tas pats iecienītais piemērs ar personas kodu &#8211; zināms teksta formāts, zināms garums. Atliek tikai izstrādāt savu klasi, kas mantota no SPField tipa, izveidot rediģēšanas kontroli savam lauka tipam (Jo Sharepoint taču automātiski ģenerē datu ievades un parādīšanas formas katram sarakstam), varbūt vēl neliela čupiņa koda&#8230; un tam ir jādarbojas. Pagaidām neesmu izmēģinājis, bet jau ticu, ka būs labi.</p>

<p>Wiki un Blog saitu templeiti. Nezinu, pagaidām nešķiet, ka jaunā spēļmantiņa būs tik vērta, cik viņi paši sola. Wiki sintakse ne tuvu nelīdzinās <a href="http://wikipedia.org">wikipedia</a> iespējām, blogi it kā ok, pat komentēt var&#8230; bet kaut kā nav ērti, vismaz ne priekš tiem, kas paši tajos raksta.</p>

<p>Overall &#8211; labais! Uzrakstīšu citreiz vēl, šoreiz jau tā par garu sanāca.</p>
]]></content:encoded>
			<wfw:commentRss>http://tips.naivist.net/2006/11/22/sharepoint-moss-un-wss-2007-versija/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Finding SPListItem by its ID</title>
		<link>http://tips.naivist.net/2005/12/19/finding_splistitem_by_its_id/</link>
		<comments>http://tips.naivist.net/2005/12/19/finding_splistitem_by_its_id/#comments</comments>
		<pubDate>Mon, 19 Dec 2005 17:26:53 +0000</pubDate>
		<dc:creator>Krišs Rauhvargers</dc:creator>
				<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://naivist.net/tips/index.php/2005/12/19/finding-splistitem-by-its-id/</guid>
		<description><![CDATA[I just found out that some operations in my SharePoint application run quite slow when used on lists containing large amounts of listitems. In the particular case it was approximately 2,500 items in the list.

The result is: NEVER use this code construction to find an element by its ID:

oList = oWeb.Lists("LongList")     [...]]]></description>
			<content:encoded><![CDATA[<p>I just found out that some operations in my SharePoint application run quite slow when used on lists containing large amounts of listitems. In the particular case it was approximately 2,500 items in the list.</p>

<p>The result is: NEVER use this code construction to find an element by its ID:</p>

<pre><code>oList = oWeb.Lists("LongList")         'gets the list object
oItem = oList.Items.GetItemById(123)   'finds the element within the list in the list
</code></pre>

<p>You should rather use this one:</p>

<pre><code>oList = oWeb.Lists("LongList")         'gets the list object
oItem = oList.GetItemById(123)         'finds the element within the list in the list
</code></pre>

<p>The big mistake is that accessing the &#8220;Items&#8221; property of the <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/spptsdk/html/tscSPList_SV01013569.asp">SPList</a>  object <code>oList</code> creates an SPQuery object in background to read <strong>all</strong> the items in particular list and then GetItemById() method of the SPListItemCollection (<code>oList.Items</code> is a SPListItemCollection object) runs a loop, looking for an item with ID attribute set to the value <code>123</code>.</p>

<p>However, if you use the second code example the SPList ojbect <code>oList</code> creates an SPQuery object in background to read only <strong>one</strong> object having ID attribute set to 123, i.e.:</p>

<pre><code>&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name="ID"&gt;&lt;/FieldRef&gt;&lt;Value Type="Integer"&gt;123&lt;Value&gt;&lt;/Eq&gt;&lt;/Where&gt;
</code></pre>

<p>and then  returns the element it found.</p>

<p>The same applies to the DeleteItemById() method. I had to work around in a bit different manner:</p>

<pre><code>'oList.Items.DeleteItemById(123) 'this was the original code
oList.GetitemById(123).ListItems.DeleteItemById(123) 'this is the improved code
</code></pre>

<p>As you can see, the improved code first finds the list item by its ID, then accesses the <code>ListItems</code> property (which is again SPListItemCollection) and executes a DeleteItemById() command on the particular collection where the size of the collection is 1. </p>

<p>A really difficult workaround was needed to fix the AddNewItem function where I had code like this:</p>

<pre><code>Dim oNewItem as SPListItem
oNewItem = oList.Items.Add()
</code></pre>

<p>Again, accessing the <code>Items</code> attribute leads to reading all the items in the list. To avoid that, I created a SPQuery object that never returned any elements, then called <code>Add()</code> method on the collection returned by the query.</p>

<pre><code>'reads all items having id=0. Should return no rows
oEmptyQuery.Query = "&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name='ID' /&gt;" &amp; _
        "&lt;Value Type='Counter'&gt;0&lt;/Value&amp;gt;&lt;/Eq&gt;&lt;/Where&gt;"
oItemColl = oList.GetItems(oEmptyQuery)
oNewSPItem = oItemColl.Add()    'adds an item to the empty list
'saves the new item and re-reads it from SharePoint
oNewSPItem.Update()
oNewSPItem = oList.GetItemById(oNewSPItem.ID)
</code></pre>

<p>The two last lines were needed because it seems that the field collection is not geting populated when a query returns no rows. However, my code didn&#8217;t seem to run nice without the last two rows.</p>
]]></content:encoded>
			<wfw:commentRss>http://tips.naivist.net/2005/12/19/finding_splistitem_by_its_id/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>SPUser? SPException!</title>
		<link>http://tips.naivist.net/2005/10/13/spuser_spexception/</link>
		<comments>http://tips.naivist.net/2005/10/13/spuser_spexception/#comments</comments>
		<pubDate>Thu, 13 Oct 2005 08:57:06 +0000</pubDate>
		<dc:creator>Krišs Rauhvargers</dc:creator>
				<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://naivist.net/tips/index.php/2005/10/13/spuser-spexception/</guid>
		<description><![CDATA[Something on SharePoint(TM) again. Either you love it or hate it, you have to work around all the pitfalls anyway.

So we all know that in SharePoint you can allow people and assign them SharePoint roles in two ways: 


creating a &#8220;Sharepoint User&#8221; within the portal and assigning roles to the user,
adding a domain group to [...]]]></description>
			<content:encoded><![CDATA[<p>Something on SharePoint(TM) again. Either you love it or hate it, you have to work around all the pitfalls anyway.</p>

<p>So we all know that in SharePoint you can allow people and assign them SharePoint roles in two ways: </p>

<ul>
<li>creating a &#8220;Sharepoint User&#8221; within the portal and assigning roles to the user,</li>
<li>adding a domain group to users and assigning roles to a particular group.</li>
</ul>

<p>The first case is the easy one. The second is not. <span id="more-96"></span>Say, we add a group &#8220;MyDomainGroup&#8221; to SharePoint users and assign them a specific SharePoint role &#8220;MySharepointRole&#8221;. What happens when a user belonging to the domain group visits your SharePoint site:</p>

<ul>
<li>the user is allowed to open the page, because he belongs to the specific group</li>
<li>the IIS thread runs under the security account of the user because this is the way IIS impersonation works</li>
<li>code in webparts is executed under the security account of the user</li>
</ul>

<p>The interesting thing is that <code>SPControl.GetContextWeb(context).CurrentUser</code> returns a valid SPUser object (even though we know there is no SharePoint Web user profile for him). You can get the LoginName property of the <code>CurrentUser</code> and you get the actual login name (let&#8217;s say, <code>MyDomain\MyUser</code>).<br />
So let&#8217;s try the opposite way &#8211; we know the user name, let&#8217;s find the user: </p>

<pre><code>SPControl.GetContextWeb(context).Users("MyDomain\MyUser")
</code></pre>

<p>This ends up in an SPException, because there is no such a user <code>MyUser</code> in this SharePoint web &#8211; he was only allowed to open this page because he is in the domain group.</p>

<p>OK, I think I should explain the situation a bit more. Of course, if you run all the code in the webpart itself, there is no problem &#8211; just keep using the <code>CurrentUser</code> property and everything should run smoothly. However, due to some particular security considerations I need to run some code under a privileged account. This is why I&#8217;m using a COM+ component that runs under another security account. </p>

<p>For instance, I have a function in the COM+ component that returns an array of role names user belongs to.  Within the function, you have to find the SPSite, SPWeb and SPUser to read the roles. You can do it like this:</p>

<pre><code>Dim oSite as New SPSite("http://server/sites/somesite")
Dim oWeb as SPWeb = oSite.AllWebs(New System.Guid("6CCED9AD-7C38-4FF3-9E69-1B2F43D2BD65"))
</code></pre>

<p>For a regular user, you could read his role list like this:</p>

<pre><code>oUser = oWeb.Users("MyDomain\MyUser")
For Each oRole As SPRole In oUser.Roles
    '... add to the return array
Next
</code></pre>

<p>This does not work for a user belonging to a domain group and not being registered as a local user in the SPWeb. As mentioned above, there is no such user. However, there is a special user &#8220;MyDomain\MyDomainGroup&#8221; registered in the web. So you can do it this way:</p>

<pre><code>For Each oGroup As SPUser In oWeb.Users
    If oGroup.IsDomainGroup() Then 'this is "True" for domain groups, "False" for regular users
        If IsUserMember("MyDomain\MyUser", oGroup.LoginName) Then
            For Each oRole As SPRole In oGroup.Roles
             '... add to the return array
            Next
        End If
    End If
Next
</code></pre>

<p>This should work fine now. Of course, you will do it in the &#8220;Catch&#8221; block after you have tried to find the user in the regular manner.<br />
The only thing we need is a function <code>IsUserMember</code> that tells if a user ir member of a domain group. This is quite another story, covered in another article &#8211; here:  <a href="http://naivist.net/tips/index.php/2005/10/13/user_group_member">Does this user belong to a domain group?</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tips.naivist.net/2005/10/13/spuser_spexception/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>
