Trying to create a custom webpart and install it into Sharepoint. I'm aware that there are many walkthroughs and instructions on how to do this, but none seem to work. Most don't seem to be written for VS2008, which adds another complication.
Any time the webpart is installed (in the /bin folder or the GAC) I receive the following error, "Could not load file or assembly 'WebPart1' or one of its dependencies. Access is denied." It brings down the entire SharePoint site.
Here are the steps I took:
1. Installed the Microsoft SharePoint toolkit for VS2008.
2. Created a new C# webpart project called WebPart1.
3. Confirmed the strong name key was automatically created.
4. Confirmed the project name, default namespace, and class name were all WebPart1.
5. Confirmed the output type was a .NET 3.5 Class Library.
6. Confirmed references were made to the following DLLs:
- Microsoft.SharePoint
- System
- System.Web
- System.XML
7. Built the project and copied the WebPart1.dll to /windows/assembly
8. Retrieved the public key from the dll and posted the following safe control in the web.config
<SafeControl Assembly="WebPart1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5" Namespace="WebPart1" TypeName="*" Safe="True" />
9. Ran an IIS reset.
** Ran the website at this point, and received the error listed above. **
10. Tried creating a WebPart1.dwp file and imported it into the webpart gallery.
** Clicked on the webpart listed in the gallery, and the following error is thrown. **
"A Web Part or Web Form Control on this Web Part Page cannot be displayed or imported because it is not registered on this site as safe."
I suspect I'm missing something simple, but can't find it. If anyone has any tips, I'd greatly appreciate it.
Thanks,
- Brad
Just in case, here is the code (Pretty much straight defaults out of the blank WebPart template):
WebPart1.cs
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace WebPart1
{
[Guid("b1183988-0aab-4886-a442-b2fbf1978444")]
public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart
{
public WebPart1()
{
}
protected override void CreateChildControls()
{
base.CreateChildControls();
// TODO: add custom rendering code here.
// Label label = new Label();
// label.Text = "Hello World";
// this.Controls.Add(label);
}
}
}
WebPart1.webpart
<?xml version="1.0" encoding="utf-8"?>
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<!--
The following Guid is used as a reference to the web part class,
and it will be automatically replaced with actual type name at deployment time.
-->
<type name="b1183988-0aab-4886-a442-b2fbf1978444" />
<importErrorMessage>Cannot import WebPart1 Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name="Title" type="string">WebPart1 Web Part</property>
<property name="Description" type="string">WebPart1 Description</property>
</properties>
</data>
</webPart>
</webParts>
WebPart1.dwp
<?xml version="1.0" encoding="utf-8"?>
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2" >
<Title>WebPart1</Title>
<Description>WebPart1.</Description>
<Assembly>WebPart1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5</Assembly>
<TypeName>WebPart1</TypeName>
</WebPart>
AssemblyInfo.cs
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("WebPart1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Licensed Company")]
[assembly: AssemblyProduct("WebPart1")]
[assembly: AssemblyCopyright("Copyright © Licensed Company 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("4f1683bb-1bc4-41b4-8709-608a95da766f")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: CLSCompliant(true)]