Gorgo.Live.ToString()

Mariusz, Gorzoch tech Blog

Archive for July 2009

SharePointWarmupJob & (401) Unauthorized.

leave a comment »

Recently I’ve installed SharePointWarmupJob on our production enviroment to improve performance of the first mainpage load and in the same way make early users more happy about our intranet solution. In the past I was using this solution on my dev machine and was quite happy about it. So, this time I decided why not do the same for our users. I’ve downloaded solution, puted on the central admin, added to the solution store and deployed. DONE! … or actually, not exacly. After a while I found strange error message on our central admin server:
 
 
On the beggining I thought that it has something to do with security around "Sharepoint timer service", but soon I found that this is not the issue (account used to host this service has access to the page the job was trying to query). I dig for a while and found the solution here KB 896861. In the nut shell this issue comes from the SP1 for Windows 2003, where Microsoft introduced loopback security check. The feature prevents access to a web application using a fully qualified domain name (FQDN) if an attempt to access it takes place from a machine that hosts that application. The end result is a 401.1 Access Denied from the web server and a logon failure in the event log.
 
As you can see in KB this can be fixed thru two ways:
 
1. Disabling this check (not recomended solution for production servers)
2. Configuring list of the hosts (FDQM) which can be queried from the server. (prefered way of doing this on the server)
 
Details around how to do it, are provided in the KB. After I’ve applied the secound option and restarting IIS admin service – everything went to normal and I didn’t saw the issue anymore.
 
 

Written by Mariusz Gorzoch

29 July 2009 at 19:51

Posted in SharePoint

BizTalk & SQL adapter

leave a comment »

If you want to go for playing with BizTalk Sql adapter and query data from external SQL server, which in addition is in diffrent domain/workgroup then you should have look at the list below, as this can save you quite a lot of time. To go for this setup you need to be aware of few teak-ups:
 
1. Make sure that you have installed all required components fot DTC:
 
 
that is you need :
– Enable network COM+ access
– Enable network DTC access
 
if you don’t have one of those components, then you will faild and believe me BizTalk will not tell you that you need them. So before you go for playing with remote SQL access make sure you have both of them installed on your BizTalk box and on the remote SQL server which you are trying to access
 
2. Security for DTC need to be on the same level
 

to get to this tab, you need to start "dcomcnfg", a then expand "Component Services"->"Computers"->"My computer" and right click on it and choise "properties". This will bring you "Properies" tab, where you need to hit "MSDTC" tab and click "Security configuration". When you get to the presented above screen you need to tweak-it up like the one shown above. Pay special attention to "No authentication required". This is the option witch will let you access DTC on remote SQL server, where you are not in the same domain, where SQL server is. Those setting need to be set in the same way in both machines, that is on BizTalk and on the SQL server you are trying to reach.

If you will not do both of those things you will probably end-up with error message : "New transaction cannot enlist in the specified transaction coordinator

That is all, I hope that I saved your time, 😉
 
links:
usefull tools for tracking DTC problems:

Written by Mariusz Gorzoch

24 July 2009 at 17:03

Posted in BizTalk

Application Definition Designer – BDC Tool

leave a comment »

For quite a long time I was complaining about current BDC for SharePoint as there was luck of tools supporing creation of XML application definition. Good for me as lately I watched quite good TechEd session around "Configuring SharePoint to Search for structured data" (done by Richard Riley) and I was supprised that Microsoft has released a tool to support this process. The tool is called "Application Definition Designer" and in the nutshell it let you create application definition with visual designer. Before you go and start use it you need to install it. This tool can be found under tools directory located in you SDK for SharePoint folder (if you don’t have it, you need to install it first), the exact location in my case was : "C:\Program Files\2007 Office System Developer Resources\Tools\BDC Definition Editor". When you get there, then you should find a file "setup.exe", which you should start and by this install this tool on your machine.
 
After first start, you shoul see this screen:
 
now, to create new application definition file, you need to click on "Add Lob system" icon. This should open for you new screen. Find and click "Connect to Database" (you have also option to connect to WebService). After providing "connection string" and pointing tables/view to import you will get visual representation of you application definition:
 
 
from no on you are ready to go to tweak this deffinition as you like and when you ready, export it, so later on you can import it to thru "SharePoint central administration\Shared services administration":
 
 
This is the tool I was looking for quite a long time and to be honest I was even supprise on the beggining that Microsoft didn’ supply it faster. With use of it, creation of application definition is quite easy task. After playing with it for a while I manage to expose my entire HR database for SharePoint and reuse those data in custom search pages.
 
