Sharepoint and .resx files with workflow task form

Bonjour,

I just figured how to use a resx file in my workflow aspx task form.

I needed to style my aspx task form with XSLT and I just hard coded it in the page knowing that I would come back to it and put it into a resource file.

NOTE: the resx files are in the following location on your sharepoint server:
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\Resources

When I tried this it was not easy.

I tried many things but then stumbled upon the SPUtility.GetLocalizedString code.

Orginally this would not work as I was trying to embed an XSLT file inside the resx file and both are XML so it was gettign confused. I then replaced all the < + > tags with &lt; + &gt; but only in the XSLT part of the resx file (the red bit below)


Then in my c# code I do the following:
string theApproversXSLT = SPUtility.GetLocalizedString( "$Resources:Approvers", "Acres", SPContext.Current.Web.Language );

Approvers is the name you can see in the resx file and Acres is the name of my file: Acres.resx.

You can use this also for language options but as you can see I just used the current:
SPContext.Current.Web.Language

So here is my resx file:


<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema

Version 2.0

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>

There are any number of "resheader" rows that contain simple
name/value pairs.

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="Approvers" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value><?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:template match="/">
<table border="0">
<tr>
<td class="ms-formlabel">Name</td>
<td class="ms-formlabel">Role Type</td>
<td class="ms-formlabel">Seq</td>
<td class="ms-formlabel">Action Type</td>
<td class="ms-formlabel">Email</td>
</tr>
<xsl:for-each select="BusinessCaseContentType/Approvers/Data_ApprovalChainMember_Contract">
<xsl:choose>
<xsl:when test="IsCurrentInWorkflowChain = 'true'">
<tr>
<td class="ms-formbody">
<xsl:value-of select="FirstName"/>.<xsl:value-of select="LastName"/>
</td>
<td class="ms-formbody">
<xsl:value-of select="AuthorityRoleType"/>
</td>
<td class="ms-formbody">
<xsl:value-of select="ResourceSeqNumber"/>
</td>
<td class="ms-formbody">
<xsl:value-of select="AuthorityActionType"/>
</td>
<td class="ms-formbody">
<xsl:value-of select="Email"/>
</td>
</tr>
</xsl:when>
<xsl:otherwise>
<tr>
<td style="background-color:#eeeeee;color:#999999;" class="ms-formbody">
<xsl:value-of select="FirstName"/>.<xsl:value-of select="LastName"/>
</td>
<td style="background-color:#eeeeee;color:#999999;" class="ms-formbody">
<xsl:value-of select="AuthorityRoleType"/>
</td>
<td style="background-color:#eeeeee;color:#999999;" class="ms-formbody">
<xsl:value-of select="ResourceSeqNumber"/>
</td>
<td style="background-color:#eeeeee;color:#999999;" class="ms-formbody">
<xsl:value-of select="AuthorityActionType"/>
</td>
<td style="background-color:#eeeeee;color:#999999;" class="ms-formbody">
<xsl:value-of select="Email"/>
</td>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
</value>
</data>
<data name="ExpenditureLines" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:decimal-format name="euro" decimal-separator="," grouping-separator="."/>
<xsl:key name="cowKey" match="ExpenditureLine" use="CowType"/>
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr>
<td class="ms-formlabel">Cow</td>
<td class="ms-formlabel">Amount</td>
</tr>
<xsl:for-each select="//ExpenditureLine[generate-id(.)=generate-id(key('cowKey',CowType))]">
<xsl:sort select="count(key('cowKey',CowType))" order="descending" data-type="text"/>
<tr>
<td colspan="3">
<b>
<xsl:value-of select="CowType"/>
</b>
</td>
</tr>
<xsl:for-each select="key('cowKey',CowType)">
<tr>
<td class="ms-formbody">
<xsl:value-of select="position()"/>.<xsl:value-of select="Cow"/>
</td>
<td class="ms-formbody">
£<xsl:value-of select="format-number(Amount, '#.###,00', 'euro')"/>
</td>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet></value></data>
</root>

Hope this helps someone

RuSs

 

转至http://russellmccloy.blogspot.com/

你可能感兴趣的:(SharePoint)