You need a custom page in SharePoint (WSS 3.0) that must do something. For arguments sake, we’ll say it needs to allow a user to select information from some data source via a combo box and use that to populate a list.
How do you do this?
Part 1: Develop the web part.
Part 2: Create the web page.
Part 3: Add the web page as a feature to your site collection.
1. Create a new Visual Studio SharePoint project.
2. Add a web part to the project. For the purposes of my demonstration, I’ve created a web part that has a text box (for the list title), a drop down list populated by ten items and an ok button (code at the end of this part).
3. Deploy the web part to your site (in VS, just select deploy from the build menu. This should also create the setup.bat file & the MOSS solution, making future deployment incredibly easy).
4. Create a new web part page in your MOSS site.
5. Create a custom list with fields that match the fields you want to update (in my case, the title text field and an additional text field to hold my selected value).
6. Add the web part to your newly created MOSS page.
public class AddItem : System.Web.UI.WebControls.WebParts.WebPart
protected DropDownList ddlAvailableValues;
protected System.Web.UI.WebControls.TextBox txtItemTitle;
protected System.Web.UI.WebControls.Button btnAddItem;
this.ExportMode = WebPartExportMode.All;
protected override void CreateChildControls()
ddlAvailableValues = new DropDownList();
ListItem memoryItems = new ListItem;
memoryItems = new System.Web.UI.WebControls.ListItem("Please select a list item", "0");
for(int i = 1; i < l =" new" value =" i.ToString();" text =" string.Format(" cssclass = "ms-RadioText" txtitemtitle =" new" cssclass = "ms-long" btnadditem =" new" text = "OK" cssclass = "ms-ButtonHeightWidth" bloglist =" SPContext.Current.Web.Lists[" item =" blogList.Items.Add();">
My web part looks like this:
So far so good. Now we come to the “let’s cheat to make this easy part”. Hehe, I knew you’d like that.
You don’t want your web part page lying around in the library right? You want it to be part of your site collection, prefrably as a feature. That would be the ideal.
So, we fire up SharePoint Designer.
We open up the web part page that we created and added the web part to.
We copy the ASPX code.
We create a new ASPX file in the windows directory we want to use as our feature deployment folder (in my case BlogPages).
We copy the code into the new ASPX file.
And that creates our ASPX file. Now for ease of deployment.
Create a feature file.
Create an element manifest.
Deploy the feature (I do this via a setup.bat file that resides in the parent directory above my BlogPages directory).
Now, on the site you deployed the feature on, enter the URL of the page, for instance: http://servername
And there you are. The page is part of your site, activated as a feature.
Life is beautiful.
My files for all this: