views:

278

answers:

1

Hi,

I have a dropdown and a button on a page layout.Dropdown is retrieving information from some list.I need to select the value in the dropdown and when I m clicking the button it should update the page metadata properties(which is nothing but document library metadata property).

I am facing two problems over here:

First how to retrieve on which page to update . As I am putting my above webpart on different pages so it is standard for all.I know there is some current page url thing but I don't know exactly how to use this in this respect.

Second how to udpate metadata property in document library. I know how to acheive this with list but not with document library.

Can you guys guide me please!!!!!

Thanks, PS

A: 

First you need to Create an Extra Column to hold the Meta Data.[Lets assume you wanted to add a metadata column with Name ExtraInfo of Type Number]

You can easily solve both the Issues in a Single shot, to give a little info each page in the Pages Library is nothing but a Normal ListItem, and it is easy to get the current List Item using the below code.

SPContext.Current.ListItem

With the List Item in the Hand you can do your stuff. So in the Button Click event you can write the following code to update the Value.

SPListItem lstItem = SPContext.Current.ListItem; // Get the Current List Item (Page)
lstItem["ExtraInfo"]=ddlExtraInfoDropDownList.SelecteValue;//Set the value for Metadata
lstItem.Update();//Update it

Note: To Update the Publising Page you might need to Check Out the page, Update the Metadata value. Also You need to ensure that the User who is going to perform the operation has the enough rights to Update the page, if not either dont show the Update button or do the whole stuff in the Elevated Mode.

Kusek