Write .net against XERO

 

Useful Links:

Steps to Get Started

Follow these steps.

Create SSL Certification

  1. Install Open SSL from link provided above.
  2. Open command prompt (Run as administrator)
  3. Navigate to bin folder of openssl e.g. “C:\OpenSSL-Win32\bin”
  4. Run following lines
openssl genrsa -out privatekey.pem 1024
openssl req -new -x509 -key privatekey.pem -out publickey.cer -days 365
openssl pkcs12 -export -out public_privatekey.pfx -inkey privatekey.pem -in publickey.cer

Copy .pem, .pfx & .cer files into solution for safe keeping. You will need to redo this prcess in 365 days as ssl will expire.

Install XeroAPI.Net into Visual Studio

Install using Package Manager Console – http://www.nuget.org/packages/XeroAPI.Net

Register your Application to Xero

  1. Go to https://api.xero.com/Application/Add
  2. Select public or private
  3. Give application name and upload .cer file
  4. Copy & Save Consumer Key

Write some code

 

  Protected Sub loadClientInvoices()

        Dim session As IOAuthSession = New XeroApi.OAuth.XeroApiPrivateSession("xxxx", "xxxxx", New X509Certificate2(Request.PhysicalApplicationPath + "\openssl\public_privatekey.pfx", "xxxx"))

        Dim repository As New Repository(session)

        Dim invoicesforClient As List(Of XeroApi.Model.Invoice) = (From x In repository.Invoices Where x.Contact.ContactID = New Guid("af5d6305-b5eb-441f-a5fb-8c9ea9c960ce")).ToList

        For Each invoice In invoicesforClient
            Response.Write(invoice.InvoiceNumber + "<BR>")
        Next

    End Sub
Advertisements

HTML5 Input Placeholders – IE6+

Place holders are awesome but were only introduced with HTML5 meaning older browsers don’t support them by default. This is a great table showing browser support for placeholders. The biggest problem is that we need to consider is IE9 and older, fortunately with JQuery we can workaround this problem. This post describes the solution that I use.

Implementation

My solution uses Mathias’ solution on github. See online demo.

Add reference to JQuery (Requires jQuery 1.6+) 

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

Download and add reference to jquery.placeholder.js

<script src="/js/jquery.placeholder.js"></script>

add the following to your form page:

<script>
$(function() {
	$('input, textarea').placeholder();
});
</script>
<style>
input, textarea { color: #000; }
.placeholder { color: #aaa; }
</style>
<input type="text" name="name" placeholder="e.g. John Doe">
<input type="email" name="email" placeholder="e.g. address@example.ext">

notes

  • requires jquery 1.6+. for an older version of this plugin that works under jquery 1.4.2+, see v1.8.7.
  • works in all a-grade browsers, including ie6.
  • automatically checks if the browser natively supports the html5

SharePoint Content Query Web Part (CQWP) Toolset

The CQWP is a fantastic tool built into SharePoint Sever edition which allows an admin to retrieve items from lists within a site collection. What makes it powerful is its out of the box functionality to style the items retrieve using XSLT & CSS. This article provides some common toolsets that use on a common basis.

There are some great blogs around that provide instructions on how to use this web part so Im not going to do that again here. This is simply a cheat sheet when using the CQWP. If you are new to this web part on want to learn the basics I recommend this article by Paul Galvin

CommonViewFields – Types

<property name="CommonViewFields" type="string">InternalColumn1, FieldType; InternalColum2, FieldType;</property>

  • Text
  • Note
  • Number
  • Currency
  • Integer
  • Boolean
  • DateTime
  • Threading
  • Lookup
  • Choice
  • URL
  • Counter
  • DisplayOnly (DisplayOnly field type has no storage of its own)
  • RichHTML
  • Image

Available Fields For Use

To iterate through all of your available fields use the following:

    <xsl:for-each select="@*">
      P:<xsl:value-of select="name()" /><br/>
    </xsl:for-each>

Retrieve Value of Field

    <xsl:value-of select="@Description" />

Force tag to render

An empty html tag will be stripped out if it contains no content. For example if you want to render <div class=”clear”></clear> this would be stripped out. The easiest way I have found to ensure it renders is to use the following:

<xsl:text> </xsl:text>
<div class="clear" ><xsl:text> </xsl:text></div>

Format URL to get Display Text & URL

<a href="{substring-before(@Link1,’,’)}"><xsl:value-of select="substring-after(@Link1,’, ‘)"/></a>

Render a list of Links

 

<xsl:template name="QuickLinks" match="Row[@Style='QuickLinks']" mode="itemstyle">
   <xsl:param name="CurPos" />
   <xsl:param name="Last" />
   <xsl:variable name="tableStart">
      <xsl:if test="$CurPos = 1">
         <![CDATA[
            <ul id="quickLinkList">
            ]]>
      </xsl:if>
   </xsl:variable>
   <xsl:variable name="tableEnd">
      <xsl:if test="$CurPos = $Last">
         <![CDATA[ </ul>  ]]>
      </xsl:if>
   </xsl:variable>
   <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="SafeImageUrl">
      <xsl:call-template name="OuterTemplate.GetSafeStaticUrl">
         <xsl:with-param name="UrlColumnName" select="'ImageUrl'"/>
      </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:value-of select="$tableStart" disable-output-escaping="yes"/>
   <div class="QLitem">
      <div class="link-item">
         <a href="{$SafeLinkUrl}" title="{@LinkToolTip}">
            <xsl:value-of select="$DisplayTitle"/>
         </a>
      </div>
   </div>
   <xsl:value-of select="$tableEnd" disable-output-escaping="yes"/>
</xsl:template>

Bundling and Minification

Fantastic post about ASP.Net bundling & minification by Scott Gu

http://weblogs.asp.net/scottgu/archive/2011/11/27/new-bundling-and-minification-support-asp-net-4-5-series.aspx

Intellisense has stopped working

A great post on stackoverflow.com resolves the issue. Thanks Gordon Bell

http://stackoverflow.com/questions/178846/visual-studio-intellisense-stopped-working

This has resolved issues in the past with Telerik.Web.UI not working or using an older version even after upgrading Telerik using the windows installer.

This configuration section cannot be used at this path….!!??

By default within Windows 7 IIS 7.5 Microsoft has locked down the parent security requiring that you explicitly allow certain functions for them to be overridden by using either the IIS interface or by your apps web.config file.

For example I received the following alert in IIS when my web.config file had “Anonymous Authentication” turned on. This alert is displayed when trying to manage the authentication settings within IIS.

“There was an error while performing this operation”
”Error: This configuration section cannot be used at this path.This happens when the section is locked at a parent level. …”

image

Resolution

  1. Open windows explorer c:\Windows\system32\inetsrv\config\
  2. edit applicationHost.config in notepad
  3. Look through xml and change relevant tags from Deny to Allow

In my case I needed to allow anonymousAuthentication so I changed the following:

<sectionGroup name=”authentication”>
<section name=”anonymousAuthentication” overrideModeDefault=”Deny” />
<section name=”basicAuthentication” overrideModeDefault=”Deny” />
<section name=”clientCertificateMappingAuthentication” overrideModeDefault=”Deny” />
<section name=”digestAuthentication” overrideModeDefault=”Deny” />
<section name=”iisClientCertificateMappingAuthentication” overrideModeDefault=”Deny” />
<section name=”windowsAuthentication” overrideModeDefault=”Deny” />
</sectionGroup>

to:

<sectionGroup name=”authentication”>
<section name=”anonymousAuthentication” overrideModeDefault=”Allow” />
<section name=”basicAuthentication” overrideModeDefault=”Deny” />
<section name=”clientCertificateMappingAuthentication” overrideModeDefault=”Deny” />
<section name=”digestAuthentication” overrideModeDefault=”Deny” />
<section name=”iisClientCertificateMappingAuthentication” overrideModeDefault=”Deny” />
<section name=”windowsAuthentication” overrideModeDefault=”Deny” />
</sectionGroup>

Path to config file: c:\Windows\system32\inetsrv\config\applicationHost.config

Developing SharePoint 2007 Webparts using Visual Studio 2010

Today I had a client that came to me that liked a web part that I had developed and wanted me to install it for them with some slight mods. No problem… Ohh wait, we developed that for SharePoint 2010 using Visual Studio 2010.

I am a huge fan of Visual Studio 2010 and its tight integration with SharePoint 2010 in its ability to quickly create features and write code like its supposed to be written (without the major headache!). Although WSPbuilder was the tool of chose for SP 2007, VS 2010 is now my new favourite weapon. With new functions like creating Visual Web Parts in a couple of clicks, features, deploy & debug with F5,  control over deployment and much more. Its fantastic, well done to Microsoft for making what should be a simple job easy again!

Since the release of SharePoint 2010 I now do a lot my development in SharePoint 2010 even if my client is running on SharePoint 2007. Why? Well because the API’s for SP 2007 & 2010 are very similar, and really haven’t effected much of my development to date. I find it so much easier to development in SP 2010 with Visual Studio 2010 especially when I run Windows 7 64-bit with SharePoint Foundation 2010 installed. Having this setup means that i can deploy directly from my local PC to a SharePoint environment for basic testing. No need to manually create project structure, manifiest files, signing of assembly, building wsps, manually deploying, attach to debug etc. Once I’m all done with development I package it up and deploy the wsp to the Sharepoint 2007 development for thorough testing. Provided I haven’t used any deprecated methods in the API, ill be all sweet. Good thing is if you have used and deprecated methods you wont be able to build solution, so you wont be doubt when deploying to SP 2007.

Problem.

So i presume your reading this because you love the new Visual Studio 2010 but need to develop web parts for SharePoint 2007. Although the interface within Visual Studio doesn’t directly enable you to develop for 2007, it is possible with some minor changes to your project.

So for the purposes of this article I am going create a basic visual web part, something that was difficult to do in SharePoint 2007 development. This process should work for most project types available…

  1. Start New Project, select Visual Web Part
    image
  2. Select – Deploy as a farm solution
    image
  3. Write your custom web part. I have just created a simple web part that contains some text and a button. When the user clicks the button the button text will change.
    image
  4. I now press F5 on the keyboard and Visual Studio will automatically build & deploy my web part to SharePoint 2010.
  5. I confirm it all works by adding the web part to the page. Great! But there is nothing special so far.
    image
  6. Now to get it into SharePoint 2007! First lets try deploying the current wsp as it is…
  7. So we need to package up the solution.
    image
  8. Grab the wsp from the bin folder
  9. Copy to SharePoint 2007 server.
  10. Deploy to 2007 env and we get an error. The error tells us that it found a version number in the manifest that it doesnt understand.
    image “Solution manifest for solution ’48cae4c9-68ba-cccf5a89304′ failed validation, file manifest.xml, line 2, character 110: The ‘SharePointProductVersion’ attribute is not declared.

Solution

After the steps above:

  1. Go back into Visual Studio 2010.
  2. Double click the “Package.package” file
  3. Select “Manifest” down the bottom. Notice where is reads SharePointProductVersion=”14.0” in the xml file.
    image
  4. In the properties panel, clear out 14.0 in the SharePointProductVersion field. This removes the property all together from the manifest file.
    image
  5. We also need to change the assembly reference in the project from Microsoft.SharePoint.dll 14.0 to 12.0.
    To do this you will need to click the show all files icon in the solution explorer panel.  image 

    -Next, delete out Microsoft.SharePoint & delete out Microsoft.SharePoint.Security as these wont be on the SP 2007 environment.-Then you want to add a reference to Microsoft.SharePoint.dll but make sure its the 12.0 version found in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\Microsoft.SharePoint.dll

  6. Because we have built a ‘Visual Web Part’, Visual Studio 2010 automattically adds some imports into the ascx user control file which wont exists in SP 2007. Therefore you need to comment these references out. Obviously if we were doing a coded web part or a event receiver we would not need to do this step.Mine currently looks like this.
    image
  7. Package up your solution again and deploy on SP 2007 environment.
    image
  8. Active, test and your good to go.
    SharePoint 2007 webpart

Notes:

  • You will need Asp.Net 3.5 installed on your SharePoint 2007 environment.
  • This may not always be the right solution for you (depending on your project) but it certainly saves me a lot of time for those basic web parts.