Some hints during creation of your app definition:
– During import of tables remember to mark some field as the one which will be use as a tittle
– When you import your definition into sharepoint, make sure that the account hosting "SharePoint timer service" has proper rights to you database (in case you use NTML)
– before you go and export you happy "app def" make sure that all methods can be started. This can be check by going under "Entities\<Entity name>\Methods\<Method name>\Instances\<instance name>" and with right button click chose execute. This let you execute particular method (even with parameters) and make sure that it is working. 

Written by Mariusz Gorzoch

21 July 2009 at 22:27

Posted in SharePoint

How to send email with use of PowerShell

leave a comment »

I’m quite sick of looking for this info everytime I need it, so this time I decided to create post about it, so here it is. To send email with use of PowerShell you just need to issue those commands:

$emailFrom = "user@yourdomain.com"
$emailTo = "user@yourdomain.com"
$subject = "your subject"
$body = "your body"
$smtpServer = "your smtp server"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)

this is quite easy and usefull especialy if you need to check if the server where you are installing your app allow you to send emails (for some reasons this functionaliy is quite often blocked inside organizations).

Written by Mariusz Gorzoch

18 July 2009 at 08:46

Posted in Powershell

A word around SharePoint security model

leave a comment »

Today I want to write a word around how I understand SharePoint security model and how to simply check, or build an solution to present list of sites where some particular user has "contribute" rights.
 
In general concept of SharePoint security model can be presented with picture shown below:
 
On the left site, we have the most granule permission which exist in SharePoint and which you cannot see. Those permission are always used when assigning some permission to some user/group (so for example if you assign contribute permission to some user/group, then in reality you assign a group of granular permissions). Going further on the middle you have some permission groups define by SharePoint team. Those permission (like “Full control”, “Design”, “Contribute”, ect..) are nothing else as a groups with gather some granular permission. Till this point, end user has no option to tweak those permission out, so if we build something based on them, we are sure that user will not break it. On the right site you have UI permission object, that is “Users” and “Groups”. Each site owner can tweak-up his site permission by assigning permission on the middle picture (blue background) to individual users or groups (and by groups to users).
 
Ok, so we know the basics now. Let use this knowlage building simple web part to present list of sites where user has "contribute" rights. As you could saw on the picture above "Contribute" right is nothing else like a group of some particular granual permission. Let declare some variable to hold list of those granual permision:
 
        public static SPBasePermissions ContributeRole = (SPBasePermissions.ViewListItems
                | SPBasePermissions.AddListItems
                | SPBasePermissions.EditListItems
                | SPBasePermissions.DeleteListItems
                | SPBasePermissions.OpenItems
                | SPBasePermissions.ViewVersions
                | SPBasePermissions.DeleteVersions
                | SPBasePermissions.ManagePersonalViews
                | SPBasePermissions.ViewFormPages
                | SPBasePermissions.Open
                | SPBasePermissions.ViewPages
                | SPBasePermissions.CreateSSCSite
                | SPBasePermissions.BrowseDirectories
                | SPBasePermissions.BrowseUserInfo
                | SPBasePermissions.AddDelPrivateWebParts
                | SPBasePermissions.UpdatePersonalWebParts
                | SPBasePermissions.UseClientIntegration
                | SPBasePermissions.UseRemoteAPIs
                | SPBasePermissions.CreateAlerts
                | SPBasePermissions.EditMyUserInfo);
 
