locked
unable to import web part RRS feed

  • Question

  • I created a Web Part in VS 2008 using C#, and I'm unable to import the web part into my Sharepoint site. When I go to the gallery, click;

    Browse --> Import -- > I then click the browse button and map to the location I have the .dwp file --> Upload ( no errors so far)
    the web part then shows up in the [uploaded web part section], but then when I click the Import button I get;

    [unable to add selected web part(s). Cannot import this web part.

    Now, I developed the web part on my local box and put the dll and dwp files out in the bin folder of the sharepoint site I created the part for, and no luck.

    What do I need to do to be able to import my web part to my Sharepoint site?
    Wednesday, November 19, 2008 1:55 PM

Answers

  • I don't think your problem is not allowing partially trusted callers, this is usually an issue when your assembly is being used by a non trusted assembly (or partially trusted assembly). But for future reference it can be allowed by adding:

    [AllowPartiallyTrustedCallers]

    To the assemblyinfo.cs file in your Visual Studio project - you may have to add an import statement for System.Security.

    Taking a look at your DWP it looks as though your public key token is incorrect - it is actually a GUID - if you have added your assembly to the GAC then just look at it's properties when using the .NET configuration tool and copy the public key token from there.

    Other ways of getting hold of it are discussed here http://blogs.msdn.com/miah/archive/2008/02/19/visual-studio-tip-get-public-key-token-for-a-stong-named-assembly.aspx

    Stu
    Blog: http://www.starznet.co.uk/sharepoint/blog Please mark replies as answered if you find it has helped you
    Thursday, November 20, 2008 12:59 PM

All replies

  • Have you added SafeControl entries. Also, if possible paste the contents of dwp here.

    --

    Madhur

    http://blogs.msdn.com/mahuja | Please mark the replies as answers if they help
    Wednesday, November 19, 2008 2:07 PM
  • here is the XML from the DWP file:

    <?xml version="1.0"?>
    <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
       <Assembly>TestWebPart, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=c60fe6c1-2604-4c0c-9948-1a1575f33cc3</Assembly>
       <TypeName>TestWebPart.WebPart.cs</TypeName>
       <Title>My First Web Part</Title>
       <Description>My first C# web part</Description>
    </WebPart>

    Wednesday, November 19, 2008 4:21 PM
  • Hi


    After reading this i came to know that you have missed the allow partially trusted callers in ur web part ......

    Try it now after adding that

    Kacharla..
    sree
    Thursday, November 20, 2008 12:03 PM
  • kancharla said:

    Hi


    After reading this i came to know that you have missed the allow partially trusted callers in ur web part ......

    Try it now after adding that

    Kacharla..


    sree



    What is "allow partially trusted callers" and how do I add it?
    Thursday, November 20, 2008 12:52 PM
  • I don't think your problem is not allowing partially trusted callers, this is usually an issue when your assembly is being used by a non trusted assembly (or partially trusted assembly). But for future reference it can be allowed by adding:

    [AllowPartiallyTrustedCallers]

    To the assemblyinfo.cs file in your Visual Studio project - you may have to add an import statement for System.Security.

    Taking a look at your DWP it looks as though your public key token is incorrect - it is actually a GUID - if you have added your assembly to the GAC then just look at it's properties when using the .NET configuration tool and copy the public key token from there.

    Other ways of getting hold of it are discussed here http://blogs.msdn.com/miah/archive/2008/02/19/visual-studio-tip-get-public-key-token-for-a-stong-named-assembly.aspx

    Stu
    Blog: http://www.starznet.co.uk/sharepoint/blog Please mark replies as answered if you find it has helped you
    Thursday, November 20, 2008 12:59 PM
  • I have my public token, I can see my web part in the web part gallery, but I still can't import into my site. I'm getting unable to import web part.

    Its just a basic "hello world" with a button and text box, its not accessing a db or anything like that.
    Thursday, November 20, 2008 6:49 PM
  • Hi ,



    using System.Configuration;

    using System.Configuration.Assemblies;

    using Microsoft.SharePoint.Administration;

    [assembly:AllowPartiallyTrustedCallers]

    namespace ConvertLead

    {

    [Guid("18c68981-73bb-45ea-b8c5-02f19737e0ad")]

    public class ConvertLead : System.Web.UI.WebControls.WebParts.WebPart



    This is the way how to add partially trustedcallers..   just look at the code abou mentioned in red colour..  you just add that code on your web part............


    sree
    Friday, November 21, 2008 4:52 AM
  • I have that in my assembly.cs file. I removed it from there and added to my webpart.cs file and it won't compile now.
    Its giving me an error message:

    Error 1 The type or namespace name 'AllowPartiallyTrustedCallersAttribute' could not be found (are you missing a using directive or an assembly reference?) C:\WebSites\WebParts\HelloWorld\Hello.cs 15 12 Hello

    Here is my code from my web part: Am I missing something here? Now, this web part is created in VS 2008 using the web part template under the SharePoint projects

    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;
    using System.Configuration.Assemblies;
    using System.Configuration;
    using Microsoft.SharePoint.Administration;

    [assembly: AllowPartiallyTrustedCallers]

    namespace HelloWorld
    {
        [Guid("b8b1e3a2-ea1b-40b0-908d-70243b4d61f5")]
        public class HelloWorld: System.Web.UI.WebControls.WebParts.WebPart
        {
            public HelloWorld();
            {
            }

            protected override void CreateChildControls()
            {
                base.CreateChildControls();

                // TODO: add custom rendering code here.
                Label label = new Label();
                label.Text = "Hello World";
                this.Controls.Add(label);
            }
        }
    }

    Friday, November 21, 2008 1:02 PM
  • Ok, you have got to be kidding me.

    I can now see my web part in my web part gallery, but now when I try to add it to my page, I'm getting the following error message:

    My Web Part: A Web Part or Web form control on this page cannot be displayed or imported. The Type could not be found or it is not registered as safe.

    and here is my web.config file for the site I'm trying to add the part to:
    <SafeControl Assembly="Hello, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5" Namespace="Hello" TypeName="*" Safe="True" />

    what is missing here? This can't be this complicated, so what am I missing?
    Friday, November 21, 2008 1:16 PM