Sharepoint errors

老子叫甜甜 提交于 2019-12-13 04:16:46

问题


I have created a .net web part and deployed it on the sharepoint site. When I preview it, the sharepoint throws up an error saying "An error occured when previewing the Web Part"

The code in the web part is as follows

        Dim myweb As Microsoft.SharePoint.SPWeb = Microsoft.SharePoint.WebControls.SPControl.GetContextWeb(Context)
        'Dim mylist As Microsoft.SharePoint.SPList = myweb.Lists(System.Configuration.ConfigurationSettings.AppSettings("BedList").ToString())
        Dim mylist As Microsoft.SharePoint.SPList = myweb.Lists("{80F6F320-E1F5-42EB-A2FB-895EAE00F589}")
        Dim items As Microsoft.SharePoint.SPListItemCollection = mylist.Items

        For Each item As Microsoft.SharePoint.SPListItem In items
            returnString = returnString + "<br/>" + item("Status").ToString() + " For " + item("Title").ToString + "<br/>"
        Next

Does anyone know why this would not work. I can not get hold of the execption thrown. any help would be greatful


回答1:


First you should make your exceptions visible by changing the following in the web.config

CallStack = true

    <SafeMode MaxControls="200" CallStack="true" DirectFileDependencies="10" TotalFileDependencies="50" AllowPageLevelTrace="false">

CustomErrors = Off

<customErrors mode="Off" />

Then you will see the real exception

You can also try obtain the current web using the following code:

Dim myweb As Microsoft.SharePoint.SPWeb = SPContext.Current.Web

Other problem could be related with wrong listId ou ListName when you try to obtain the list.

Hope it helps




回答2:


You could try checking whether myList is nothing before doing myList.Items




回答3:


Also look for <compilation..> tag and set it to

<compilation debug="true"..>




回答4:


Did you add the "BedList" key to the correct web.config file?



来源:https://stackoverflow.com/questions/590047/sharepoint-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!