问题
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