none
Custom WebPart on default.aspx for FARM and SANDBOX

    Question

  • Hi

    I would like to add a custom webpart to a page (default.aspx) that would work for sandbox and farm deployment.

    Code below works OK but only for SANDBOX if i include line 

    <Solution SolutionId="$SharePoint.Package.Id$" xmlns="http://schemas.microsoft.com/sharepoint/" />

    or only for FARM if i remove that line. If I have that line in farm I get error: "Web Part Error: The request could not be completed
    because the specified solution was not found."

    Is there a way to make one definition work for both ?

    Thanx,

       VaBr

     <File Url="default.aspx" Path="default.aspx">
          <AllUsersWebPart WebPartOrder="0" WebPartZoneID="Left" ID="..."  >
            <![CDATA[<webParts>
      <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
        <metaData>
          <type name="....." />
          <importErrorMessage>....</importErrorMessage>
          <Solution SolutionId="$SharePoint.Package.Id$" xmlns="http://schemas.microsoft.com/sharepoint/" />
        </metaData>
        <data>
          <properties>
            <property name="HelpUrl" type="string" />
            ... 
          </properties>
        </data>
      </webPart>
    </webParts>]]>
          </AllUsersWebPart>


    Monday, February 20, 2012 4:10 PM

All replies

  •  

    Hi VaBr,

    I have a test in my local server, the web part can be added to both sandbox solution and farm solution through adding the webpart.dwp file content, both situation don’t need:
    <Solution SolutionId="$SharePoint.Package.Id$" xmlns="http://schemas.microsoft.com/sharepoint/" />

    Would you please create a farm solution web part, then deploy it to site, download the web part from web part gallery, then copy the file content to the <AllUserWebPart> tag, to check whether it works.

    If it doesn’t work, please provide more information about without <Solution SolutionId="$SharePoint.Package.Id..> in sandbox solution, what error message will occur?

    Thanks,
    Qiao


    Qiao Wei

    TechNet Community Support

    • Marked as answer by Shimin Huang Sunday, March 04, 2012 9:25 AM
    • Unmarked as answer by VaBr Sunday, March 04, 2012 12:27 PM
    Tuesday, February 28, 2012 11:09 AM
    Moderator
  • Hi Qiao Wei

    I tried your approach but it did not work.

     - To create the .dwp file instead of .webpart, I must inherit from  "Microsoft.SharePoint.WebPartPages.WebPart", which is not allowed in sandbox sollution.

     - If I Inherit from "System.Web.UI.WebControls.WebParts.WebPart" and use .dwp I get error "Cannot import this Web Part." when adding webpart to page. Is it even possible to import a "System.Web.UI.WebControls.WebParts.WebPart" using dwp? 

    Can you give me some more information about you test:

     1) Did you use a custom webpart or a sharepoint built in webpart?

     2) What did you use for your webpart base class ("Microsoft.SharePoint.WebPartPages.WebPart" or  "System.Web.UI.WebControls.WebParts.WebPart")?

     3) If it worked for your custom webpart could you post your wp.dwp, wp.cs and elements.xml ?

    Thanx,

       VaBr




    • Edited by VaBr Sunday, March 04, 2012 12:33 PM
    Sunday, March 04, 2012 12:26 PM