Thursday, October 11, 2012

Allowing a Windows Forms Application to manage SharePoint 2010

If you'd like to create a Windows Forms Application that a power user (i.e. perhaps a Business Analyst who isn't versed in PowerShell, but has a high level of access to the SharePoint Farm) could use for administering functionality on your SharePoint farm that isn't covered by standard tools, there are a few steps that you'll need to carry out first before your application will run on the farm.  After creating your Windows Forms Application, the first thing you'll need to do is add a reference to the Microsoft.SharePoint.dll file.  This can be accomplished via the following steps:
  1. Using Visual Studio 2010, open your Windows application solution
  2. Expand the tree under your solution in the Solution Explorer view
  3. Under your project, right-click on References and select Add Reference...
  4. There will be two routes you can pursue for adding the assembly based on your development environment:
  • If your developing on an environment with SharePoint installed, you can reference the assembly via the following steps:
    1. Click on the .NET tab
    2. Locate and click on the Microsoft.SharePoint item
    3. Click OK
  • If you don't have SharePoint installed in your environment, you can reference the assembly via the following steps:
    1. Obtain the assembly via the steps that I've covered in my blog post titled Accessing files contained in the Global Assembly Cache
    2. Create a new folder in your project called "External Assemblies"
    3. Add the Microsoft.SharePoint.dll file to the new folder
    4. Under your project, right-click on References and select Add Reference...
    5. Click on the Browse tab
    6. Navigate to the "External Assemblies" folder
    7. Click on the Microsoft.SharePoint.dll file
    8. Click OK
Once you've associated the SharePoint assembly, the next step will be to make certain your Windows application can run in a 64 bit environment if your app is going to be accessing SharePoint 2010.  By the way, if you don't follow these steps, your code will throw an error message that reads "Object reference not set to an instance of an object".  Here are the steps that will allow your app to run in a 64 bit environment: 
  1. In the Solution Explorer view, right-click on the project and select Properties
  2. Under General, locate the Platform target: dropdown and change the value from "x86" to "Any CPU"

  3. Save the change and build your solution
At this point in time, your Windows application will now be able to run directly on one of your SharePoint WFE servers in order to carry out the admin activities that your power user would like it to execute.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.