문제

업로드 된 Excel 파일에서 새 목록을 만들려면 문서 라이브러리에 이벤트 수신기를 작성하고 있습니다. ItemAdded () 및 itemUpdated () 이벤트에서 실행됩니다.

목록에 새 항목을 추가 할 방법을 호출하기 전에 이전 항목을 지우는 데 필요한 경우 처음에는 전통적인 방식으로 이것을 시도했습니다 (내림차순 주문 및 모든 레코드 삭제) 및 이제 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])); 라인에 도달하면 debuggin이

문서 업로드 화면으로 다시 제어되며 대부분의 시간은 나머지 코드가 없지만 레코드가 실제로 낮 으면 (<100)이면 제어를 처리하고 다음 줄로 제어합니다 (InsertIntoList(ExcelRecords, site.OpenWeb().Lists[listName].Items);) .

스레드 문제가 발생할 수 없으면 ProcessBatch가 작업을 완료 할 때까지 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