As a developer, you will say GetList can throw exception but TryGetList will not. It is actually confusing because TryGetList looks for listTitle and returns null if list is not available at expected location. GetList will expect listUrl and can throw FileNotFoundException or ArgumentException if list is not present at expected location or relative/absolute url of list is invalid relatively. Another biggest difference is they belong to different class!
Apart from all those technical details, I noticed that many sharepoint administrators likes to start with a simple list/library name and eventually change it to make it as close as possible to what they do. That will make list/library url and their names different. Here comes the actual problem. If you are actually using list/library names in your code, it will no longer work. OR we can say you are not allowing sharepoint administrators to change name of list/library that they have created.
By using GetList you are actually giving them flexibility to use whatever name they like to use, as far as they are not changing url or list/library code will still work.
In conclusion, it really depends on requirements how you are going to deal with the situation but it is good to keep in mind that you can use GetUrl function in your code to allow sharepoint administrators to change their names without worrying about breaking functionality.
Sharepoint Tutorials, Tips and tricks, development, analysis, administration, and much more
Welcome
Sharepoint lead is a place where you can read about interesting topics related to sharepoint, and you can also post comments and suggessions.
Showing posts with label Best practice. Show all posts
Showing posts with label Best practice. Show all posts
Monday, July 2, 2012
Wednesday, May 16, 2012
Best Practice: Maintaining scripts in your sharepoint project
Introduction
Branding is the most important part of any sharepoint project. If you are planning to deliver branding in your release, you have to make sure your developer team is proactive to deliver quality branding from early stage of the project. In most of the branding project, jQuery and javascript becomes must-have part. Here we will discuss practices that can be followed to ensure quality deliverables.
Practice
- Manage script files
From the very starting stage of your project, split your all javascript code in three files. - jQuery.min.js - This will contain jQuery reference and should be reference first in order.
- jQuery.plugins.js - This should contain all custom plugins we used in it.
- ProjectName.js - This hsould contain all your custom code written to get your project pages work properly
- Choosing plugins for your project
- Download plugin bundle to your local computer
- Generally plugin will contain sample html files, jQuery and plugin script files.
- First thing to check is, jQuery version you are using in your project and the one which is used in plugin
- If they are different, replace their jQuery.min.js with the one we are using
- Properly test the sample provided in plugin in all browsers you are planning to support
- Once browser and version compability matches paste plugin's min.js at end of jQuery.plugins.js file.
- Implement plugin specific mark up wherever applicable
- Always use projectName.js to initialize plugin.
- Repeat above process when you choose to add any jQuery plugin
- Resolving CONFLICTS!
Another challenging part is jQuery ready not working or custom plugin you are using is disturbing your site's css. Here are thoughts on the same - Aways use _spBodyOnLoadFunctionNames.Push("yourFunctionName") to init your scripts in page load.
- Always use only necessary css from what plugin css has proviced and prefix class or ID in css as application. For example if a generic class .clear is used and you are calling plugin using $('#news') you should replace that with #news .clear. Do this for all css you include for the class
Final thoughts
Here I pointed out some of the best practices. Like this post? You like to add/correct something? please provide your feedback on the same.
Subscribe to:
Posts (Atom)