Antony Delaney
Antony Delaney

Reputation: 1168

Sharepoint errors

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

Upvotes: 0

Views: 1064

Answers (4)

Tudor Olariu
Tudor Olariu

Reputation: 1328

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

Upvotes: 0

Anders Rask
Anders Rask

Reputation: 862

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

<compilation debug="true"..>

Upvotes: 0

Paulo Oliveira
Paulo Oliveira

Reputation: 218

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

Upvotes: 3

Paul Rowland
Paul Rowland

Reputation: 8352

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

Upvotes: 0

Related Questions