1

My goal here is to create a list template with code-behind on my server and copy it to a completely different Sharepoint server. The problem is that my server has Visual Studio 2010 while the other server does not, which makes adding code-behind to the other server's Sharepoint sites a bit of a challenge.

I created a custom list using SharePoint Designer 2010 in a new blank site collection. Basic list, nothing special. Then I used the Site Actions -> Save Site As Template to create a .wsp file so I could use Visual Studio 2010 to import the list. This way I could make some changes to the Schema.xml and add an event receiver for the itemAdding event. After the changes I deployed it back the site and it worked exactly how I wanted it to work.

On my site I went to my list then used List Settings to save the list as a template. At the List Template Gallery, I selected my template, and used the Documents -> Download A Copy to make a copy in my downloads folder. Then I created a new site collection using Central Administration. At this new site I went to it's List Template Gallery and uploaded my template from my downloads folder. I created a new list from this template and it's code-behind worked perfectly.

Now I have copied the template from my downloads folder to the other server, went to its site's List Template Gallery and uploaded my template. I created a new list from the template and it's code-behind for itemAdding does not work at all. The list looks like it should with the changes to the Schema.xml but the code-behind does not work.

What have I missed?

2 Answers 2

2

well, your code behind is DLL, right? to call a code from a dll (even declaratively like configuring EventReceiver in xml) you need to have that dll in GAC or in a place on file system. seems that you have used VS to deploy your changed package which automatically copy DLL to GAC so it should work on your system. to make it working everywhere you need to add your dll to module and deploy it as farm-scope or sandbox solution. I would check if your target server has User Code service enabled and your code behind uses allowed methods before using sandbox approach, but probably most straightforward way is to use farm-scope way to deploy your dll to GAC. actually if all you need is receiver, I would look into WebTemplates

2
  • I looked at the link for WebTemplates that you provided. The site is already there (already exists), the request was just for an itemAdding event for a list, so an entire Web template is overkill (I think). It seems that this "simple" request is much bigger than it should be. I found a .ps1 file that does nothing but get the web url and the list url and searches for event receivers. It found the receiver for my test site, but not for the other site. It couldn't even find the web url for the other site! So I'm thinking there's something else going on here other than just programming errors.
    – Susie Q
    Sep 10, 2012 at 19:07
  • I see. So imho the simplest way to fix your situation, you can create separate solution just to deploy and attach your receiver to the prod farm. In VS2010 add required code and create web-scope feature. In feature activation receiver attach your list receiver to proper list. Sep 11, 2012 at 17:36
1

You can make publish copy of your solution and put .wsp files from bin folder of publish copy to your another SharePoint server and deploy there with PowerShell Script using following command

Install-SPSolution -Identity <solution.wsp> -WebApplication <name or guid of web app> -GacDeployment

Refer this link for more detail.

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.