Create dll using Visual Studio 2010 SharePoint 2010

Now, we will see how to create a DLL file for a class using Visual Studio 2010 in SharePoint 2010.

Create Create DLL file using Visual Studio 2010 in SharePoint 2010

Follow steps to create Create dll file for the class using Visual Studio 2010 in SharePoint 2010:

In Visual Studio click File, click on New Project and select .NET Framework 3.5 as the target framework, select SharePoint 2010 under the installed template, select the Empty SharePoint Project and give the project name SharePointDllFileExample and then click OK. See in fig

Create Create DLL file using Visual Studio 2010 in SharePoint 2010

Give the SharePoint URL and port and choose to Deploy as a farm solution and then click on Finish. See in fig

Create dll using Visual Studio 2010

Now right click on solution explorer =>add =>New Item. See in fig

how to Create dll using Visual Studio 2010

Now Select Class under code of Visual c# and give the class name classTobecalledUsingDll.cs and click OK. See in fig

Create dll using Visual Studio 2010 sharepoint

Now write the following code in this class. See in fig

how to Create dll using Visual Studio 2010 sharepoint

Now build the project from the solution explorer. See in fig

how to Create dll using Visual Studio 2010 sharepoint 2010

Now you can see you classTobecalledUsingDll.dll into Projects\SharePointDllfileExample\SharePointDllfileExample\bin\Debug\ directory

Now add your assembly to global assembly cache (GAC). Either you can drag from debug (C:\Users\cjuser\Documents\VisualStudio2010\Projects\SharePointDllfileExample\SharePointDllfileExample\bin\Debug) into C:\Windows\assembly directory. Otherwise, you can use command line utility.

Now you have to register your assembly into the project where you want to use. In my case, I am using it in a master page. Add below code to the top of the page.

<%@ Assembly Name="#strong name#" %>
<%@ Import Namespace="#assembly name# "%>

Replace #strong name# with the strong name of the class and “#assembly name# with the name of an assembly of the class. To find strong name follow this link.

Otherwise go to C:\Windows\assembly and select classTobecalledUsingDll.dll file right click on it and select properties. See in fig

sharepoint 2010 Create dll using Visual Studio

You will get assemblyname, Version ,Culture and publickeyToken In this case it will look like this

<%@AssemblyName="dllfileexample, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=28e209cae9a6ed9″ %>
<%@ Import Namespace="dllfileexample"%>

Now you can access the class method wherever you want like this

<%=classTobecalledUsingDll. getMessage ()%>

In my case I am using in update panel like this

<asp:UpdatePanel ID="updatepanelDateTime" runat="server" UpdateMode="Always">
                            <ContentTemplate>
                            <fieldset>
                            <legend>This is updatepanel date</legend>
                           <%=classTobecalledUsingDll. getMessage()%>
                           </fieldset>
                           </ContentTemplate>
                            </asp:UpdatePanel>

Now you can run your project and enjoy .You will see” This is simple class dll file example”. In the updatepanel section result.

You may like following visual studio 2010 tutorials:

Here we have learned how to create dll file for class using Visual Studio 2010 in SharePoint 2010.

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

Navneet Singh

I am Navneet Singh, Working at C3it software solutions pvt. ltd. in Pune. My core skills are SharePoint 2013, Office 365, SharePoint 2010, SharePoint Designer, SharePoint Designer Workflow, Nintex Workflow, Infopath, Webpart, CSOM/SSOM, Power-shell, C#, ASP.NET and SQL Server.

>