views:

602

answers:

2

Hey all,

I'm having a hard time figuring out how to refer to a specific Item List within a list in SharePoint. I looked up the page in SharePoint Designer and found that the listitem is inside a custom made webpart inside a custom made webpage. I'm coding an event receiver and need to read the information that the user types into that listitem which is a textbox. Does anyone know the code to do this or how to get the guid for the specific list item?

I would appreciate any help I can get. I have tried looking all over the web for the answer. Thanks.

+1  A: 

It might be a good idea to edit your question with exactly what you'd like to do with the information you read. However from what you've said so far:

The ID of the item being edited will already be passed through to the event receiver via SPItemEventProperties so there is no need to look it up. If you need to look up a different item in the list (or indeed in a different list altogether), the Accessing list items using the object model page on SharePoint Dev Wiki gives you all of the options. A good general rule is use SPQuery to get best performance on the whole.

Note: There is a pretty good page on the SharePoint Dev Wiki demonstrating how to write an event receiver. It shows how to query and obtain a list item title.

Update after comments:

Once you have an SPListItem object, you can find its GUID through the UniqueId property. In the "Accessing lists" wiki link I've provided above the code samples show how to use the Title property.

Every piece of data you need to access within SharePoint should be available through the object model. This is a simplification, but generally the pages themselves are rendered from template files on the server and combined with data in the database to display to the user. So editing the page programmatically or through its source isn't going to work.

Apologies if I'm making an incorrect assumption but you sound fairly new to SharePoint development. I strongly recommend you read at least the first few chapters of Inside Windows SharePoint Services 3.0 as the inner workings of SharePoint are important to get a good understanding of and this book should help a lot. There is a section of event receivers in it as well.

Alex Angas
Brian Wilson wrote a very nice guide about event handling and included a ready-to-use framework. Event handler can be a lot of fun, happy coding
Kasper
http://blogs.msdn.com/brianwilson/archive/2007/03/05/part-1-event-handlers-everything-you-need-to-know-about-microsoft-office-sharepoint-portal-server-moss-event-handlers.aspx
Kasper
Thanks for your quick feedback. I really appreciate it. I was wondering if there was an easy way to find the guid to a particular List Item? Where would I go to find this? Could I access this through source code of a page or through a SharePoint page?Also, the List Item I am trying to read is the title value when a user tries creating a new record in a list. After they add the information, I want to check to see if this title already exists before I allow it to be added as another title. I hope this clarifies the problem.
A: 

Have you looked at SharePoint.ListsService Webservice?

string url = "WSS Site URL";
SharePoint.ListsService.Lists lists = SharePoint.ListsService.Lists(url);
XmlNode list = lists.GetList("ListName");
XmlNode xlists = lists.GetListCollection();
CptSkippy