HOME ABOUT
I AM HERE
  • Twitter icon
  • Facebook icon
  • Technorati icon
Bookmark and Share

PayPal example project C# ASP.Net

December 1, 2011 13:31 by Aidan

A few weeks ago I spent some time integrating PayPal Express Checkout into http://bookhashtags.com so that I could take payments for the featured book spot.

Whilst PayPal produces a lot of documentation and provides some tools to help generate code these were not always that helpful. For example the code wizard produces code that doesn't build and uses a very old version of the API which means that a lot of the things you can now do according to the documentation just didn't work and it wasn't immediately obvious why.

I have put together a bare bones Visual Studio 2010 project that will give you a quick understanding of the basics of the three Express Checkout calls (SetExpressCheckout, GetExpressCheckoutDetails and DoExpressCheckout) you need to make to get things working.

To get the project to run you will need to set up a PayPal sandbox account here - https://developer.paypal.com

You will need to add your sandbox account username, password and signature in the NVPAPICaller class.

Once that is done just press play, change the default values on the default.aspx page and hit the Pay button.

The example only adds one item and doesn't handle shipping costs. For more information on parameter names etc. see the PayPal Express Checkout Integration pdf

Download the project

 

 


Tags:
Categories: ASP.Net | PayPal
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Simple Linq to XML example

November 30, 2011 14:26 by Aidan

 string xml = "<?xml version='1.0' encoding='utf-8'?><people>"
                + "<person><id>1</id><name>Aidan Garnish</name><company>65hours</company><email>aidan@65hours.com</email></person>"
                + "<person><id>2</id><name>Joe Bloggs</name><company>65hours</company><email>Fred@65hours.com</email></person>"
                + "<person><id>3</id><name>Fred Smith</name><company>Microsoft</company><email>Joe@Microsoft.com</email></person></people>";

           

            XDocument doc = XDocument.Parse(xml);

            //filter by company and return a collection of names as strings
            var query = from person in doc.Descendants("person")
              where (string)person.Element("company") == "65hours"
              select (string)person.Element("name");

            foreach (string name in query)
            {
                Console.WriteLine(name);
            }

 

            //return a collection of objects
            var query2 = from person in doc.Descendants("person")
                    where (string)person.Element("company") == "65hours"
                    select new
                         {
                             id = person.Element("id").Value,
                             name = person.Element("name").Value,
                             email =person.Element("email").Value,
                             company = person.Element("name").Value
                         };
           
            foreach (var obj in query2)
            {
                Console.WriteLine(obj.id + " - " + obj.name);
            }           

            Console.ReadLine();


Tags:
Categories: Linq
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Some simple Linq to Objects examples

November 30, 2011 13:57 by Aidan

Linq to Objects is a really handy way to filter and order lists of objects. The following code is a simple example that shows how to filter and how to order a list by an object property.

//a little bit of object and list set up
            ContractPerson person1 = new ContractPerson()
            {   Name = "Aidan Garnish",
                AccountID = "1",
                Company = "65hours",
                Email = "aidan@65hours.com",
                Role = "SharePoint Consultant" };

            ContractPerson person2 = new ContractPerson()
            {
                Name = "Fred Smith",
                AccountID = "2",
                Company = "65hours",
                Email = "fred@65hours.com",
                Role = "Dynamics Consultant"
            };

            ContractPerson person3 = new ContractPerson()
            {
                Name = "Joe Blogs",
                AccountID = "3",
                Company = "Microsoft",
                Email = "joe@ms.com",
                Role = "Microsoft Consultant"
            };

            List<ContractPerson> people = new List<ContractPerson>();
            people.Add(person1);
            people.Add(person2);
            people.Add(person3);


            //filter list by ContractPerson.Company
            var filteredPeople = from person in people
                        where person.Company == "65hours"
                        select person;
           
            foreach (ContractPerson filterPerson in filteredPeople)
            {
                Console.WriteLine(filterPerson.Name);
            }

            //filter list by people who have a name beginning with A
            var peopleWithNameStartingA = from person in people
                                 where person.Name.StartsWith("A")
                                 select person;

            foreach (ContractPerson filterPerson in peopleWithNameStartingA)
            {
                Console.WriteLine(filterPerson.Name);
            }

            //order the list
            var orderedList = from person in people
                              orderby person.Name ascending
                              select person;

            foreach (ContractPerson filterPerson in orderedList)
            {
                Console.WriteLine(filterPerson.Name);
            }

            Console.ReadLine();


Tags:
Categories: Linq
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Book#Hashtags and PayPal integration

November 5, 2011 12:01 by Aidan

Quite a few people have been asking how they can support http://bookhashtags.com or have their book featured on the home page.

As a result I have combined these two things together and it is now possible for authors or publishers to feature their books on the home page by visiting http://www.bookhashtags.com/getyourbookfeatured

