Skip to main content

Deploy Webpart as Solution Package and Feature

In this example we will create a SharePoint WebPart using VseWss, which will display data from a SharePoint list in a gridview control. After creating the webpart we will deploy the solution file i.e. .wsp file in our SharePoint site using stsadm.


To begin with you need to install the Visual studio extensions for Windows SharePoint Services 3.0 (VseWss) for your appropriate Visual Studio version.
You can download the latest one from this link.

Output:


Next thing that you have to keep in mind is that you are developing this solution on the server or machine which has WSS 3.0 installed in it.
Lastly, a Cutsom list named "Clients" should exist in your SharePoint site. Since I am using a Custom list called "Clients" and also a Custom column "Clients" in that list in my webpart.

Lets begin with the steps
1. Create a SharePoint WebPart Project. See the Screen below.

2. Now in your soluiotn explorer you would see a folder named "WebPart1". Letse just rename it to "MyCustomWebPart". Make sure you also rename all the files in the folder. Also, don't forget to change the url path in MyCustomWebPart.xml. So, we have somthing like below .

3. Now lets write some code in our MyCustomWebPart.cs . In this webpart we will create a Gridview control and will bind it to one of the columns in the SharePoint list. We have also used RunWithElevatedPrivileges so that the code runs under Application Pools identity and should not cause errors for the end users. The list we have used is called "Clients" and the Column in the list is also called "Clients".

Code :

namespace MyCustomWebPart
{
[Guid("f66be37b-91f9-4e99-97dc-0e30f6eb44ff")]
public class MyCustomWebPart : System.Web.UI.WebControls.WebParts.WebPart
{
GridView myGrid;

public MyCustomWebPart()
{
}

protected override void CreateChildControls()
{
SPDataSource SPDataSource1 = new SPDataSource();
try
{
SPSite mySite = SPContext.Current.Site;
SPWeb myWeb = mySite.OpenWeb();
//Using RunWithElevatedPrivileges

SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite siteCollection = new SPSite(mySite.ID))
{
using (SPWeb web = siteCollection.OpenWeb(myWeb.ID))
{
myGrid = new GridView();
myGrid.AutoGenerateColumns = false;

BoundField ClientName = new BoundField();
ClientName.HeaderText = "Our Clients";
ClientName.DataField = "Clients";
myGrid.Columns.Add(ClientName);

SPList List = myWeb.Lists["Clients"];
SPDataSource1.List = List;


myGrid.DataSource = SPDataSource1;
myGrid.DataBind();

Controls.Add(myGrid);

base.CreateChildControls();
}
}
});
}
catch { }
}
}
}

In above Code we have also used SPDatasource which will define the Source for Gridview control as SharePoint list.

Now lets just build the project. Please Note that building the project will not create a .wsp or solution package . To create a Solution file or .wsp file we will have to virtually Deploy the project. So, to do that just right click on the Project "MyCustomWebPart" and click on Depoly. See the screen below.



You will likely get an error at this point. Since, we have not specified the deployment target. Just ignore the error and grab the .wsp file. To see awhat all files are created click on "Show all Files" button on top the solution explorer.


Now you will see your .wsp file along with files like feature.xml and manifest.xml files.


Deployment : At this point we have two options for deploying this wsp or solution package in our sharePoint site.
1. Deploy using Visual Studio - This is quick and easy deployment. Just right click on you project and goto Properties. Goto the "Debug" tab and enter you SharePoint site's url . Save it and again hit the Deploy button. See the screen below.



2. We will deploy the wsp file using stsadm . To do this open a command prompt and navigate to the below path
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN.
Open this path in your windows explorer and drap and drop your wsp in here. See Screen below.



Lets write the command to deploy the webpart.



In this case you will just add the solution package in SharePoint's Solution store. You would then need to goto CentralAdmin->Operations->Solution Management and deploy the webpart. Just click on the webpart title in Solution management screen and you will see the below. Click on Deploy Solution and Choose the webapplictaion.


