How to create SharePoint Windows Forms Application in Visual Studio?

How to use SharePoint In Desktop Windows Application

In this post, we will learn how to add Microsof.SharePoint.dll reference in Windows Forms Application to be able to connect and create SharePoint Windows Forms Application in Visual Studio.

create sharepoint windows forms application in visual studio
create SharePoint Windows Forms Application in Visual Studio

You might also like to read SharePoint Framework For SharePoint Server 2016.


Using SharePoint In Windows Forms Application in Visual Studio

In Visual Studio, I want to build a SharePoint desktop application and consume SharePoint Object Model inside Windows Forms Application instead of SharePoint Solutions, So that I have tried to create a new Windows Forms Application, then I have added Microsoft.SharePoint.dll reference and finally, I hit the build button to build the solution.

But I had noticed that the Microsoft.SharePoint.dll  was removed from the reference list automatically and I can’t use SharePoint.dll reference In Desktop Windows Application using Visual Studio.

SharePoint Server Side Object Model Vs SharePoint Client Side Object Model

In Visual Studio Windows Forms Application, to can connect and deal with your SharePoint farm through one of the below Models:

  1. SharePoint Server Side Object Model (Microsoft.SharePoint.dll). or
  2. SharePoint Client Side Object Model (Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.RUNTIME.dll).
SharePoint Object ModelSupported LanguageSupported SharePoint VersionsUsed InNotes
SSOM – Server Side Object ModelC#, VB.NETSharePoint 2007,2010, 2013 and 2016Wed and Desktop1. SharePoint Installation is required.
2. Must be deployed on the farm side.
CSOM – Client Side Object ModelC#, VB.NETSharePoint 2010, 2013 and 2016Wed and Desktop1. No SharePoint Installation required.
2. No deployment on the farm side.
3. Faster
JSOM – JavaScript Side Object ModelJS/JQuerySharePoint Online, 2010, 2013 and 2016Web
SSOM Vs CSOM Vs JSOM

Create SharePoint Windows Forms Application in Visual Studio

In this section we will explain

  1. How to use SharePoint SSOM in Windows Forms Application?
  2. How to use SharePoint CSOM in Windows Forms Application?

How to use SharePoint SSOM in Windows Forms Application?

In this section, we will show How to use SharePoint Server Side Object Model in Visual Studio Desktop Windows Application by adding Microsoft.SharePoint.dll reference as the following:

Solution

  1. Change Platform Target.
  2. Change Framework Target.
  3. Add SharePoint Reference.

1 ) Change Platform Target in Visual Studio for SharePoint

SharePoint doesn’t support x86 platform, so you should change it to x64 as the following:

Steps
  1. Open your Windows Forms Application in Visual Studio> Right click on the Project Name > Click on Properties.
open sharepoint windows forms app properties
S
  1.  Click on Build Tab > at Platform Target > Change Platform Target from 86x to 64x.
change platform target in visual studio

2 ) Change Framework Target in Visual Studio for SharePoint

Based on SharePoint version, you should make sure that you are targeting the supported framework by doing the following:

Steps
  1.  Select  Application Tab >  Target frameworks.
change target .net framework in visual studio
  1. For SharePoint 2010, you should change Target Framework from .Net Framework 4 client profile to .Net framework 3.5.
How to create SharePoint Windows Forms Application in Visual Studio?

For SharePoint 2013 and 2016, you should use Microsoft .NET Framework version 4.5 or higher.

Add Microsoft.SharePoint.dll reference in Windows Forms Application

As we earlier mentioned, to use SharePoint SSOM in Windows Forms Application, you should add the Microsoft.SharePoint.dll reference as the following:

Steps
  1. Try now to add the Microsoft.SharePoint.dll reference to your windows forms application.
add l reference in Windows Forms Application visual studio
  1. Search for Microsoft.SharePoint > Select Microsoft.SharePoint.dll > Click Ok.
Add Microsoft.SharePoint.dll reference in Windows Forms Application
  1. Now, try to build your solution that should be working properly.

How to use SharePoint CSOM in Windows Forms Application?

In the SharePoint Client Side Object Model, no need to have SharePoint installed. however, you should have a copy of the following dlls in your development environment:

  1. Microsoft.SharePoint.Client.dll
  2. Microsoft.SharePoint.Client.RUNTIME.dll

You can get these dll files from a SharePoint farm at C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI

Add Microsoft.SharePoint.Client.dll reference in Windows Forms Application

In case, you have already a SharePoint installed, you can add Microsoft.SharePoint.Client.dll reference as the following:

Steps
  1. Right-click on References > Click Add Reference.
  2. Search for Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.RUNTIME.dll > Click OK.
Add Microsoft.SharePoint.Client.dll reference in Windows Forms Application

In case, you don’t have already a SharePoint installed, you can add Microsoft.SharePoint.Client.dll reference as the following:

Steps
  1. Right-click on References > Click Add Reference.
  2. Click browse to browse the folder that holds the copied dlls (Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.RUNTIME.dll) from another SharePoint farm > Click OK.
browse add Microsoft.SharePoint.Client.dll reference in Windows Forms

Conclusion

In conclusion, we have learned how to How to create SharePoint Windows Forms Application in Visual Studio using SharePoint SSOm or CSOM. also, we have learned the main differences between SSOM, CSOM, and JSOM.

Applies To
  • SharePoint 2016.
  • SharePoint 2013.
  • SharePoint 2010.
  • Visual Studio.
You might also like to read
Have a Question?

If you have any related questions, please don’t hesitate to ask it at deBUG.to Community.

8 thoughts on “How to create SharePoint Windows Forms Application in Visual Studio?”

  1. drzwi fornirowane kraków

    You really make it appear really easy with your presentation but I in finding this topic to
    be really something that I believe I’d by no means understand. It kind of feels too complicated and extremely broad for me. I’m looking ahead to your subsequent put up,
    I will try to get the hold of it!

Leave a Reply