从Sharepoint列表中检索项目时间歇性失败 [英] Intermittent failure while retrieving items from a Sharepoint list

查看:48
本文介绍了从Sharepoint列表中检索项目时间歇性失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您知道造成这种间接异常的原因吗? 

Do you know what is causing this intermitent exceptions? 

推荐答案

您好,

要获取 列表项的计数,我们可以使用"lista.ItemCount" ;。如果列表不存在,则以下代码行将抛出异常。

To get count of list items, we can use "lista.ItemCount". If the list does not exists, the following line of code will throw exception.

SPList lista = web.Lists["MyList"];

我修改下面的代码作为参考:

I modify the code below for your reference:

try
{
	DateTime ini = DateTime.Now.AddDays(-7);
	Console.Write(ini.ToString("HH:mm:ss") + " - Connecting..");
	using (SPSite site = new SPSite("http://srvspdev01/subsite"))
	{
		using (SPWeb web = site.OpenWeb())
		{
			SPList lista = web.Lists["MyList"];
			int total = lista.ItemCount;
		}
		Console.ForegroundColor = ConsoleColor.Green;
		TimeSpan duracao = DateTime.Now.AddDays(-7) - ini;
		Console.WriteLine("OK: " + duracao.TotalSeconds.ToString() + "sec(s)");
		Console.ResetColor();
	}
}
catch (InvalidOperationException ioEx)
{
	string msgErro = string.Format("HResult: {0} - Source: {1} - Message: {2}", ioEx.HResult, ioEx.Source, ioEx.Message);
	Console.ForegroundColor = ConsoleColor.Red;
	Console.WriteLine("Erro: " + msgErro);
	Console.ResetColor();
}
catch (SPException spEx)
{
	string msgErro = string.Format("HResult: {0} - ErrorCode: {1} - Source: {2} - Message: {3}", spEx.HResult, spEx.ErrorCode, spEx.Source, spEx.Message);
	Console.ForegroundColor = ConsoleColor.Red;
	Console.WriteLine("Erro: " + msgErro);
	Console.ResetColor();
}
catch (Exception ex)
{
	string msgErro = string.Empty;
	Exception curEx = ex;
	do
	{
		if (!string.IsNullOrEmpty(curEx.Message) && !curEx.Message.Contains("One or more errors occurred"))
		{
			if (!string.IsNullOrEmpty(msgErro)) msgErro += "; ";
			msgErro += curEx.GetType().ToString() + " - " + curEx.Message;
		}
		curEx = curEx.InnerException;
	} while (curEx != null);
	Console.ForegroundColor = ConsoleColor.Red;
	Console.WriteLine("Erro: " + msgErro);
	Console.ResetColor();
}

我建议您提供有关基本要求的更多信息,为什么要在循环中添加代码?

I suggest you provide more information about your base requirement, why did you add the code in a loop?

最诚挚的问候,

丹尼斯


这篇关于从Sharepoint列表中检索项目时间歇性失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