0

I was wondering if I could get some thoughts on what the best practices are for sharepoint webparts and Visual Studio structure. What I mean by this is, I have several sharepoint form application projects, all have several tabs or pages within their project (admin page, view records page etc) and are all under the same grand "intranet" company project. I see a lot of tutorials and other sites that seem to make all their Webparts in seperate solutions and what not. I have three questions:

1.) Should each "part" of the form project even if it's another page be in different webparts OR of the same project? I would think the latter, because if it was in another project, it would be difficult to get control of during runtime.

2.) Should other forms of the same master intranet project, but in their own Visual Studio projects be in the same solution? or different ones.

3.) Class Libraries... Are they done the same way as WPF or ASP.net?

1 Answer 1

1

Well it really depends on your requirements. Most of the time i use the WebPart just as a wrapper to load my UserControls (which are in a different project but in the same solution) dynamically. If you need something more "static" i'd recommend using Application Page's instead of WebPart's.

I'll try it to explain it with an example:

Lets say you want to create a solution that helps your project managers do their job (haha :-). You'd call this app something like "PM App". It consists out of 3 parts: Issue Tracker, Time Tracker and a Reporting App.

First step, obviously, is creating a blank solution named "PM App". As all 3 parts of the solution have somethings in common, for example a logger component or a DataAccessLayer, you'll create a new project named "Common".

Then it really depends on your solution design. Lets say we go for a WebPart / UserControl solution. You create a new project named "SP PM" which is a SharePoint project (actually, i have yet to find a appropriate name for this project). Then you create a WebPart for each part of your solution (IssueTrackerWebPart etc...). Now, if you only have 1 UserControl per WebPart, easy peasy. The WebPart basically acts as a wrapper for your UserControls.

If you (want to) have multiple UserControls, it gets quite tricky. I always end up creating a new ASP.NET WebApplication project named "UserControls" and add my UserControls there. The problem with doing it this way is referencing the UserControls in your "SP PM" project. Referencing the dll's is no problem, referencing the .ascx files on the other hand, is.

What i do is, copy the .ascx file(s) from my "UserControls" project to my "SP PM" project with a post-built script. I know this is definitely not the best solution, however i've talked to many other devs about this issue, but nobody has found a better solution until now.

This is a really tough issue in the SharePoint context (as in any other actually), and there aren't any Best Practices as far as i know. The best thing to do is sit together with your fellow developers, and ask them how they would create the solution/project structure and then find a good middle way.

tl;dr no "generic" way - really depends on your requirements.

I quickly put the solution togther how i think it should look:

solution explorer

Hope this makes any sense to you, and feel free to ask if you have any further questions. Also i'd like to hear some opinions about how other people approach these issues :-)

2
  • Sure. 2.) I think this kind of goes with your answer to #1. I'm trying to decide from a maintenance and deployment standpoint, what would be best. If I have application1 (which is a form with fields and people fill them out and then it sends stuff to an email) and application2 which is a spreadsheet of data that people can access. Are these 2 different WebParts, different user Controls, different projects? i think I am lost at the naming and conception difference between a web part and a user control. Also, should there be more than one webpart in a particular project? Aug 2, 2011 at 12:42
  • #3 is like Data Access layer. Where lets say i made a Messenger Class. All this class does is handle email requests. i don't want to duplicate my efforts and copy it into every Webpart project. i would much rather have a library that holds all my generic classes and have my webparts reference them. Does that make more sense? if so, how do I do it and do you have any tutorials on how to do it. We tried the other day and got all sorts of errors trying to access the library. Aug 2, 2011 at 12:46

Your Answer

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

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