splistitem

Setting author field in SPListItem won't persist

I am trying to copy an SPListItem (with file) from one site collection to another. I do this by creating the file like this: var archiveFile = newsArchive.Lists[listName].RootFolder.Files.Add(originalItem.File.Name, originalItem.File.OpenBinary()); var archiveItem = archiveFile.Item; through a utility method I wrote i then set all fie...

SharePoint SPListItem.ContentType.Name - "Message" vs "Discussion" ?

I am writing a C# code to find all of our SharePoint Sites that have emails contained in the Email List page. It appears that some of our email messages are SPListItem.ContentType.Name = "Message" and some of our email messages are SPListItem.ContentType.Name = "Discussion" Aside from the confusion, this is forcing my to cycle through m...

How to copy a DataTable to a SharePoint SPList?

I have my source list data in the sourceList data table and want to copy that data to its root list. How can I do that? private void MoveToTopTaskList(DataTable sourceList, SPSite DestinationSiteCollection) { SPWeb Destinationsite = DestinationSiteCollection.OpenWeb(); SPList DestinationList = Destinationsite.Lists[TASKS]; ...

How to use HTTPContext for SPList

I have the following requirement. public void GetSubSite(SPWeb site) { site.AllowUnsafeUpdates = true; SPList destinationList = site.Lists[TASKS]; SPWebCollection subSitesCollection = site.Webs; foreach (SPWeb subSite in subSitesCollection) { //..... Now I want to display the destinationList as a web part,...

How to copy SPListitem from one SPList to Another SPList

I have requirement to copy items from one SPList to another, Here is the code which is not working: public void CopyList(SPList src) { //Copy items from source List to Destination List foreach (SPListItem item in src.Items) { if(isUnique(item.UniqueId)) { foreach (SPField field in src.Fields) { ...

SharePoint: How to create/delete multiple items in a transaction

Hi I am trying to delete multiple items in a sharepoint list. But the constraint is : either all the items should be deleted or not a single item should be delted.In short I am looking for trasactional behavior in SharePoint.I tried to use ProcessBatchData() function. But it seems that it doesnt fulfill my requirement. Is there any othe...

How to hide SPListItem

hi I want to hide a particular SPListitem , want only visible to the Admin. how can i do that? thanks Azra ...

Find latest approved version of an SPListItem

I am trying to iterate through the SPListItem.Versions collection to find the latest approved list item. My list item has three versions: the first two are approved, the last is in draft. But my code says they're all in draft! Please help! // Iterate through all versions for (int index = 0; index < item.Versions.Count; index++) { S...

When is SPFile.Properties != to SPFile.Item.Properties in SharePoint?

One of our customers has a problem that we cannot reproduce. We programmatically copy a document's properties to a destination file using SPFile.Properties. However, for some reason the file's properties do not match the meta data specified on the list the file is stored in. Now, we can probably solve this by copying SPFile.Item.Propert...

Iterating through a SPListItem/SPList

Hi guys, I'm making a checklist for people to do tasks on our company website. The feature I'm working on right now is that once they complete a task and mark it as done, I want our sharepoint webpart to send an email to them containing a list of what they still need to finish. Since the powers that be want to be able to add and subtra...

SPList Item get value - ArgumentException

Hi All, I have got a SPListItem and i have an array of column names. When i try to access the SPListItem values using the code below: for(int i=0;i<arrColName.length;i++) { string tempValue = item[arrColName[i]].ToString(); // Works fine in case the the specific column in the list item is not null // Argument exception - V...

Finding SharePoint list item by its display form's URL

Sometimes users require to change information in SharePoint list item that is not editable for them, for instance, a field that is hidden in edit form (in my case it was the records number). I decided to create a small Windows GUI application that the administrator would run on the server and make the requested change. However, the simp...

SharePoint: Apply source ContentType to destination when copying a SPListItem

Greetings, I've written my own ContentType definition that can be applied to any Document Library. I would like to preserve the data associated with an item via my ContentType when that item is copied by the user to a Document Library to which my ContentType definition is not yet attached. The obvious thing to do, it seems, is to catc...

C# - Insert/Update multiple lookup values to an SPListItem

My SharePoint list has a column that allows multiple lookup values. My C# control (within a webpart) allows the user to make multiple selections from a list box. I split these values into an array - each array member being a selected value that needs to be updated in the same SPListItem column. I know that the selections are being p...

I am adding a new splistitem to a sharepoint list but it always gives me an exception: "object reference not set to an instance of an object"

_site = new SPSite("http:\\MySite"); _web = site.OpenWeb(); { list = _web.Lists[sListName]; _web.AllowUnsafeUpdates = true; items = list.Items; item = items.Add(); item["Title"] = "new Title"; item["UserName"] = CurrentUser.ToString(); item["Configuration"] = sConfiguration.ToString(); } item.Update(); _web.Allo...

Copying List Items from Master List to sub sites

I have a site which contains a custom list Master. I have a number of sub sites which contain copies of this list. When someone edits or adds a new list item to the master list, I would like all sub sites to be updated accordingly by an event handler which is associated with the master list. e.g. if item is added, add it to the list of ...

How do I stall until a SharePoint List Item is Deleted with SPLongOperation?

I have a workflow, which creates a task and deletes it after the task is edited and its useful information acquired. I created a custom edit form for the task, so I have an SPLongOperation that I can use to stall the page. This is necessary, because if I don't stall the page in some fashion, the person will see the task in the task list ...

Can I retrieve additional fields for a SPListItem from SPQuery which had ViewFields set?

I am retrieving SPListItems from SPList with a SPQuery that has ViewFields set. I am using ViewFields to improve performance. However, for some items, I need additional data. I know I can just retrieve the single item again with a new query. However, I am wondering, is there a more efficient way that would allow me to just pull the addit...

Workflow lock "edit item"

Is it possible to disable "edit item" in a Sharepoint List when a custom workflow is running? Maybe a property in the workflow that can be affected? Thanks, David Esteves ...

SharePoint List - Copy SPListItem ID

I have a solution that copies all the content of SharePoint lists to a file, and then copies the content of the file back onto SharePoint (used for backups and stage / live environment switches). Now I can copy all the fields I need except for one : ID I understand that it is a read only field, but some other read only fields can be up...