Problem: I can't debug my SharePoint projects using Visual Studio 2010 (VS). I get the error "Could not load the Web.config configuration file. Check the file for any malformed XML elements, and try again. The following error occurred: Cannot connect to the SharePoint site. If you moved this project to a new computer or if the Url of the SharePoint site has chnaged since you created the project, update the Site Url property of the project." in VS when I try debug.
Initial Hypothesis: I recenctly renamed all my VS projects in my VS solution. The error tells me to check the "Site Url" on each of my projects. I missed the project that was set as my start up project.
Resolution: Set the "Site Url" property in VS on the projects.
Tuesday, 9 November 2010
Friday, 5 November 2010
Dropdownbox population options for custom SharePoint applications
Problem: I need to populate combo boxes and drop down list boxes on a customised SharePoint page using a web part. The web part has 5 of these lists that are populated choice fields.
Initial Hypothesis: I could use the Enum generated by Linq to SharePoint for the choice field options but to change the available options would require me to re-generate the SPMetal proxy. I could use lookup lists and then use Linq to SharePoint but this is pretty heavy for simple choice columns. So I chose to use the SP Server-side Object Model, this is not too heavy as it is only looking up the columns and looping thru the choices however I have 5 drop down lists doing this repeatedly for a lot of users. So although it is working it could be better if the results were cached for a minute. This would allow choice options to be change and the using a cache duration of 1 minute, the longest the wait would be is 60 seconds before users see the updated lists.
Resolution: I cached my list item collections, on the page I had 5 choice fields. By adding the caching I am getting a 36% performance increase in my Page Request response time. So not as good a return as I was expecting but still a considerable improvement.
Test Information:
I used a sample of 10 items per request type. The 10 pages requested each for the cached list item collections and the un-cached version. I excluded the 1st page request for warm up.
All the results were pretty consistent.
The testing was done on a local development machine.
Code to cache list item collections:
HttpContext.Current.Cache.Insert(keyname, null, DateTime.Now.AddMinutes(1), Cache.NoSlidingExpiration)
Initial Hypothesis: I could use the Enum generated by Linq to SharePoint for the choice field options but to change the available options would require me to re-generate the SPMetal proxy. I could use lookup lists and then use Linq to SharePoint but this is pretty heavy for simple choice columns. So I chose to use the SP Server-side Object Model, this is not too heavy as it is only looking up the columns and looping thru the choices however I have 5 drop down lists doing this repeatedly for a lot of users. So although it is working it could be better if the results were cached for a minute. This would allow choice options to be change and the using a cache duration of 1 minute, the longest the wait would be is 60 seconds before users see the updated lists.
Resolution: I cached my list item collections, on the page I had 5 choice fields. By adding the caching I am getting a 36% performance increase in my Page Request response time. So not as good a return as I was expecting but still a considerable improvement.
Test Information:
I used a sample of 10 items per request type. The 10 pages requested each for the cached list item collections and the un-cached version. I excluded the 1st page request for warm up.
All the results were pretty consistent.
The testing was done on a local development machine.
Developer Dashboard showing improved response times using cacheing. |
HttpContext.Current.Cache.Insert(keyname, null, DateTime.Now.AddMinutes(1), Cache.NoSlidingExpiration)
Wednesday, 3 November 2010
Error occurred in deployment step 'Activate Feature': A duplicate field name "xx" was found.
Problem: A site column/ field occurs more than once. I.e. there is a duplicate field name.
Initial Hypothesis: If you are deploying site columns declaritively (CAML), you will have 2 site columns with the same name and type. This commonly happens with "Email" so be more specific or reuse the exisitng site column.
Resolution: Ensure thre duplicate field name is unique or reuse an exisitng suitable site column.
If you have check that you don't have the issue above and you are deploying using Visual Studio 2010 use the following advice. This occurs after you have renamed or deleted the site columns as explained above.
Problem: Deploying site columns using VS results in the error "Error occurred in the deployment step 'Activate Features': A duplicate field name "Email" was found.
Initial Hypothesis: If you are deploying site columns declaritively (CAML), you will have 2 site columns with the same name and type. This commonly happens with "Email" so be more specific or reuse the exisitng site column.
Resolution: Ensure thre duplicate field name is unique or reuse an exisitng suitable site column.
If you have check that you don't have the issue above and you are deploying using Visual Studio 2010 use the following advice. This occurs after you have renamed or deleted the site columns as explained above.
Problem: Deploying site columns using VS results in the error "Error occurred in the deployment step 'Activate Features': A duplicate field name "Email" was found.
Initial Hypothesis: Ensure you don't have duplicate fields as show in the above problem solver. Activate the feature using ststadm, it will now work. The problem is that Visual Studio on it's 1st build and deployment caches SharePoint information, this was done by MS to speed up subsequent deployments of code. However, the cached VS SP info is now wrong so restart VS 2010 and deploy again.
Resolution:- Retract the solution that holds the failing feature;
- Close and reopen the Visual Studio Project; and
- Deploy the feature using VS 2010.
Reverse Engineer Lists, Content Types and Site Columns and retrieving the CAML
Problem: You need to create deployable lists, this should be done using a feature. You can create a lists using the UI and then get the CAML that created the list. The code will have some hicups but it a good place to start for building your Lists based on List definitions, content types and their corresponding site columns.
Resolution:
Get the CAML and create your feature based on the declaritive CAML
http://%7bwebapplication%7d/%7Bsite%7D/_vti_bin/owssvr.dll?Cmd=ExportList&List={ListGuid}
Thanks to Sahil Malik
Read More:
http://blah.winsmarts.com/2008-2-Dev_Tip__The_SharePoint_University_of_Reverse_Engineering.aspx
http://www.synergyonline.com/blog/blog-moss/Lists/Posts/Post.aspx?ID=24
Download: SharePoint 2010 sandbox project example that creates 2 lists with a lookup field. Updated 24/03/2011
Resolution:
Get the CAML and create your feature based on the declaritive CAML
http://%7bwebapplication%7d/%7Bsite%7D/_vti_bin/owssvr.dll?Cmd=ExportList&List={ListGuid}
Thanks to Sahil Malik
Read More:
http://blah.winsmarts.com/2008-2-Dev_Tip__The_SharePoint_University_of_Reverse_Engineering.aspx
http://www.synergyonline.com/blog/blog-moss/Lists/Posts/Post.aspx?ID=24
Download: SharePoint 2010 sandbox project example that creates 2 lists with a lookup field. Updated 24/03/2011
Labels:
CAML,
Content types,
list definition,
OWSSVR.DLL,
Reverse Engineer,
site columns
Monday, 1 November 2010
SharePoint DateTime format is incorrect
Problem: The SharePoint DateTimeControl displays the date in US format i.e. 1033 or mm/dd/yyyy despite me changing the site collections regional settings.
Site Settings > Regional Settings > Locale > Select [English (United Kingdom)]
Inital Hypothesis: In MOSS changing the Locale did not change the format of the DateTimeControl.
Resolution: This is still the case, you need to explicitly set the local on eash DateTimeControl. You can set it to be the same as the site's local.
E.g. myDateTimeControl.LocaleId = SPContext.Current.Web.Locale.LCID
Or set the "LocaleId"attribute of the SharePoint DateTime control
E.g. SharePoint:DateTimeControl runat="server" LocaleId="2057"
=========================
Tip: Changing the Regional settings will affect the curreny columns.
List of Locale's: http://msdn.microsoft.com/en-us/goglobal/bb964664.aspx
====================
Site Settings > Regional Settings > Locale > Select [English (United Kingdom)]
Inital Hypothesis: In MOSS changing the Locale did not change the format of the DateTimeControl.
Resolution: This is still the case, you need to explicitly set the local on eash DateTimeControl. You can set it to be the same as the site's local.
E.g. myDateTimeControl.LocaleId = SPContext.Current.Web.Locale.LCID
Or set the "LocaleId"attribute of the SharePoint DateTime control
E.g. SharePoint:DateTimeControl runat="server" LocaleId="2057"
=========================
Tip: Changing the Regional settings will affect the curreny columns.
List of Locale's: http://msdn.microsoft.com/en-us/goglobal/bb964664.aspx
====================
Using CAML and SPQuery to query using dates
Problem: Using SPQuery I can't filter using a datatime parameter.
Hypothesis: I can see my custom web part code is formatting the DateTime selection (SharePoint:DateTimeControl) differently in my custom code CAML than the CAML generated by U2U.
Resolution:
Use the Microsoft.SharePoint.Utilities.SPUtility.CreateISO8601DateTimeFromSystemDateTime() method to get your DateTime control value into the correct format.
SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.UtcNow)
More Info:
http://blogs.msdn.com/b/saurabhkv/archive/2008/05/05/spquery-with-boolean-and-datetime.aspx
http://snahta.blogspot.com/2009/07/spquery-few-important-things.html
http://www.aidangarnish.net/post/Using-SPQuery-and-CAML-to-filter-and-order.aspx
Hypothesis: I can see my custom web part code is formatting the DateTime selection (SharePoint:DateTimeControl) differently in my custom code CAML than the CAML generated by U2U.
Resolution:
Use the Microsoft.SharePoint.Utilities.SPUtility.CreateISO8601DateTimeFromSystemDateTime() method to get your DateTime control value into the correct format.
SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.UtcNow)
More Info:
http://blogs.msdn.com/b/saurabhkv/archive/2008/05/05/spquery-with-boolean-and-datetime.aspx
http://snahta.blogspot.com/2009/07/spquery-few-important-things.html
http://www.aidangarnish.net/post/Using-SPQuery-and-CAML-to-filter-and-order.aspx
Friday, 29 October 2010
SPGridView explained
Overview: The SPGridView is similar to the asp GridView. The SPGridView is derived from the aspGridView and has additional functionality. The SPGridView does not support the property AutoGenerateColumns, you must specify each SPBoundField.
Example: SPBoundFields such as "BoundField" are used to display datasource columns.
Example: To format a bound column use the property "DataFormatString", e.g. colDate.DateFormatString = "{0:d}";, this will display the short date only from a DateTime type. If you need more advanced formating such as for a multi choice field, create a new class that derives from BoundField and use it in the SPGridView.
Tip: Don't use DataKeyName on the SPDataGrid, it causes the error "Unable to cast object of type 'System.Int32' to type 'System.String'.".
Read More:
http://msdn.microsoft.com/en-us/library/bb466219(office.12).aspx
Labels:
DataFormatString,
SPBoundFields,
SPDataGrid,
SPGridView
Subscribe to:
Posts (Atom)