Representation of a list item within the SharePoint API.

learn more… | top users | synonyms

11
votes
1answer
9k views

How to get a SPFieldLookupValue from an SPListItem?

When you get an SPListItemCollection from a SPList.GetItems(SPQuery) request, and the items have SPFieldUser or SPFieldLookup fields, what is the sexy way to get typed values, not the ...
11
votes
2answers
11k views

Safest way to get a date from Sharepoint into a C# datetime field, using object model?

If I have a Sharepoint list item with a date field. How can I get the field value populated into a c# datetime object? For example: DateTime validfrom = Convert.ToDateTime(item["validfrom"]); ...
8
votes
1answer
3k views

SPList.Add() vs SPList.AddItem() SharePoint 2010

Using some test code i found out that SPList.AddItem() executes slight faster then SPList.Add() - does anyone know why is it so ? DateTime start = DateTime.Now; SPList ...
8
votes
2answers
613 views

Is it possible to create a “Link to a Document” in a Document Library using a CAML Batch Command with UpdateListItems?

I have a Document Library in WSS 3 which has the "Link to a Document" content type enabled, and I want to use a batch command (via lists.asmx updatelistitems) to create a series of links. Here is the ...
7
votes
3answers
2k views

Multiple Lookup field , how to return better deliminators using object model?

I have a multiple lookup field, and when I do this: string myValue = oItem["MyLookupField"]; I get this string back: [id];#[displayText];#[id];#[displayText] or a real example: "5;#C3;#15;#P3" ...
6
votes
1answer
2k views

Attach a file to the list item

I attach file to the list item when it updating and when new item added. Additional condition when item updating - if the file already exists, remove it and replace the new. I receive events ItemAdded ...
5
votes
4answers
18k views

How to set ListItem Lookup Field value

How do I set a ListItem's Lookup field using code? SPFile file = list.RootFolder.Files.Add(destUrl, iStream, true); SPListItem item = file.Item; item["DocumentID"] = DocID.ToString(); ...
5
votes
2answers
3k views

Powershell: Update People Picker Field with domain\Username

I'm trying to get this to work in powershell: $spListItem[$ppField] = "domain\username" $spListItem.Update() This gives me the following error: Exception calling "Update" with "0" argument(s): ...
5
votes
1answer
2k views

ItemUpdated event handler runs four times

I have a list in the rootweb, and a list in a subweb. I want to update/add when something changes in an item in the subweb. This method is invoked in an ItemUpdated event receiver. The problem is that ...
5
votes
3answers
74 views

SPList.GetItems(view) vs SPList.GetItems(query)

Which solution from the two is the most efficient one: 1. Using SPList.GetItems with a given view as a parameter 2. Using SPList.GetItems with a given query as a parameters and then retrieving from ...
5
votes
2answers
316 views

SPQuery returning different before and after using RunWithElevatedPrivileges method

I am having a huge problem here. I am executing a query looking for a SPListItem, when I execute this query with user identity it works well, retuning the fields "Author" and "Editor" that I need. ...
5
votes
1answer
503 views

How can I tell if a document is 'being published'?

I need to use the relevant event receiver to tell if a document is being published, is this possible? I will settle for has 'just been published' - i.e. I have no preference between itemupdating and ...
5
votes
1answer
312 views

Get SPListItem from LINQ

I have used SPMetal to create a data context. I can query my lists. The queries return an object of the type of list that they are in. Is it possible to convert this type into a normal SPListItem ...
5
votes
2answers
1k views

SPListItem.SystemUpdate updates SPListItem.File.ModifiedBy

As can be seen from the debug image when I call SystemUpdate(false) of a SPItem, that SPItem's File object's ModifiedBy attribute changes to "SHAREPOINT\system". Sorry, it's a bit weird way to ...
5
votes
2answers
857 views

Problem with CAML SPQuery ItemChildCount result

I know that this query works fine SPQuery query = new SPQuery(); query.Query = "<OrderBy><FieldRef Name='ItemChildCount' Ascending='FALSE' /></OrderBy>"; But my ...
4
votes
2answers
6k views

Fastest way to retrieve an item by title?