This was achieved using PayPal's Express Checkout API to take payment - I am thinking of writing a blog post on using PayPal Express Checkout with C# ASP.Net so if that would be useful to you please let me know in the comments. Although PayPal has a lot of documentation finding the relevant parts and putting them all together did take quite a bit of time and effort so maybe a blog post on this could save other people some pain?


Tags:
Categories:
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Displaying a Visio 2010 drawing with links in a Page Viewer Web Part

October 4, 2011 13:51 by Aidan

If you have tried saving a Visio 2010 drawing as a web page and then displaying it in a Page Viewer web part in SharePoint then you will know that by default hyperlinks in the drawing will no longer work.

This is because the default output format for Visio 2010 drawings being saved as a web page is XAML. When you save the drawing as a web page a collection of files are generated one of which is called xaml_1.js. Opening the Visio drawing .htm file directly in the browser works as expected and hyperlinks are active. However, if you try to display the Visio drawing inside a Page Viewer web part you will see a JavaScript error that references the xaml_1.js file seemingly because there is conflict with DOM elements that exist in the standard SharePoint page.

I suspect that this didn't receive much attention during testing by Microsoft as the assumption could be that if you are using Visio 2010 you will also be using SharePoint 2010 and Visio Services to display your Visio drawings in the browser.

There is a way to work around this by changing the output format of Visio to VML (Vector Markup Language) instead of XAML. Unless you choose VML the first time you save as a web page then Visio remebers the XAML default and there is no setting in Visio (that I can find!) that allows you to change this default. The only option left is to crack open the registry and go searching for the relevant setting.

Open regedit and go to - HKEY_CURRENT_USER -> Software -> Microsoft -> Office -> 14.0 -> Visio -> Solution -> SaveAsWeb -> Settings then change "priformat" from XAML to VML

Save your Visio drawing as a web page again and this time it will be produced using the VML format which does not include the xaml_1.js file that causes the error and prevents links from working.

When you add the link to a Page Viewer you should now have working links.


Most Common SharePoint Application Development Mistake

July 28, 2011 18:59 by Aidan

SharePoint is a huge product with plenty of opportunities to make mistakes in lots of different ways. The infrastructure could be configured badly, the business may not have clearly defined what they hope to achieve with SharePoint or the information architecture is allowed to sprawl out of control.

Having worked with SharePoint for over 7 years there is one mistake that I see being repeated over and over again when SharePoint is introduced into an organisation.

Imagine the scene, SharePoint has just been installed and in this case the business do have a clear idea of what they expect from SharePoint. The first priority is to move several small legacy systems including some spreadsheets and a couple of Access database applications onto SharePoint.

The justification for this is that moving these apps to the SharePoint platform will make them easier to find and share, they will immediately fall under the SharePoint backup and disaster recovery regimes and using SharePoint as the interface will provide a more consistent user experience across all of these apps. In addition to that the business has heard all about how rapidly small applications can be developed and deployed using SharePoint and are excited to see this process in action.

Back in the IT department the .Net developers have just come back from a weeks intensive training and naturally they want to make a good impression by demonstrating their newly acquired SharePoint knowledge and showing the business what a great platform SharePoint is.

The requirements to migrate several spreadsheet based apps start to roll in and the team begin by putting together a few quick prototypes. The decision is made to move the spreadsheet contents across into SharePoint lists to take advantage of functionality like views and to be able to apply approval workflows to items.

The users of the apps take a look at the protoypes and start to provide feedback. Requests include things like:

  • Can a row be highlighted in red if some field drops below a specific number?
  • Could a link be added to the view item form that takes us straight to a specific view?
  • We don't always really like seeing the Alert Me functionality, can this be hidden for some of the lists but left on for others?

The developers know that technically they can do all of these things and they want to say yes to the business. This is a mistake.

It is a mistake for a couple of reasons. The business has been promised rapid application development by whoever sold them SharePoint. They may even have been told that this assumes you use as much out of the box functionality as possible and avoid code customisation if you can. Understandably, what they don't realise is that the things they are asking for are customisations that will require code to be written, tested, deployed and maintained.

It is up to the developers or IT managers to explain this to the business users and make it very clear whether what is being asked for is out of the box or whether it is a code based customisation.

Another reason it is a mistake is that the requests to turn off alerts or add links in unusual places are significant changes to the standard interface. One of the benefits of using SharePoint is that it provides a consistent platform and each change to that platform chips away at this consistency. The benefit of a consistent interface is that once a user has mastered one application or area of SharePoint they should be able to open any other SharePoint site and feel immediately at home. The changes mentioned may sound small but over time can build up to mean that some areas of SharePoint become almost unrecognisable. This will lead to an increase in support calls and training costs as users will be confused by these inconsistencies and ultimately this can hurt user adoption of the platform as a whole.

I'm not saying that you shouldn't use code based customisations or alter the user interface in any way but these customisations do come with an overhead that needs to be understood by the business. The danger is that if this is not clearly explained the original expectations of rapid application development and the benefits of a consistent platform are not met and the business starts to question whether these claims were ever true or even worse, whether any claim made about SharePoint is true!

