Introduction, creation and deploying a Visual Web Part in SharePoint 2013
What is visual web part?
Introduction, creation and deploying a Visual Web Part in SharePoint 2013. In SharePoint, Web parts are the main interface elements. Web parts are the reusable component that displays the content on the Web page in share point.
the process of creating the visual web part in SharePoint 2013 is different from SharePoint 2010. In the SharePoint 2010, a visual web part made of user control and web part file which defines the control and properties of the web part. In the SharePoint 2013, A visual web part template completely changed. Web part class and user control classes are merged together and created one template. Now we have only one visual web part template that is used to create both form and sandbox solution.
In this article, I will explain you stepwise to creating web parts and deploying wsp package file to your SharePoint site.
We can create web parts in three ways
- Using Visual studio
- Using SharePoint designer
- Using OOB
There are 4 ways to deploy web parts
- Using Visual Studio to deploy the solution
- Manually moving the DLL to the server
- Uploading WSP to SharePoint server
- Deploying through command prompt
Creating visual web part
- Create a SharePoint 2013 Visual Web Part Project.
- Next, add the Site URL and select deploy as farm.
- The Solution should look like below.
- Add a label in your .ascx file and add assign it in your code behind like this.
Creating visual web part using Uploading WSP to SharePoint server
- Save and click start
- Upload and Activate .wsp
- You should be able to find the .wsp file in the windows explorer where the project is placed. It will be under Bin\Debug with extension .wsp.
- Once you are all set with .wsp file to navigate to Site Settings on SharePoint site -> Solutions and upload the wsp and make sure to activate the solution
- Congratulations! Now the newly created web part can be added to any web part page from the web part gallery.
- Click on the page in ribbon and save the page. Your web part is ready.
Deploying Web Part using Visual Studio
in this option just right click on SharePoint solution created using visual studio and click on deploy. Now you don’t need to do anything visual studio will be deploy and activate automatically, you can add web part any page.
Deploy wsp using PowerShell SharePoint
- Right click on solution and publish the solution to creating the WSP of the solution.
- Open SharePoint 2013 Management Shell with Run as administrator. Copy the below command and paste it.
Add-SPSolution “Your WSP Location”\”Your WSP Name”.wsp.
- Open SharePoint Central Administration and click on Solution Management. Your solution is added to Solution Management.
- Open the SharePoint 2013 Management Shell with Run as administrator. Copy the below command and paste it . and press enter key.
Install-SPSolution –Identity “WSP Name”.wsp –WebApplication “Site Url” –GACDeployment
Now you can check your solution has been deployed in SharePoint site.