After you deploy : After yo deploy the webpart you will need to add it into webpart gallery. To do this Open your site and goto "SiteActions->Site Settings ->Modify All Site Settings ->WebParts. Click on New and select the webpart from the Screen. See below



 Now you are all set to add the webpart in your webpart page.

Comments

  1. After checking out a handful of the blog articles on your web page, I truly like your technique of
    blogging. I book-marked it to my bookmark site list and will
    be checking back in the near future. Take a look at my web site
    too and let me know how you feel.

    My web site; cash advance in an hour

    ReplyDelete
  2. Have you ever thought about adding a little bit more than just your articles?

    I mean, what you say is fundamental and everything.
    But just imagine if you added some great graphics or video clips to give your posts
    more, "pop"! Your content is excellent but with pics
    and clips, this site could definitely be one of the best in its niche.
    Excellent blog!

    My blog ... related web site

    ReplyDelete
  3. My partner and I stumbled over here from a different web address and thought
    I may as well check things out. I like what I see so now i am following you.
    Look forward to looking over your web page repeatedly.



    Feel free to visit my website: Orange County Catering

    ReplyDelete
  4. Hi there, I discovered your website via Google at the same
    time as looking for a similar topic, your web site got here up, it appears to be like good.
    I have bookmarked it in my google bookmarks.
    Hi there, simply became aware of your weblog thru Google, and found that it is really informative.
    I am gonna be careful for brussels. I will be grateful should you proceed
    this in future. Lots of people shall be benefited out of your writing.

    Cheers!

    Also visit my site Mortgage loans

    ReplyDelete

Post a Comment

Popular posts from this blog

Tab Control in Asp.Net

Scenerio: I need your help in designing tab control in   asp.net .My requirement is I need a tab control in   asp.net (C#) like  for example goto my computer ,right click c drive and select properties.we get tabs like general,security etc....... like that i need to design one tab control(no need of any rightclick) in my web page and the database table columns should come as tabs and inseide the tab data of that particular column should come.   Example:Employee master tab1:Employee name.........his name in the tab tab2:Age.............his age tab3:Address........his address   Solution:   You can do this using a simple div <style type="text/css"> .tabs         {             position: relative;             height: 20px;             margin: 0;   ...

AI and Microsoft: Revolutionizing Efficiency in Nonprofit Organizations

  How AI and Microsoft Enhance Efficiency in Nonprofit Organizations In today’s fast-paced world, nonprofit organizations face unique challenges—limited resources, increasing demands, and the constant need to do more with less. But what if technology could be the game-changer they need? In my latest research paper,  "How AI and Microsoft Enhance Efficiency in Nonprofit Organizations" , I explore how cutting-edge technologies like Artificial Intelligence (AI) and Microsoft’s innovative tools are revolutionizing the way nonprofits operate. From streamlining administrative tasks to enhancing donor engagement and optimizing resource allocation, AI and Microsoft’s solutions are empowering nonprofits to focus on what truly matters—their mission. This paper dives deep into real-world examples, practical applications, and the transformative potential of these technologies. Whether you’re a nonprofit professional, a tech enthusiast, or simply curious about the intersection of technolo...

Social tagging overview in Sharepoint 2010

A tag is a word or phrase that identifies an individual piece of information according to a set of attributes or criteria. Tags make it easy to find and share information about a specific subject or task. Social tagging helps users categorize information in ways that are meaningful to them. Social tagging can improve the quality of search results by filtering against specific tags, and it can also connect individuals who want to share information with other users who have like interests. This article describes the social tagging features in Microsoft SharePoint Server 2010. This article does not describe how to configure social tagging features. It also does not discuss how to implement social tagging features as part of an overall social media strategy for an enterprise. About using social tagging features Social tagging features help users to share information and to retrieve relevant, high-quality content more efficiently. Such sharing encourages collaboration and b...