Create dll file for class using Visual Studio 2010 in SharePoint 2010

InfoPath alternatives for form designing SharePoint

In this post, we will discuss how to create a DLL file for a class using Visual Studio 2010 in SharePoint 2010.

Also, you can check out:

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

1. 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 dll file for class using Visual Studio 2010 in SharePoint 2010
Create a dll file for the class using Visual Studio 2010 in SharePoint 2010
2. Give the SharePoint URL and port and choose to Deploy as a farm solution and then click on Finish. See in fig
Create dll file for class using Visual Studio 2010 in SharePoint 2013
Create a dll file for the class using Visual Studio 2010 in SharePoint 2013
3. Now right click on solution explorer =>add =>New Item.  See in fig
Create dll file for class using Visual Studio 2010 in SharePoint 2016
Create dll file for class using Visual Studio 2010 in SharePoint 2016
4. Now Select Class under code of Visual c# and give the class name classTobecalledUsingDll.cs and click OK. See in fig
Create dll file for class using Visual Studio 2015 in SharePoint 2019
Create DLL file for the class using Visual Studio 2015 in SharePoint 2019
5. Now write the following code in this class. See in fig
Create dll file for class using Visual Studio 2010 in SharePoint 2010
Create DLL file for the class using Visual Studio 2010 in SharePoint 2010
6. Now build the project from the solution explorer. See in
Create dll file for class using Visual Studio 2010 in SharePoint 2016
Create dll file for class using Visual Studio 2010 in SharePoint 2016
7. Now you can see you classTobecalledUsingDll.dll  into  Projects\SharePointDllfileExample\SharePointDllfileExample\bin\Debug\  directory
8. 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.
9. 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# “%>
10. 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.
11. Otherwise go to C:\Windows\assembly and select classTobecalledUsingDll.dll  file right click on it  and select properties. See in fig
Create dll file for class using Visual Studio 2010 in SharePoint 2010
Create a dll file for the class using Visual Studio 2010 in SharePoint 2010
12. 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”%>
13. Now you can access the class method wherever you want like this
 <%=classTobecalledUsingDll. getMessage ()%>
14. 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>
15. 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 Also like the Following SharePoint Online Tutorials:

About 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.

View all posts by Navneet Singh →

Leave a Reply