尝试返回文档时出现对象错误(Umbraco Document API)
我正在研究一种递归方法,显示我有权查看的所有文档。第一遍工作得很好,但是当它递归地调用自身并传递当前文档子级的文档数组时,它会抛出错误:
对象引用未设置为 对象的实例。描述:安 期间发生未处理的异常 当前网络的执行 要求。请检查堆栈跟踪 有关错误的更多信息 以及它在代码中的起源。
异常详细信息: System.NullReferenceException:对象 未设置对实例的引用 对象。
这是代码:
protected void Page_Load(object sender, EventArgs e)
{
lblTest.Text = "Data<br /><br />";
Document[] releaseDocs = Document.GetRootDocuments();
displayDocs(releaseDocs);
}
public void displayDocs(Document[] releaseDocs)
{
string docPermissions = null;
User currentUser = User.GetCurrent();
foreach (var doc in releaseDocs)
{
docPermissions = currentUser.GetPermissions(doc.Path);
if ((docPermissions.Contains("F")) && (docPermissions.Contains("U")))
{
lblTest.Text += "D/T: " + doc.CreateDateTime + "<br />\r\n";
lblTest.Text += "Level: " + doc.Level + "<br />\r\n";
lblTest.Text += "Text: " + doc.Text + "<br />\r\n";
lblTest.Text += "<hr />\r\n";
if (doc.HasChildren)
{
Document[] childDocs = Document.GetChildrenForTree(doc.Id);
displayDocs(childDocs); //error occurs here
}
}
}
}
I'm working on a recursive method that displays all documents I have permissions to see. The first pass works great, but when it calls itself recursively passing a document array of the current document's children it throws an error:
Object reference not set to an
instance of an object. Description: An
unhandled exception occurred during
the execution of the current web
request. Please review the stack trace
for more information about the error
and where it originated in the code.Exception Details:
System.NullReferenceException: Object
reference not set to an instance of an
object.
Here's the code:
protected void Page_Load(object sender, EventArgs e)
{
lblTest.Text = "Data<br /><br />";
Document[] releaseDocs = Document.GetRootDocuments();
displayDocs(releaseDocs);
}
public void displayDocs(Document[] releaseDocs)
{
string docPermissions = null;
User currentUser = User.GetCurrent();
foreach (var doc in releaseDocs)
{
docPermissions = currentUser.GetPermissions(doc.Path);
if ((docPermissions.Contains("F")) && (docPermissions.Contains("U")))
{
lblTest.Text += "D/T: " + doc.CreateDateTime + "<br />\r\n";
lblTest.Text += "Level: " + doc.Level + "<br />\r\n";
lblTest.Text += "Text: " + doc.Text + "<br />\r\n";
lblTest.Text += "<hr />\r\n";
if (doc.HasChildren)
{
Document[] childDocs = Document.GetChildrenForTree(doc.Id);
displayDocs(childDocs); //error occurs here
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Document.GetChildrenForTree(doc.Id) 方法是否有可能返回 null?
Is it possible that the Document.GetChildrenForTree(doc.Id) method returns a null?