1

カスタム リストに標準の SharePoint 2013 イベント レシーバーを作成しました。

監視イベント = "ItemAdded".

コードの後半で、リスト アイテムの添付ファイルをユーザーが挿入した順序で取得する必要があります。残念ながら、SharePoint はデフォルトでこれを行わないようです。

ユーザーがリスト アイテムを作成し、次のファイルを添付します。

写真_正面.jpg

Picture_back.png

写真_231.jpg

これで、イベント レシーバーで、最初に「Picture_back」を取得してから「Picture_front」を取得する可能性があります...またはその他の順序で取得できます。

リスト アイテムに添付されたのと同じ順序で添付ファイルを取得するにはどうすればよいですか? SPFile プロパティ 'TimeCreated'を使用しようとしましたが、これも機能しません...同じタイムスタンプを取得しました :( ('Ticks' を使用している場合も)

アイデアはありますか、それとも何か間違っていますか?

ここに私のコードがあります:

    public override void ItemAdded(SPItemEventProperties properties)
        {

            SPAttachmentCollection attachments = properties.ListItem.Attachments;

            if (attachments.Count > 0)
            {
                int p = 1;
                Dictionary<string, string> attachementDict = new Dictionary<string, string>();

                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
                }
       }
4

2 に答える 2