質問

ドキュメントライブラリのイベント受信機を書き込んで、アップロードされたExcelファイルから新しいリストを作成しています。 ItemAdded()とitemupdated()イベントで実行されます。

リストに新しい項目を追加する前に古いアイテムをクリアする必要がある場合は、最初は従来の方法(降順で繰り返し、すべてのレコードを削除し、htef="http:/でこれを試してみました。 /merill.net/2008/02/effiewiotly-delete-purge-all-items-from-a-sharepoint-list/ "rel=" nofollow "> processbatchdata

 using (SPSite site = new SPSite(properties.WebUrl))
                        {
                            if (site.OpenWeb().Lists[listName].Items.Count > 0)
                            {
                                var deleteBatch = site.OpenWeb().ProcessBatchData(BuildBatchDeleteCommand(site.OpenWeb().Lists[listName]));
                            }
                            InsertIntoList(ExcelRecords, site.OpenWeb().Lists[listName].Items);
                        }
.

ProcessBatachDataは何らかの性が良いですが、それでも正確ではありません問題は、コントロールが行var deleteBatch = site.OpenWeb().ProcessBatchData(BuildBatchDeleteCommand(site.OpenWeb().Lists[listName])); に達するとデバッグです。

ドキュメントのアップロード画面にコントロールを取り戻すと、ほとんどの時間は残りのコードにヒットしませんが、レコードが実際に低い(<100)、次の行にコントロール(InsertIntoList(ExcelRecords, site.OpenWeb().Lists[listName].Items);)を実行します。 。

スレッドの問題が発生することができない場合は、ProcessBatchがそのジョブを終了し、次の行に移動するまで、いつかスリープするようにスレッドを切り替えると、スレッドが実行されます。

完全な機能はのように見えます

 public override void ItemUpdated(SPItemEventProperties properties)
        {
            UpdateMarketingCalendar(properties);
            base.ItemUpdated(properties);
        }


private void UpdateMarketingCalendar(SPItemEventProperties properties)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                try
                {
                    using (SPSite site = new SPSite(properties.WebUrl))
                    {
                        SPList list = site.OpenWeb().Lists[listName];

                        bool recordsRetrieved;
                        DataTable ExcelRecords = GetRecordsFromExcel(properties.ListItem, out recordsRetrieved);

                        if (recordsRetrieved)
                        {
                            if (list.ItemCount > 0)
                            {
                                var deleteBatch = site.OpenWeb().ProcessBatchData(BuildBatchDeleteCommand(list));
                            }
                            InsertIntoList(ExcelRecords, list.Items);
                        }
                    }
                }

            });
        }
.

オタク正しい方向を向いてください。 私はあなたに助けと時間をかなっています。

Vishal

役に立ちましたか?

解決

This is probably not the root cause of your performance issues, but part of it. Your code is written in a quite inefficient way, opening webs to the right and left and looking for the list multiple times. Something like this does the same thing but more efficiently:

If your feature is web scoped:

    var web = properties.Feature.Parent as SPWeb;

if site scoped

    var site = properties.Feature.Parent as SPSite;
    if(site == null) return;
    var web = site.OpenWeb(properties.WebUrl);

and as MdMazzotti pointed out you would actually need to dispose the web in this scenario, I would use the using statement, replace the last line with this:

using(var web = site.OpenWeb(properties.WebUrl)){

and add an extra } at the end of the following :

    if(web == null || !web.Exists) return;

    var list = web.Lists[listName]
    if (list != null && list.Items.Count > 0)
    {
        var deleteBatch = web.ProcessBatchData(BuildBatchDeleteCommand(list));
    }

    InsertIntoList(ExcelRecords, list.Items);
}
ライセンス: CC-BY-SA帰属
所属していません sharepoint.stackexchange
scroll top