An informed choice needs to be made by the business on a per application basis as to whether they are prepared to invest the extra time and effort to get an application that meets 100% of requirements. Or, decide that it is better to have something delivered far more rapidly that meets ~80% of the requirements and loses some of the nice to have elements. In addition, there also needs to be someone in the business taking an overall view of what customisations are acceptable across the platform to preserve interface consistency for the benefit of all applications.

This is clearly not an all or nothing choice and there is a sliding scale of just how much customisation the business is prepared to take on. Once people come to terms with and fully understand these choices and trade offs they usually feel much happier about SharePoint and the best way to deliver applications for their business. Ultimately SharePoint is about giving the business the tools to do a job in the most effective and efficient way possible and sometimes this means having to say no to some requirements.

What do you think? Is this something you have seen happening at companies you work with? Are there other mistakes that you see happening more frequently?


Book Hashtags, Seth Godin and a New Website

May 29, 2011 08:35 by Aidan

This is a bit off topic for this blog so if you came looking for SharePoint tips look away now!

Last week Seth Godin blogged about using hashtags on Twitter to keep track of the conversations going on around books.

I think that this is a great idea as it allows readers to easily find and engage with people reading the same books and it also provides a way for the author to get involved and to show up at the conversations that their books are provoking.

There seemed to be a couple of issues with this approach though:

  1. How do you find the "official" hashtag for each book? (Assuming that the author/publisher hasn't thought to mention it somewhere in the book)
  2. Twitter search only returns Tweets from the last few days so the tail end of the conversation is soon lost

For those reasons I have created bookhashtags.com. The site acts as a place where readers can come and find the "official" hashtag for their book and also as a place that displays the entire conversation going on around each book hashtag that has been indexed.

What do you think? Is this side conversation a useful addition to your enjoyment of a book? Which books/hashtags would you like to be added? If you have a book/hashtag to add you can add it here.


Tags:
Categories:
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Using JQuery to round averages in a SharePoint view

April 14, 2011 19:09 by Aidan

I had a question from a user asking whether it was possible to round the Average that is displayed on SharePoint views to 2.d.p.

Out of the box this is not possible but with a little bit of JQuery we can find the average and round it to the required d.p.

<script src="jquery.js"></script>
<script>
$(document).ready(function(){
   $('b').each(function(index){
   var value = $(this).html();
   var num = value.replace('Average = ','');
   var result = Math.round(num*Math.pow(10,2))/Math.pow(10,2);
   $(this).replaceWith('<b>Average = '+result+'</b>');
   });
});
</script>


Tags:
Categories:
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Dynamically change InfoPath submit connection properties

April 12, 2011 18:49 by Aidan

If you want to change the properties of the data connection that your InfoPath form is using on submit you can do this in code. You might want to do this if you have lots of sites that use the same structure and each site contains a library that holds a certain type of form. Eg. A project site contains a library for project changes that are submitted using an InfoPath form. Each project site has a project changes library but you don't want to have to create a new project change form with a different submit connection for every site.

In the submit event use the following for SharePoint 2007

SPWeb web = SPContext.Current.Web;
FileSubmitConnection dc = (FileSubmitConnection)DataConnections["Submit"];
dc.FolderUrl = web.Url + "/[library name]";
dc.Execute();

e.CancelableArgs.Cancel = false;

In SharePoint 2010 there is also the option of using the ServerInfo class that has a property called SharePointListUrl to provide the current list context which can be used as follows

FileSubmitConnection dc = (FileSubmitConnection)DataConnections["Submit"];
dc.FolderUrl = ServerInfo.SharePointListUrl;
dc.Execute();
e.CancelableArgs.Cancel = false;


Tags:
Categories:
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

SharePoint 2010 SPTimer job won't activate

February 2, 2011 12:10 by Aidan

...and the error you see in ULS viewer is "The SPPersistedObject, XXXXXXXXXXX, could not be updated because the current user is not a Farm Administrator"

Solution can be found here - http://unclepaul84.blogspot.com/2010/06/sppersistedobject-xxxxxxxxxxx-could-not.html - cheers Paul!

Script to turn off remote administration security is:

# AUTHOR: Paul Kotlyar
# CONTACT:
unclepaul84@gmail.com
# DESCRIPTION: sets an option on content web service that allows updating of SP Administration objects such as SPJobDefinition from content web applications
function Set-RemoteAdministratorAccessDenied-False()
{
 # load sharepoint api libs
 [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null
 [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Administration") > $null

  # get content web service
 $contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
  # turn off remote administration security
 $contentService.RemoteAdministratorAccessDenied = $false
  # update the web service
 $contentService.Update()
  
}

Set-RemoteAdministratorAccessDenied-False


Tags:
Categories: SharePoint 2010
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed