我在连接到 Sharepoint 的 Web 服务中有以下代码:
string response = string.Empty;
SPSecurity.RunWithElevatedPrivileges(new SPSecurity.CodeToRunElevated(delegate()
{
using (SPSite spsite = new SPSite("http://sharepoint/"))
{
using (SPWeb spweb = spsite.OpenWeb("sites/" + site))
{
spweb.AllowUnsafeUpdates = true;
SPFolder spfolder = spweb.GetFolder(path);
/* The following value will always be set to FALSE
* but the next time spfolder.Exists is called, the
* returned value will be true.
*/
//bool exists = spfolder.Exists;
if (spfolder == null || !spfolder.Exists)
response = "Folder Does Not Exist!";
else
response = "Folder Exists!";
}
}
}
return response;
如果我从顶部开始逐步调试它,上面的代码工作得非常好。如果我在没有调试的情况下运行它,或者如果我稍后在代码中的某处放置断点,则 SPFolder.Exists 值始终设置为 false,而实际上它应该为 true。如果我取消注释bool exists
上面的行,那么它会正常工作。
我在这里做错了吗?