Sharepoint Smartpart 问题

发布于 2024-08-12 07:36:02 字数 751 浏览 9 评论 0原文

我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

尹雨沫 2024-08-19 07:36:02

AFAIK,自从 SharePoint 2003 以来,智能部件就不再被真正需要了。为什么不创建一个常规用户控件并将其放在 /ControlTemplates 文件夹中呢?如果适用,将其部署为具有相关代码的功能的一部分...

另外,更新您的 Web.Config 文件以显示有意义的错误消息:

  • customErrors=off
  • 通过将 CallStack=”true” 添加到 SafeMode 标记来启用堆栈跟踪
  • 设置编译调试属性设置为“true”

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:

  • customErrors=off
  • Enable Stack Traces by adding CallStack=”true” to the SafeMode tag
  • Set the compilation debug attribute to "true"
戒ㄋ 2024-08-19 07:36:02

附带说明一下,您通常应该将 SPSite 和 SPWeb 对象包装在 using 子句中,因为这些是非托管对象,如下所述:
http://msdn.microsoft.com/en-us/library/aa973248。 ASPX

protected void Button1_Click(object sender, EventArgs e)
{
 using (Microsoft.SharePoint.SPSite srv1 = new SPSite("http://server:port/"))
 {
  using (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);
   }
  }
 }
}

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

protected void Button1_Click(object sender, EventArgs e)
{
 using (Microsoft.SharePoint.SPSite srv1 = new SPSite("http://server:port/"))
 {
  using (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);
   }
  }
 }
}
末蓝 2024-08-19 07:36:02

好的,已经解决了,谢谢大家的信息和帮助。

这是关于信任级别,我在相关网站集的 web.config 文件中将推力级别设置为“WSS_Medium”。

<trust level="WSS_Medium" originUrl="" />

我在 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.

<trust level="WSS_Medium" originUrl="" />

I have found this solution (along with some more relevant information on subject) in Jan Tielen's blog at here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文