czwartek, 10 kwietnia 2014

Visual Studion: Install to GAC on Post Build event

In Visual Studio 2012:
"$(FrameworkSDKDir)bin\NETFX 4.0 Tools\gacutil.exe" /i "$(TargetPath)" /f

In Visual Studio 2010:
"$(FrameworkSDKDir)bin\gacutil.exe" /i "$(TargetPath)" /f

Change rendering of the List using XSL

I have a list definition in Visual Studio. Now I want to modify the rendering of the list views using XSL.
First I point my custom xsl file in the XslLink attribute in the list Schema.xml file:

<XslLink Default="TRUE">CustomLibrary.xsl</XslLink>

MailType is a custom column of type Choice and has the following options to choose: In, Out, Other.
I’d like to change two things:
  •  the way its values are displayed in the ListView: show icons instead of text
  • the column header of the ListView: instead of the default DisplayName, I want custom text “In/Out”


Here is the XSL file:

<xsl:stylesheet
       xmlns:x="http://www.w3.org/2001/XMLSchema"
       xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt"
       xmlns:asp="http://schemas.microsoft.com/ASPNET/20"
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       xmlns:msxsl="urn:schemas-microsoft-com:xslt"
       xmlns:SharePoint="Microsoft.SharePoint.WebControls"
       xmlns:ddwrt2="urn:frontpage:internal"
       xmlns:o="urn:schemas-microsoft-com:office:office">

<xsl:include href="/_layouts/xsl/main.xsl"/>
       <xsl:include href="/_layouts/xsl/internal.xsl"/>

       <xsl:template name="FieldRef_header.MailType" match="FieldRef[@Name='MailType']" mode="header">
             <th nowrap="nowrap" scope="col" onmouseover="OnChildColumn(this)">
                    <xsl:attribute name="class">ms-vh2</xsl:attribute>
                    <xsl:call-template name="dvt_headerfield">
                           <xsl:with-param name="fieldname">
                                  <xsl:value-of select="@Name"/>
                           </xsl:with-param>
                           <xsl:with-param name="fieldtitle">
                                  <xsl:value-of select="'In/Out'"/>
                           </xsl:with-param>
                           <xsl:with-param name="displayname">
                                  <xsl:value-of select="@DisplayName"/>
                           </xsl:with-param>
                           <xsl:with-param name="fieldtype">x:string</xsl:with-param>
                    </xsl:call-template>
             </th>
       </xsl:template>


<xsl:template name="FieldRef_body.MailType" match="FieldRef[@Name='MailType']" mode="body">
             <xsl:param name="thisNode" select="."/>
             <xsl:choose>
                    <xsl:when test="$thisNode/@*[name()=current()/@Name] = 'In'">
                           <img src="/_layouts/images/gbwwain.png" alt="Typ: {$thisNode/@MailType}" title="{$thisNode/@MailType}" />
                    </xsl:when>
                    <xsl:when test="$thisNode/@*[name()=current()/@Name] = 'Out'">
                           <img src="/_layouts/images/gbwwaoof.png" alt="Typ: {$thisNode/@MailType}" title="{$thisNode/@MailType}" />
                    </xsl:when>
                    <xsl:when test="$thisNode/@*[name()=current()/@Name] = 'Other'">
                           <img src="/_layouts/images/generaldocument.gif" alt="Typ: {$thisNode/@MailType}" title="{$thisNode/@MailType}" />
                    </xsl:when>
                    <xsl:otherwise>
                           <span></span>
                    </xsl:otherwise>
             </xsl:choose>
       </xsl:template>
</xsl:stylesheet>

The above file needs to be deployed to the {SharePointRoot}\Template\Layouts\XSL\ folder.

Problem during deployment of BDC Model

First thing to check is Feature1.Template.xml. Chances are it lacks SiteUrl property. Here is example of correct xml code:
<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/">
  <Properties>
    <Property Key='SiteUrl' Value='http://...'/>
  </Properties>
</Feature>

How to hide Ribbon items

The Ribbon on the SharePoint Forms supports customization of the default tabs, groups, and controls.
In order to customize Ribbon item, you need to know the specific identifier (ID).
The IDs can be found in the CMDUI.xml file in the …\14\TEMPLATE\GLOBAL\XML directory or you can see them here: http://msdn.microsoft.com/en-us/library/ee537543.aspx
Here is the example of how to hide some ribbon items in the form’s code-behind:
protected void Page_Load(object sender, EventArgs e)
{
  SPRibbon rib = SPRibbon.GetCurrent(this);
  if (rib != null)
  {
    rib.TrimById("Ribbon.ListForm.Edit.Actions.DeleteItem");
    rib.TrimById("Ribbon.ListForm.Edit.Actions.EditSeries");
    rib.TrimById("Ribbon.ListForm.Edit.Actions.ClaimReleaseTask");
    rib.TrimById("Ribbon.ListForm.Edit.Actions.DistributionListsApproval");       
  }
}