Steps to deploy a WebPart as a Wsp Solution Package in SharePoint 2007
1. Open visual studio 2005/2008
2. Create a SharePoint WebPart.
3. Write all your code.
4. Now build the WebPart.
5. Go to solution properties & change the start browser with URL to your SharePoint site URL.
6. Now click on deploy.
7. Now the .wsp file was generated in the bin\debug or bin\release folder of your project.
8. Now open this path and copy the wsp file to the above path “C:\Program Files\common files\Microsoft Shared\web server extensions\12\bin”.
9. Now open your central administration
10. Go to operations tab
11. In operations go to solution management.
12. Click on your wsp file.
13. Click on deploy solution.
14. Deploy solution link will take you to solution.aspx.
15. In this page select the dropdown which contains sitecollection URL’s in the server.
16. Now select your sitecollection & press ok.
17. Now go to your SharePoint site.
18. Go to site settings page.
19. In this page select webparts.
20. Click on new.
21. Select your wsp & click on populate gallery.
Here is the above code I have tested for WSP.
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.Security;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
[assembly:AllowPartiallyTrustedCallers]
namespace SampleWSpSolution
{
[Guid("7c14ef7b-9ca7-4d14-9047-58f333a4c6af")]
public class SampleWSpSolution : System.Web.UI.WebControls.WebParts.WebPart
{
SPDataSource sd = new SPDataSource();
GridView dgvClients;
string strError = string.Empty;
public SampleWSpSolution()
{
}
protected override void Render(HtmlTextWriter writer)
{
writer.Write(strError);
try
{
dgvClients.RenderControl(writer);
}
catch (Exception ex)
{
writer.Write(ex.ToString());
}
}
protected override void CreateChildControls()
{
try
{
dgvClients = new GridView();
SPWeb myWeb = SPControl.GetContextWeb(Context);
dgvClients.AutoGenerateColumns = false;
BoundField ClientName = new BoundField();
ClientName.HeaderText = "Our Clients";
ClientName.DataField = "Title";
dgvClients.Columns.Add(ClientName);
this.Controls.Add(dgvClients);
SPList List = myWeb.Lists["Clients"];
sd.List = List;
dgvClients.DataSource = sd;
dgvClients.DataBind();
}
catch (Exception ex)
{
strError += ex.ToString();
}
}
}
}
No comments:
Post a Comment