Currently I am using a foreach loop to find the item I want by its title using the following code: SPList list = web.Lists.TryGetList("DocumentLibrary"); foreach ...
4
votes
3answers
8k views

Cannot get field value of list item through JavaScript

I try to get the value of a list item (that is currently selected). I know that I must load it into the context but even with loading the field explicitly I get the following message. Microsoft ...
4
votes
1answer
2k views

How to get Attachment URL Programatically From Sharepoint ListItem?

How to get Attachment Full URL Programatically From Sharepoint ListItem? Explanation: I have adding new item with attachment. Now i have to bind that attachment link to grid. When click on that link ...
4
votes
3answers
4k views

How to get SP.Folder for SP.ListItem in SharePoint 2010 JavaScript Client Object Model?

I have a custom button on ribbon for document library and need to disable it if current SPListItem is an empty folder. To disable button I use EnabledScript attribute of CommandUIHandler. I can get ...
4
votes
2answers
3k views

Locking SPListItem for entirely server-side update

I am using code similar to the following to apply an update to an SPListItem, after necessarily elevating to System privileges on said item. Because this can be called multiple times for the same ...
4
votes
2answers
188 views

Editing list item with custom field creates a new list item on current date and time

Based on How to add new field to custom list (See edit!) It is a different question relating to the above so thought I'd create a new question as the above was technically answered. But after adding ...
4
votes
1answer
200 views

Delayed Writes & Implications for Cross-Process Synchronization

Simple scenario: OWSTIMER creates a new SPListItem, populates it and calls .Update(). It then fires an HTTP request over to w3wp.exe (front-end app-pool) to invalidate an in-memory cache held there. ...
4
votes
0answers
81 views

Can you add comments to an append-only field in a list in Sharepoint 2010 using C#? [duplicate]

Possible Duplicate: Can you programmatically add comments to an append-only comment field in a custom item list using C#? Posted on stack exchange first, then I found this Sharepoint ...
3
votes
3answers
2k views

Find creation time for list elements (including documents)

I know SharePoint has some hidden fields for list items. I need to check the timestamp for when a list element was created, is this possible? The reason is I must allow the item to be edited for the ...
3
votes
1answer
562 views

How can I make sure that only one of two fields is filled out (ListItem)?

I have custom SharePoint list with several fields. Two of the fields are TargetPage and ExternalURL. At the moment the user is allowed to fill out both of them if he want to, and I want to deny that. ...
3
votes
6answers
4k views

ArgumentException when trying to access SPListItem value

I have a tool to update all items in SP (link replacement). The tool works most of the time but sometimes it throws me an ArgumentException ("Value does not fall within the expected range."). Here is ...
3
votes
2answers
4k views

How do I get the url for attachments on an SPListItem using C#?

I have an SPListItem for which I would like to get the urls of all its attachments. The urls will be used as part of my custom web part which has an SPList of SPListItem items.
3
votes
2answers
5k views

Set default value in a document library column via Powershell?

I'm looking for a powershell script that allows me to set the default value for a column in SharePoint. Thanks
3
votes
2answers
3k views

Invalid SPListItem. The SPListItem provided is not compatible with a Publishing Page

Whenever I try to save or publish or check in the web-interface, I get this error. The test-environment did not have this issue, and I've only added a single web part to the page and tweaked the CSS ...
3
votes
4answers
356 views

Set permissions on an item depending on column value

Is there anyway to set permissions on an item depending on a column value? I was think about creating a feature to do this but do I have to?
3
votes
1answer
594 views

Get last major published version of items returned as DataRow (from SPSiteDataQuery)

Does anyone know the solution for this? If I'm querying items by SPSiteDataQuery I receive a DataTable with DataRow objects. I could fetch the current version of an item and check if it ends with ...
3
votes
1answer
157 views

SPListItemVersionCollection - iteration performance

This question is related to my issue described here: SharePoint 2010 Performance troubleshooting On SP 2010: Does anyone knows if there is some performance limitations while using ...
3
votes
1answer
292 views

Caching SPListItems with Permissions

