1

What is the best way to add a custom webpart to a sharepoint default page(i.e list page like NewPost.aspx) and/or into the webpart gallery programmatically without directly deploying from Visual studio.

[Edit]

What I did:
1) Created a custom Visual webpart solution in Visual Studio.
2) Directly deployed my custom webpart into my dev site.
3) Then I published the custom webpart(*.wsp).
4) I exported my custom webpart from dev site which had the assembly reference of webpart and some of its properties as below.

<webParts>
  <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
    <metaData>
      <type name="CstmWebpart.BlogPosts.CreateandEditBlogPosts.CreateandEditBlogPosts, CstmWebpart.BlogPosts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=51ad286432a40bbb" />
      <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
    </metaData>
    <data>
      <properties>
        <property name="ExportMode" type="exportmode">All</property>
        ..
        ..
        ..
      </properties>
    </data>
  </webPart>
</webParts>

5) After that I deployed the webpart solution(*.wsp) into my target site which is another machine using Install-SPSolution cmdlet.
6) Then I uploaded and added the exported webpart (*.webpart) into target site, which throws error as shown in below image. enter image description here
7) If I upload the exported the webpart into the same dev site, its working.

Am I doing it in the right way? Any help would be greatly appreciated.

1 Answer 1

2

If you are just taking an exported web part from your dev site and trying to put it into production, then there is no need to worry about an install-spsolution. Continue to do what you are doing.

If the web part is created as part of a feature, then in Visual Studio, you need to package the solution. This will build a WSP that you can push out to the farm with install-spsolution.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.