34

This is related how instance of SPListItem is being created. Actually in both cases new item is added to the collection of items in list, in first case new item is added explicitly, in the second one implicitly. The point is, that for initializing collection of items in list is used the same method GetItems but with different queries. SPList.Items.Add()...


18

Assuming that you already have a reference to the list item (called "item" in the following code sample), you must first get a reference to the list field and then use the GetFieldValue method to read the actual value. SPFieldUser userField= (SPFieldUser)item.ParentList.Fields.GetFieldByInternalName(internalName); var fieldValue = ((SPFieldUserValue)...


17

You can use one of the SPUtility.ParseDate overloads. Check the article Converting Date and Time Values for more details.


15

Here is the solution: [Microsoft.SharePoint.SPUser]$spuser = $spWeb.EnsureUser("domain\username") $spListItem[$newSMTName] = $spuser $spListItem.Update()


15

You can also use SPQuery and a CAML query, like below. I also agree with what Dave Wise said about PortalSiteMapProvider class. SPQuery query = new SPQuery(); query.Query = "<Where><Eq><FieldRef Name=\"Title\" /><Value Type=\"Text\">YourTitle</Value></Eq></Where>"; query.RowLimit = 1; query.ViewFields = ""; ...


13

You load multiple items. A conflict occurs. Collect all items you need and call "load". After you call load for all items, then run context.executeQueryAsync. Save your selected items as a global variable (this.items): function showTitles(urlColumnName) { var context = new SP.ClientContext.get_current(); var web = context.get_web(); var lists = web....


13

Try this (Excerpt from here): function getListItem(url, listname, id, complete, failure) { // Getting our list items $.ajax({ url: url + "/_api/web/lists/getbytitle('" + listname + "')/items(" + id + ")", method: "GET", headers: { "Accept": "application/json; odata=verbose" }, success: function (data) { // ...


12

A simple solution is to just validate the fields on submit by adding a validation rule in the list settings. Go to List Settings Open Validation settings under the General Settings area In the formula add your formula, I think it will be like this in your scenario: =OR(IF(ISBLANK(TargetPage),NOT(ISBLANK(ExternalURL))),IF(ISBLANK(ExternalURL),NOT(ISBLANK(...


12

The ItemCount function could be applied to List resource, for example: /_api/web/lists/getbytitle('<list title>')/ItemCount but not to ListItemCollection resource You could consider the following options of getting items count for list items: Option 1 How to return items count from json result: var endpointUrl = _spPageContextInfo....


11

If you use linq to object, you always retrieve ALL records from DB. It is not good if you have got a lot of data. To reduce records you can use CAML query: SPQuery query = new SPQuery(); query.Query = "<Where>" + "<Eq>" + "<FieldRef Name=\"FileLeafRef\"/>" + "<...


10

private IEnumerable<string> GetAttachmentUrls(SPListItem item) { return from string fileName in item.Attachments orderby fileName select SPUrlUtility.CombineUrl(item.Attachments.UrlPrefix, fileName); }


9

I found answer for my question. private string GetAttachmentUrls(SPListItem oItem) { string path = string.Empty; try { path = (from string file in oItem.Attachments orderby file select SPUrlUtility.CombineUrl(oItem.Attachments.UrlPrefix, file)).FirstOrDefault(...


9

AS PER MSDN SPList.ItemCount: The value of the ItemCount property includes folders within a document library, as well as files within subfolders. The value of the Count property of the SPListCollection class does not include folders. SPListItemCollection.Count: Gets the number of list items in the collection, excluding folders. BUT Although it's ...


8

Assuming the field type of "validfrom" is DateTime then there should be no need to convert the value, only cast it. You only need to convert/parse if your field type is text, in which case you may consider switching your type to a DateTime or use Marek's advice for conversion. DateTime validFrom = (DateTime) item["validfrom"];


8

If fetching of item["ID"] instead of 'Title' works AND If you are using the SPQuery object. Then, include the columns that you want to fetch in the ViewFields property of SPQuery. This will resolve your issue. Reference: http://discoverlars.wordpress.com/2012/01/24/argumentexception-value-does-not-fall-within-the-expected-range-error-using-fields-on-...


7

Each item has a created date and modified date which you can get through the indexer. item["Created"];


7

We might have to manipulate/update the data without changing the Modified or Modified By fields to meet the business needs and also retaining the document/Item status without incrementing the version is also important aspect to be considered. In such cases SystemUpdate() method of SPListItem can be leveraged. This basically updates the content database with ...


7

Use below code to get User name: new SPFieldLookupValue(properties.ListItem["Staff Member"].ToString()).LookupValue; For User ID: new SPFieldLookupValue(properties.ListItem["Staff Member"].ToString()).LookupId;


6

Is there data in the field that you are calling .ToString on? It sounds like maybe the field is null.


6

I anticipate that your root list has the same event receiver assigned to it, and that causes the recursion. The problem, of course, may be not so obvious, but anyway, to prevent event receiver to fire several times, there is a common practice in SharePoint: just use DisableEventFiring and EnableEventFiring methods. internal void UpdateItemOnRootwebList(...


6

The PortalSiteMapProvider is the fastest way to access content and you should be able to do what you need with that.


6

You can use the SPWeb GetFile method to retrive the SPFile located at a specified url. Try something like this: SPFile file = SPContext.Current.Web.GetFile(string.Format("{0}/{1}", x, y));


6

You can retrieve the value by using item.Properties["Name"] instead. We ran into the same problem and while I wasn't able to find a root cause this worked as a fix.


6

SharePoint does not provide a method of restarting a workflow. You can however cancel a running workflow and start it again. A good example of canceling a running workflow can be found here: http://blog.brianfarnhill.com/2008/10/how-to-cancel-a-workflow-programmatically The snippit of code below will start your workflow. private static void StartWorkflow(...


6

The objects you get from $list.Folders are SPListItems not SPFolders so the ListItems property gives the Lists ListItemCollection not something for the folder. To get the SPFolder you have to access $folder.Folder. If what you're working with is a document library, then it's easy just access $folder.Folder.Files and you'll get the files in the SPFolder, ...


6

Make sure that the column you include in the where clause is defined as an indexed column in SharePoint. You can check by going to the list you're querying and into List -> Settings -> Indexed Columns. It's not applicable in your CAML query, but if you have more than one 'where', ensuring the first where hits an indexed column can increase efficiency. ...


6

get the item in SPlistitem and then get value from it. For ex = Splistitem item = list.getitembyid(1); var x = item.ID;


6

In SharePoint ID is a counter and always incremental. Even though you delete item, it is never going to occupy the blank ID. It always keeps on incrementing. Also list.Items always return SPListItemCollection. But when you delete the item from List, the index of Item keeps on changing. For example, you had 10 items in list list.Items[9] will give you the ...


5

The item["Created"] field will store the date and time that item was created. Cast it to a DateTime type to do your comparison.


5

The other answers work, but you may want to consider: item[SPBuiltInFieldId.Created]; I'm never sure what happens to the default field names in non-English language setups.


Only top voted, non community-wiki answers of a minimum length are eligible