I have a versioned list that I need to cache list items for. The effect of which being: If a user has permission to view non published items the cache can return the item pending approval. ...
3
votes
1answer
765 views

Setting the DisplayFormURL of a CalendarView item to an absolute URL, SPCalendarView control

Background: I have a WebPart that makes use of the SPCalendarView control and in it I add items (events) dynamically from different Calendar lists from multiple sites. like this (please note that I ...
3
votes
2answers
2k views

Updating a ListItem that another user has edited

I have an event receiver that creates/updates/deletes publishing pages in a publishing library. In ItemUpdating, I get a handle to the page's underlying ListItem, change some of its properties and ...
3
votes
1answer
439 views

How can I undelete records from a SPList programmatically?

There is a SharePoint List from which many records have been deleted using CAML. The records are available in the Recycle Bin. Is there an way to recover the records using scripting/CAML etc ? Since ...
3
votes
2answers
289 views

SP2010 splistitem AND accessing css or style

I have an event receiver which adds splistitems from child sites to the parents site list (in a calendar). How do I access the css or style of an splistitem? I am wanting to color code the different ...
3
votes
1answer
121 views

Get actual item from SPRecycleBin

Similar to this question, I need to permanently delete only specific items from the recycle bin. I need to know more than just their names, however, and SPRecycleBinItem seems to have only have a ...
3
votes
2answers
188 views

Get Notified on List Item Changes - not using email

I'm searching for an easy way to display the latest changes of a sharepoint list. Situation: one huge list (10k entries) with a lot of daily changes (lets say 100). Target: Display the changes during ...
3
votes
2answers
715 views

Attach ListItem to TaskItem

I've created a custom approval worfkflow for an listitem. Now I need to see the values of the item in the taskitem. So I think one way would be to attach the ListItem to the TaskItem. Does anybody ...
3
votes
2answers
2k views

OnWorkflowItemChanged not firing when using SPListItem.Update()

I am experiencing a very weird behavior: After using SPListItem.Update() the OnWorkflowItemChanged is triggered (so the title is misleading), but sends the workflow into a sleep state it never wakes ...
2
votes
2answers
822 views

How to find a file with name = X in a SPList

Looking for recommendations. Have a file in a document library with name x.txt. In a workflow code behind, I need to get the file to read its contents. What is the best/most efficient way to do ...
2
votes
1answer
111 views

Exception when getting the value of field in SPListItem

Hi Guys I have this problem: I query a list using Caml. items = list.GetItems(query); This returns 6 items and works ok. Then I do: foreach (SPListItem item in items) { var title = ...
2
votes
2answers
963 views

How to add a blog post programmatically?

I'm trying to create a C# script that will allow me to import blog posts from a different system (exported as CSV) into a SharePoint blog. I have found a script for comments to a blog post, but I'm ...
2
votes
4answers
790 views

What is the best way to retrieve random item?

I would like to retrieve random item from SharePoint list. I have these approaches: Get random index and use list.items[randomIndex]. But I think that I retrieves all items from DB in this case. ...
2
votes
3answers
101 views

Get SPListItem by UniqueID

I'm trying to retrieve AN SPListItem from his UniqueID. I can have his document library url like http://mysharepoint.be/MYDOCUMENTLIBRARY but when i try to get the SPList from the name ...
2
votes
6answers
4k views

How can I auto-increment a column?

I am working on a solution where I have a list with a column named LogIDNumber. For each new entry in the list, I would like to increment the LogIDNumber by one. I could use the ID generated by ...
2
votes
3answers
2k views

Attempt to get property CheckOutType of SPFile cause 'System.NullReferenceException' exception

I have a strange situation: If the "Require Check Out" and "Create Major Versions" options are switched on for the current Document Library, then when I try to get the CheckOutType property I receive ...
2
votes
1answer
2k views

How to read an User field value for a list item

I've got a content type that contains a filed of the type user. When I want to read the ListItem I just get a string containing the users name instead of a object which contains Name, Username, E-Mail ...
2
votes
1answer
131 views

Help with getting the value of a look up field

Currently, I am using an ajax request to access the list items. The fields that are not lookups come as expected but the lookup fields come across as an ID of the object that corresponds to its ...