C# .NET - Web Part Error

Asked By Maria Raja Kumar
17-Nov-06 12:51 AM

Hello Friends,

I have sharepoint services running on my Windows 2003 R2 Server. From VS2005, I created a sample web part like below (just to see how it looks).

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;
using System.Reflection;

[assembly: AssemblyKeyFile("sample.snk")]

namespace WebPartLibrary1
{

    /// <summary>
    /// Description for WebPart1.
    /// </summary>
    [DefaultProperty("Text"),
        ToolboxData("<{0}:WebPart1 runat=server></{0}:WebPart1>"),
        XmlRoot(Namespace = "WebPartLibrary1")]
    public class WebPart1 : Microsoft.SharePoint.WebPartPages.WebPart
    {
        private const string defaultText = "";

        private string text = defaultText;

        [Browsable(true),
            Category("Miscellaneous"),
            DefaultValue(defaultText),
            WebPartStorage(Storage.Personal),
            FriendlyName("Text"),
            Description("Text Property")]
        public string Text
        {
            get
            {
                return text;
            }

            set
            {
                text = value;
            }
        }

        /// <summary>
        /// Constructor for the class.
        /// </summary>
        public WebPart1()
        {
            this.Title = "This is a test web part";
        }

        protected override void RenderWebPart(HtmlTextWriter output)
        {
            output.Write(SPEncode.HtmlEncode(Text));
            //Create a Label
            Label testLabel = new Label();
            //Write the Text
            testLabel.Text = "Hello World";
            //Add the label control to the page
            this.Controls.Add(testLabel);
            testLabel.RenderControl(output);           
        }

  
    }
}

and  my dwp file look like this

<?xml version="1.0" encoding="utf-8"?>
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2" >
 <Title>WebPart1</Title>
 <Description>WebPart1.</Description>
 <Assembly>WebPartLibrary1</Assembly>
 <TypeName>WebPartLibrary1.WebPart1</TypeName>
 <!-- Specify initial values for any additional base class or custom properties here. -->
</WebPart>

I made "safe control" entry in the web.config file (c:\inetpub\wwwroot) like below....
 <SafeControl Assembly="WebPartLibrary1" Namespace="WebPartLibrary1" TypeName="*" Safe="True" />

Also copied the WebPartLibrary1.dll to the c:\windows\assembly (GAC).

Still when I try to drag the web part in a wep part page... I get error like
below...

"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 have even reinstalled IIS and Sharepoint Servies. My sharepoint runs as (All Unassigned)".

Can any body tell me what could be the reason for error and how to fix it.  I am really struck up with this error.

Thanks in Advance.

TMRK

 

 

  Sushila Patel replied to Maria Raja Kumar
19-Nov-06 06:55 PM

Have you tried changing the security level of the entire application from minimal to medium in the web.config?

Also check if the below workaround from the Newsgroup helps

<extract>

To determine the correct PublicKeyToken value
for the Assembly attribute of the SafeControl tag for your
Web Part, perform the following workaround:

In Windows Explorer, open the c:\inetpub\wwwroot\bin
folder.
In a separate window, open the c:\Windows\Assembly folder.
(C:\Windows\Assembly exposes the contents of the Global
Assembly Cache (GAC).)
Drag your Web Part assembly (your sample from these
procedures should be named SimpleWebPart.dll) from the
c:\inetpub\wwwroot\bin folder into the c:\Windows\Assembly
folder.
In the c:\Windows\Assembly folder, right-click your
assembly, and then click Properties.
Copy the Public Key Token value, and then paste it into
the SafeControl tag for your assembly.
In the c:\Windows\Assembly folder, right-click your
assembly, and then click Delete. 
Note You can also determine the PublicKeyToken
value of your Web Part assembly by using the sn.exe
command-line utility:
sn.exe -T c:\inetpub\wwwroot\bin\SimpleWebPart.dll

</extract>

 

Create New Account
help
GAC Can you give the brief explanation of GAC(Global Assembly Cache) in ASP.NET. Each computer where the common language runtime is installed has a machine-wide code cache called the global assembly cache. The global assembly cache stores assemblies specifically designated to be shared by several applications on the computer
Global Assembly Cache Can someone pelase explain to me what is the global assembly cache. I read about it and I just dont get it The Global Assembly Cache (GAC) is a special folder in windows to store .net global dll's. It
How to copy files from Global Assembly Cache to Bin Folder ? .NET Framework How to redistribute files from Global Assembly Cache to Bin Folder for upload on Web Site ? Best Regards, Luqman ASP.NET Discussions Site BlogMetaFinder (1) UnBlog (1) GAC (1) You need to have a local copy of the assembly to deploy. The GAC uses a special "view" of the / assembly folder that prevents copying of assemblies directly out of the GAC. - - Recursion: see Recursion site
path of dll" what i stands for? gacutil helps to place the dll in the global assembly cache. The Global Assembly Cache tool allows you to view and manipulate the contents of the global assembly cache and download cache. From the start menu - -Run Command - - Enter assembly and press enter
Global Assembly Cache .NET Framework Hello everyone, I have used gacutil tool to install my COM dll into Global Assembly Cache, http: / / msdn2.microsoft.com / en-us / library / ex0ss12c(VS.80).aspx But I am not sure whether I need to manually copy the actual assembly dll into some directory (like Windows \ System32? Windows?) after running this tool? Or gacutil tool will automatically copy (install) the assembly for me - - so I only need to run gacutil -i <dllname> ? thanks in advance, George