Solving the “User cannot be found” error with SPFile.Author
来源:互联网 发布:java开发项目说明文档 编辑:程序博客网 时间:2024/06/05 09:41
I ran into a bug today that was a bit unusual. We have a custom ASP.NET page that shows information from a custom list in SharePoint 2007. That page shows details, including the Author, for attachments. On one particular list item, users started getting a “User cannot be found” error whey they tried to view it with our custom page. The stack trace showed that it was getting the error in Microsoft.SharePoint.SPFile.get_Author().
It turns out that SPFile stores the user as a login name and tries to resolve the name using SPWeb.SiteUsers, which throws an error if the login name is not found. The issue was, in this case, the attachment author had been removed from Active Directory and was no longer in SharePoint’s user list, hence the error.
The fix is to go directly to the SPFile properties and get the login name. Since we can no longer resolve the login name to a user display name, we just display the login name.
string GetAuthorName(SPFile file)
{
SPUser author = null;
try { author = file.Author; } catch { }
return (author == null) ? (string)file.Properties["vti_author"] : author.Name;
}
- Solving the “User cannot be found” error with SPFile.Author
- MyEclipse Error: The Table cannot be found on the database
- MyEclipse Error: The Table cannot be found on the database
- The page cannot be found
- [ERROR] The service cannot be found for the endpoint reference (EPR) /axis2...
- Stacktrace:] with root cause The Struts dispatcher cannot be found. This is usually caused by using
- Error creating bean with name 'XXX' in the [XXXX.xml] --The import XXX cannot be resolved
- The Struts dispatcher cannot be found
- The Struts dispatcher cannot be found
- 关于The resource cannot be found.
- The Struts dispatcher cannot be found....
- The Struts dispatcher cannot be found.
- The Struts dispatcher cannot be found
- The Struts dispatcher cannot be found.
- The Struts dispatcher cannot be found
- The Struts dispatcher cannot be found.
- The Struts dispatcher cannot be found.
- The Struts dispatcher cannot be found.
- ORA-27054: NFS file system where the file is created or resides is not mounted with correct options
- 利用GZIP压缩网页相关知识
- 今天终于明白JS对象了。
- iPhone中Png图片格式的研究
- 多对多关联查询 ManyToMany
- Solving the “User cannot be found” error with SPFile.Author
- CSP开发——基本函数详解1
- AD属性对照表
- php curl选项列表(大全)
- C++小品:她来听我的演唱会——C++11中的随机数、线程(thread)、互斥(mutex)和条件变
- SVN软件开发版本管理
- C# HashTabable
- C++类模版特化
- 成都计委原副主任贪污640万获刑:自己太自信-党员领导-贪污罪-计委