to generate list of sites where current user has "Contribute" right we just need iterate thru all webs and check if current user has proper rights defined thru "ContributeRole" variable. You can do this like that:
 
  Dictionary<string,string> websToReturn = new Dictionary<string,string>();
  string currentUserLogin = SPContext.Current.Web.CurrentUser.LoginName;
  SPSecurity.RunWithElevatedPrivileges(delegate()
   {
    foreach (SPSite currentSite in SPContext.Current.Site.WebApplication.Sites)
    {
     foreach (SPWeb web in currentSite.AllWebs)
     {
      try
      {
       if (web.DoesUserHavePermissions(currentUserLogin, ContributeRole))
        if (!websToReturn.ContainsKey(web.Url))
         websToReturn.Add(web.Url, web.Title);
      }
      finally
      {
       if (web != null)
        web.Dispose();
      }
     }
    }
 
this peace of code will fill websToReturn dictionary collection with all sites, where our user has "Contribute" rights.

Written by Mariusz Gorzoch

15 July 2009 at 20:23

Posted in SharePoint

Are you ready for SharePoint 2010?

leave a comment »

Hey devs ? are you ready for SharePoint 2010 ? it is comming and it will bring a lot of features we all requesting from a long time ago. Today I watch "Developer sneak peek" about new features inside SharePoint 2010 and Visual Studio 2010 for developers and I need to say that I’m impress. On the end of this year we should see beta version of SharePoint and on the beggining of the next year it should be released as production version. If you have some time I suggest you to watch what do they presented as this is worth a while.
 
 
Here are some things I noted and I’m looking for:
  • Linq for SharePoint. Are you tired of current way of taking data from SharePoint, remembering all those strange names and so, on… 2010 will bring us linqu and at least they are saying it should take a lot of pain. The think which intrest me the most is : "what about performance" ? but as I know it will depend 🙂 and we will have old ways of taking data and new ones.
  • New client object model. New version is going to have more reach client object model witch will let us to run some code on the client machine. Sound briliant ? maybe it is, but I’m just thinking if it willl realy bring something new if someone already know something around javascript and AJAX.
  • new BDC. This is the think I mostly looking for. The current BDC is quite difficult to use and as there is no way to connect it directly under the list I prefer not to use it. The other pain around current BDC is the way how you define the BDC… if you didn’t do it…believe me IT IS PAIN. New Visual studio is going to help us here a lot, as it will have new BDC project with special designers. In addition SharePoint bring new type of list, called "External list" which is created especialy for connecting it to BDC <- and this is the think which I believe is briliant. Just think what you can do ? finally we have a simple way to change the DB engine under the list and build our own one 🙂
  • Improve source control
  • Improve versioning and upgrading of WSP. I hope that it will be done good, as at least in my opinion for now there is no easy way of upgrading your solution. I even something make fun of this and insted of calling it upgrading I’m calling it hotfixing (if you were doing this you should know what I mean).
  • Web part designer for Visual studio. Quite nice that they thought about that and implemented it. This should be helpfull for biggners
  • Improved "solution"/"feature" file generator. As it was shown the new one combine autogeneration of those files with manual input. It should finally solve the problem that when you bring some modyfication to autgenerated solution and feature files and later on Visual Studio replace them with refresing of those fiels.
  • Visual studio "Server explorer" can finally handle SharePoint. If it will work as shown then probably we would have say goodbay to our old fiend "Sharepoint manager"
  • Enhancements to deplyment setup inside visual studio. We should be able to define steps Visual Studio should take after we press F5 button.
  • Developer dashbord. I like this feature as it can help us with performace tracking. In general this should shown us what is happening during rendering of the page on the server. In addition it should include how much time it take to process each of the web part placed on the page. Think about what we can do with this data ? 🙂

in the nutshell : if SharePoint 2010 and Visual Studio 2010 will look on the end like is was shown on this webcast, then it should be so huge step as it was when Microsoft introduced SharePoint 2007 to replace SharePoint 2003.

Written by Mariusz Gorzoch

14 July 2009 at 22:17

Posted in SharePoint

Content query web part enhancements

leave a comment »

This time it gonna be a short story about some improvments you can easy do for "Content query web part" (CQWP). I came across those needs during development I was asked for one application. The requirements was to build a way to present 10 recent modified document by anyone in entire site collection. During this work I stuck with two issues, which I would like to present here. Those issues are:
 
1. Change color of the alternative rows so they will have diffrent color then the normal ones. With little experiances around CQWP you will find out that this can not be done, by simple atributes tweak-up. To do so, you need to go to ItemStyle.xsl and build your own new template. If you need such a functionality try to use this template:
 
 <xsl:template name="AlternateItems" match="Row[@Style=’AlternateItems’]" mode="itemstyle">
  <xsl:param name="CurPos" />
        <xsl:variable name="SafeLinkUrl">
            <xsl:call-template name="OuterTemplate.GetSafeLink">
                <xsl:with-param name="UrlColumnName" select="’LinkUrl’"/>
            </xsl:call-template>
        </xsl:variable> 
        <xsl:variable name="DisplayTitle">
            <xsl:call-template name="OuterTemplate.GetTitle">
                <xsl:with-param name="Title" select="@Title"/>
                <xsl:with-param name="UrlColumnName" select="’LinkUrl’"/>
            </xsl:call-template>
        </xsl:variable>
        <xsl:variable name="LinkTarget">
            <xsl:if test="@OpenInNewWindow = ‘True’" >_blank</xsl:if>
        </xsl:variable>
  <xsl:variable name="BgColor12">          
   <xsl:choose>               
    <xsl:when  test="($CurPos mod 2 = 0)">
     <xsl:value-of select="’white’" />
    </xsl:when>
    <xsl:otherwise>
     <xsl:value-of select="’whitesmoke’" />
    </xsl:otherwise>
   </xsl:choose> 
  </xsl:variable>

        <div id="linkitem" class="item link-item">   
            <xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/>
   <table width="100%" bgColor="{$BgColor12}" cellpadding="0" cellspacing="0">
    <tr>
     <td width="3%"><xsl:value-of select="$CurPos" /></td>
     <td width="6%" align="center"><xsl:value-of select="@CTLawyersDocumentFolderDocNoField"/></td>
     <td align="left">
      <a href="{$SafeLinkUrl}" target="{$LinkTarget}" title="{@LinkToolTip}">
       <xsl:value-of select="$DisplayTitle"/>
      </a>   
     </td> 
    </tr>
   </table>
  </div>
 </xsl:template> 
 
the most importent part is the variable "BgColor12", which is responsible for recalculating if the current row is alternate one or not. In addition, to make this work you need to go to "ContentQueryMain.xsl" file, check it out and find definition of template "OuterTemplate.CallItemTemplate". This template deffinition need to be tweak-up by adding new "when" statement like this one:
 
 <xsl:when test="@Style=AlternateItems">
    <xsl:apply-templates select="." mode="itemstyle">
      <xsl:with-param name="CurPos" select="$CurPosition" />
   </xsl:apply-templates>
 </xsl:when> 
 
This tells to CQWP engine to pass a parameter to our template with the number of current processing row.
After those two changes, please check-in both files. When you check them in, you can go to your "Content query web part" and change the Item style, to be the "AlternativeItems" (this option will pop-up automaticly as we created definition of it in itemstyle.xsl).
 
Done, if you have done everything right, then you should get your list with alternative background colors:
 
 
2. Force "Content query web part" to show link to the document properties, insted of to the document itself. Out of the box, when you ask CQWP to get some items for you, he will provide you the list, where you can find some fields containing URL to the document. The problem is that those links are poiting directly to the document itself and not to the "Properties" of the item. After fighting for a while I found solution for that.
 
First you need to export you web part and add few additional field to be taken by the engine. When you export the web part definition, please open it and change the line containing "CommonViewFields" property to looks like this (by default it should be empty):
 
        <property name="CommonViewFields" type="string">FileRef, Lookup;EncodedAbsUrl,Computed</property>
 
This will couse to retrive additional fields during performing query.
Now, save and upload new definition to the web part galery, so you will have new version of your "Content query web part" (the good idea is also to change name of the web part so you will not override the default one).
 
Next, open "ItemStyle.xsl" and go to out custom "AlternateItems" template. Inside it define new variable:
 
  <xsl:variable name="ViewLink">
   <xsl:value-of select="@EncodedAbsUrl" /><xsl:value-of select="substring-before(substring-after(@FileRef,’#’),’/’)"/><xsl:value-of select="’/Forms/DispForm.aspx?ID=’"/><xsl:value-of select="substring-before(@FileRef,’;’)"/>
  </xsl:variable>
 
and let use it, somewhere in "DIV" section, like so:
 
   <table width="100%" bgColor="{$BgColor12}" cellpadding="0" cellspacing="0">
    <tr>
     <td width="3%"><xsl:value-of select="$CurPos" /></td>
     <td width="6%" align="center"><xsl:value-of select="@CTLawyersDocumentFolderDocNoField"/></td>
     <td align="left">
      <a href="{$ViewLink}" target="{$LinkTarget}" title="{@LinkToolTip}">
       <xsl:value-of select="$DisplayTitle"/>
      </a>   
     </td> 
    </tr>
   </table>
 
Done. Now you need to upload new version of "ItemStyle.xsl" file, check it in, and apply the "AlternateItems" style to you web part (created based on the web part definition uploaded before). If you do so, then from now on, when you click on the document name you will be redirected to the document details page insted to document (attachment) itself.
 
those things also can be really ease done with use of Enhancement content query web part.
 
Usefull resources:
 

Written by Mariusz Gorzoch

13 July 2009 at 16:21

Posted in SharePoint