Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting ID of item after posting to a document library
    primarykey
    data
    text
    <p>I'm currently consuming information from Sharepoint 2010 using WCF Data Services from C# (an asp.net mvc4 application).</p> <p>With regular Sharepoint lists items, when saving the changes to the context, the id of the new item is automatically populated on the original object. Meaning:</p> <pre><code>SomeContext context = /* creation of the context*/; var someEntity = new SomeEntity {...}; context.AddToSomeEntityItems(someEntity); context.SaveChanges(); var newId = someEntity.Id; //this will have the new id </code></pre> <p>However, if what you are creating is an item for a document library, the id doesn't seem to be updated on the saved entity. For example:</p> <pre><code>SomeContext context = /* creation of the context*/; var someOtherEntity = new SomeOtherEntity {...}; Stream data = /* some stream*/; context.AddToSomeOtherEntityItems(someOtherEntity); context.SetSaveStream(someOtherEntity, data, true, "SomeMIMEType", "SomeSlugPath"); context.SaveChanges(); var newId = someOtherEntity.Id; //this will instead always have 0 </code></pre> <p>I initially thought this was a bug in the first version of WCF Data Services so I updated to the latest, <a href="http://nuget.org/packages/Microsoft.Data.Services.Client/5.4.0" rel="nofollow">5.4.0</a>. But the behavior seems to be the same.</p> <p>I would prefer to have to avoid strange lookups that ultimately could fail during heavy load, such as using <code>.OrderByDescending(x =&gt; x.Id).First()</code> to get the recently created item.</p> <p>When looking at the actual network traffic using Fiddler, I can see that the initial upload of the binary data actually does return the information for the item along with its ID. And if I configure other relationships to that item using <a href="http://msdn.microsoft.com/en-us/library/system.data.services.client.dataservicecontext.setlink%28v=vs.95%29.aspx" rel="nofollow">SetLink</a> prior to saving changes they are linked correctly, so the context does handle the value accordingly.</p> <p>Is there any way to get WCF Data Services to update the ID on the entity when the item is for a document library?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload