Sharepoint Smartpart 问题
我对 Sharepoint 编程非常陌生,就像我团队的其他成员一样。我们决定使用智能部分作为共享点和我们的开发工作之间的桥梁。经过一番努力,我们将其启动并运行。然而,问题是,当我使用一个简单的用户控件进行测试时,使用 sharepoint om 代码获取文档库中的文件名,sharepoint 给了我一个相当有用的“发生了未知错误”。这段代码在 aspx 页面中工作得很好。我编写了另一个简单的测试用户控件,它只执行 Response.Write() 行来检查执行代码是否存在问题,但这个控件在智能部分也运行得很好。
代码就像
protected void Button1_Click(object sender, EventArgs e)
{
Microsoft.SharePoint.SPSite srv1 =
new SPSite("http://server:port/");
SPWeb web = srv1.OpenWeb();
var list = web.GetFolder("http://server:port/documentLibrary");
for (int i = 0; i < list.Files.Count; i++)
{
ListBox1.Items.Add(list.Files[i].Name);
}
}
我们可能遗漏或做错了什么? 提前非常感谢...
I am very new to Sharepoint programming, like the rest of my team is. We have decided to use smart part as our bridge between sharepoint and our development efforts. After some effort we got it up and running. However, the problem is, that when i use a simple user control for test, with sharepoint om code that gets names of files in a document library, sharepoint gives me a rather helpful "An unknown error has occured". This code works just fine when inside an aspx page. I have written another simple test user control that just executes a Response.Write() line to check is there a problem with executing code, but this one works just fine in smart part too.
Code goes like
protected void Button1_Click(object sender, EventArgs e)
{
Microsoft.SharePoint.SPSite srv1 =
new SPSite("http://server:port/");
SPWeb web = srv1.OpenWeb();
var list = web.GetFolder("http://server:port/documentLibrary");
for (int i = 0; i < list.Files.Count; i++)
{
ListBox1.Items.Add(list.Files[i].Name);
}
}
Anything we may be missing or doing wrong?
Many thanks in advance...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
AFAIK,自从 SharePoint 2003 以来,智能部件就不再被真正需要了。为什么不创建一个常规用户控件并将其放在 /ControlTemplates 文件夹中呢?如果适用,将其部署为具有相关代码的功能的一部分...
另外,更新您的 Web.Config 文件以显示有意义的错误消息:
AFAIK, Smart Part hasn't been really needed since SharePoint 2003. Why don't you just create a regular user control and plop it in the /ControlTemplates folder? Deploy it is as part of a Feature with related code, if appropriate...
Also, update your Web.Config file to display meaningful error messages:
附带说明一下,您通常应该将 SPSite 和 SPWeb 对象包装在 using 子句中,因为这些是非托管对象,如下所述:
http://msdn.microsoft.com/en-us/library/aa973248。 ASPX
Just a side note, you should generally wrap your SPSite and SPWeb objects in a using clause as these are unmanaged objects as outlined here:
http://msdn.microsoft.com/en-us/library/aa973248.aspx
好的,已经解决了,谢谢大家的信息和帮助。
这是关于信任级别,我在相关网站集的 web.config 文件中将推力级别设置为“WSS_Medium”。
我在 Jan Tielen 的博客 这里
Ok it's solved, thanks everybody for information and help.
It was about trust level and i set thrust level to "WSS_Medium" in relevant site collection's web.config file.
I have found this solution (along with some more relevant information on subject) in Jan Tielen's blog at here