Questions about deploying web parts

I have a few theoretical questions about a web part of all which are very basic and should be easy for someone to answer. I just need to make sure I understand how this stuff works better. I created a VISUAL Web Part in VS 2010 for an SP 2010.

target was a subsite. Mydomain/Northwind rather than the root site.
Set to a farm solution rather than sandboxed.
My initial deployment scope was site but maybe it should have been web as this WP only performs a search of a specific list. So the feature shows up under site collection features, rather than the features of the specific subsite (web) that was the deployment target.
Web Part shows up under custom gallery as it should when I go to insert it in a page inside the subsite  
Web part works as intended on the correct site but if I add it to a page on the root site, it bombs because it can't find the list in question because the list exists in the subsite
Using SPList shippers = SPContext.Current.Web.Lists["Shippers"];

All of this makes sense to me so far. So maybe the problem is that I should have made this scoped to web,

Question
If I scope it to web, does that only mean that the same feature will show up on all sites (web) in the site collection under each site's feature section? I would rather that this only show up in the features of the specific subsite I targeted in the deployment because it will bomb if it is used on other sites


Deacativated the feature under site collection features where it is found
Deleted the web part from the page

The web part still shows up in the gallery and if I re-add it to the page it works as long as I use it in the subsite that contains the list it is supposed to search.

Question
Why? I thought it wouldn't be available in the gallery if it is deactivated, and I didn't expect to not only find it there, but also be able to re add it, but I did and the web part works.

I don't want this available for addition to pages on other sites where that list it is searching will not be present. So after deleting it from the page once again, double checking that it was still deactivated under site collection features where it shows up, I went back to my project, kept the target location the same but changed the scope to web.

Question
VS tells me that I cannot deploy the project through a feature with a web scope. Why not?


Hopefully some very easy questions. Thanks in advance.
LVL 9
BobHavertyComhAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rainer JeschorCommented:
Hi Robert,

web parts have a scope of "Site" as the web part gallery only exists on the site collection level (physically the root web of the site collection).
And as your module for the web part should look like
<Module Name="VisualWebPart1" List="113" Url="_catalogs/wp">

Open in new window

the activation will fail on the web scope.

Therefore if you have a web part which should only run on a specific sub site you have either the option that the SharePoint admin/designer should know what he does (as you would have instructed him to use this web part only on that sub site) or you implement a fail-safe coding hence checking if the list exists and if not to display nothing or just a warning / error message (proper error handling and not exception handling).

HTH
Rainer
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BobHavertyComhAuthor Commented:
Hi Rainer, I'll mark the above as the accepted solution. Thanks for the explanation. But why is the web part still showing up in the gallery for use after deactivation and why does it still work? That's the one part I'm still missing. The rest makes perfect sense to me now. Thanks. I'm not having any problems with it and my code and deployment work fine, but I need to makes sure I understand everything about how this all works in terms of activation, decativation.
0
Rainer JeschorCommented:
Hi Robert,

and one additional comment: I do not think that the web part files get automatically removed from the web part gallery. I am not sure if this happens every time or if it depends on if the web part has not been used / has been used on the site.

At least - best practice is to write code on your feature event receiver to "manually" cleanup the web part gallery on feature deactivation.

HTH
Rainer
0
BobHavertyComhAuthor Commented:
Thanks again
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SharePoint

From novice to tech pro — start learning today.