Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to retrieve list item attachments with SharePoint 2013 Event Receiver in correct order
    primarykey
    data
    text
    <p>I've created a Standard SharePoint 2013 Event Receiver on a custom list.</p> <p>Watched Event = "ItemAdded".</p> <p>Later in my code I need to retrieve the attachments of the list item in the same order as the user inserted them. But unfortunately it seems that SharePoint does not do this by Default.</p> <p><strong>Example</strong>:</p> <p>The User creates a list item and attach the following files</p> <p>Picture_front.jpg</p> <p>Picture_back.png</p> <p>Picture_231.jpg</p> <p>Now in my Event Receiver it is possible that I first get 'Picture_back' then 'Picture_front'... or in any other order.</p> <p>How can I retrieve the attachments in the same order as they have been attached to the list item? I tried to use the <strong>SPFile Property 'TimeCreated'</strong> but this is also not working... They got the same timestamp :( (also if I am using 'Ticks')</p> <p>Any ideas or I am doing something wrong?</p> <p><strong>Here is my Code:</strong></p> <pre><code> public override void ItemAdded(SPItemEventProperties properties) { SPAttachmentCollection attachments = properties.ListItem.Attachments; if (attachments.Count &gt; 0) { int p = 1; Dictionary&lt;string, string&gt; attachementDict = new Dictionary&lt;string, string&gt;(); try { foreach (string attachement in attachments) { SPFile attachementFile = properties.ListItem.ParentList.ParentWeb.GetFile(properties.ListItem.Attachments.UrlPrefix + attachement); string imageUrlPath = properties.WebUrl + attachementFile.ServerRelativeUrl; string imageTimestamp = attachementFile.TimeCreated.Ticks.ToString(); // This Dict is used lator for sorting // but at the Moment I get here the error that the same key already exists because of the same timestamp of the files :( attachementDict.Add(imageTimestamp, imageUrlPath); } } catch (Exception ex) { // SPLog } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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