[SharePoint 2010 – Error fixing] Content By Query WebPart, display items links with wrong URL

image
You are programmatically creating a ContentQueryWebPart and when you test the solution, you try to click on an item link and you get a :
“404 NOT FOUND” page error

The error :

The Content By Query Webpart displays items url as :
http://jeff/sites/test/News/Lists/Posts/1_.000 or
http://jeff/sites/test/News/Lists/Posts/2_.000

 

Solution :

When you programmatically create the CQWP, you need to set the attribute UseCopyUtil to true.
wpCqwp.UseCopyUtil = true;
After, the item url should works and will look like :
http://jeff/sites/dzdza/_layouts/CopyUtil.aspx?Use=id&Action=dispform&ItemId=2&ListId=0b3c3cfc-5724-48e6-85ed-4943eae4f3b9&WebId=954e1a32-c41d-46f1-94b8-615ffd01156d&SiteId=edf289e7-9e97-4429-a9cf-e7d4af9636f2&Source=http%3A%2F%2Fjeff%2Fsites%2Fdzdza%2FSitePages%2FHome%2Easpx

 

Explanation :

By default, when you create a CQWP by the interface, SharePoint set the property UseCopyUtil to true.
Programmatically it’s set to false (i saw it by exporting the webpart, which gave me a .webpart file , and i compared it to a content query webpart created by interface).
Msdn explains, about that property that :
“Objects that are not streamed, such as announcements or calendar events, do not have an associated URL. When you set this property to true, objects that are not streamed have an associated URL that points to the View property of the item. “ Msdn
 
Voila !

[SharePoint 2010 – Error Fixing] Error “Object reference not set to an instance of an object.” when trying to add links in top navigation bar, as sub menu. With a custom created Sharepoint web template

If you created a webtemplate based on any Site Definition (Team Site…) and if you comment the navbars part

   1: <NavBars>
   2:     <!--<NavBar Name="$Resources:core,category_Top;" Separator="&amp;nbsp;&amp;nbsp;&amp;nbsp;" Body="&lt;a ID='onettopnavbar#LABEL_ID#' href='#URL#' accesskey='J'&gt;#LABEL#&lt;/a&gt;" ID="1002" />
   3:     <NavBar Name="$Resources:core,category_Documents;" Prefix="&lt;table border='0' cellpadding='4' cellspacing='0'&gt;" Body="&lt;tr&gt;&lt;td&gt;&lt;table border='0' cellpadding='0' cellspacing='0'&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='/_layouts/images/blank.gif' id='100' alt='' border='0'&gt;&amp;nbsp;&lt;/td&gt;&lt;td valign='top'&gt;&lt;a id='onetleftnavbar#LABEL_ID#' href='#URL#'&gt;#LABEL#&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;" Suffix="&lt;/table&gt;" ID="1004" />
   4:     <NavBar Name="$Resources:core,category_Lists;" Prefix="&lt;table border='0' cellpadding='4' cellspacing='0'&gt;" Body="&lt;tr&gt;&lt;td&gt;&lt;table border='0' cellpadding='0' cellspacing='0'&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='/_layouts/images/blank.gif' id='100' alt='' border='0'&gt;&amp;nbsp;&lt;/td&gt;&lt;td valign='top'&gt;&lt;a id='onetleftnavbar#LABEL_ID#' href='#URL#'&gt;#LABEL#&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;" Suffix="&lt;/table&gt;" ID="1003" />
   5:     <NavBar Name="$Resources:core,category_Discussions;" Prefix="&lt;table border='0' cellpadding='4' cellspacing='0'&gt;" Body="&lt;tr&gt;&lt;td&gt;&lt;table border='0' cellpadding='0' cellspacing='0'&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='/_layouts/images/blank.gif' id='100' alt='' border='0'&gt;&amp;nbsp;&lt;/td&gt;&lt;td valign='top'&gt;&lt;a id='onetleftnavbar#LABEL_ID#' href='#URL#'&gt;#LABEL#&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;" Suffix="&lt;/table&gt;" ID="1006" />-->
   6:       </NavBars>
   7:   <Configurations>

You might get this error when you create the SiteCollection :

“Object reference not set to an instance of an object.”

You guessed well, all you have to do is to uncomment those line, and prefer to delete it instead of commenting it.

You could also modify the navbar by custom code attach to a feature (with a feature receiver), in order to modify the web template navigation.

[SharePoint 2010 – Error Fixing] SPException invalid date/time (Erreur : Valeur de date/d’heure non valide. Un champ de date/d’heure contient des données non valides. Vérifiez la valeur, puis réessayez)

What did i try to do ?

I’m creating SPListItem Programmatically (create elements in a list) and when the item.update(); is called by the code, the following error is thrown :
“Erreur : Valeur de date/d’heure non valide.Un champ de date/d’heure contient des données non valides. Vérifiez la valeur, puis réessayez”
or in english :
“SPException : invalid date/time…”

What could be the problem ?

  1. The date format is not correct
  2. The date is not correct (minimum date for SharePoint ?)

Solving the problem

I’m giving an example of an incorrect date value “01/01/0001 00:00:00” :

   1: SPList list = web.Lists["myList"];
   2:  
   3: SPListItem item;
   4: string date = "01/01/0001 00:00:00";
   5:  
   6: item = list.Items.Add();
   7:  
   8: item["currentDate"] = date;
   9: if (DateTime.TryParse(row["currentDate"].ToString(), out dateTime) == true)
  10: {
  11:     //si la date est définit
  12:     if (dateTime.ToString() != "01/01/0001 00:00:00")
  13:     {
  14:         item["currentDate"] = SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Parse(date));
  15:     }
  16: }
  17:  
  18: item.update();
  19: list.update();

01/01/2001 is an incorrect value for a date in sharepoint.

And we check the date in order to respect sharepoint dates rules, using the method : CreateISO8601DateTimeFromSystemDateTime.

Have you ever had other issue with dates and SPListItem ?

[VmWare Workstation] Vmware workstation error : “Taking ownership of this virtual machine failed. The virtual machine is in use by an application on your host computer. Configuration file…”

Launching a vm leaded me that message error : “Taking ownership of this virtual machine failed. The virtual machine is in use by an application on your host computer. Configuration file”


To solve the problem, delete lck files in the machine virtual folder content, search for : *.lck 

[Sharepoint 2010 – Error Fixing] The file has been modified by … unknown

I got the following error message in visual studio during programing :

“The file has been modified by … unknown”

It was because i called two times (by error) the item.update(); method.

This could happen as well when you code an event receiver (sometime happening when you do something on a list, web, site….) and you use item.update(), in order to fix that :

  •  call and disable event firing before your code with : base.EventFiringEnabled = false;
  • update your item by calling item.systemUpdate(false); 
  • enable event firing with : base.EventFiringEnabled = true;

[SharePoint 2010 – Developpement] The file is not extracted, it has to be extracted before modifications (Le fichier n’est pas extrait, il doit être extrait avant d’être modifié)

In my code, i got the SPLIMITEWebPartManager object, before the page checkout.

Actually, you’ll have to first :

  1. CheckOut the page
  2. Get the SPLimitedWebPartManager

This post explain how to do it

http://blogs.edwardwilde.com/2009/11/29/splimitedwebpartmanager-savechanges-throws-microsoft-sharepoint-webpartpages-webpartpageuserexception-the-file-is-not-checked-out/

———————————————–

Dans la page de code, je récupérais SPLIMITEWebPartManager avant le checkout de la page en question.
Il faut d’abord :

  1. Faire le checkout de la page
  2. Recuperer l’objet SPLimitedWebPartManger

Ce post explique la manipulation

http://blogs.edwardwilde.com/2009/11/29/splimitedwebpartmanager-savechanges-throws-microsoft-sharepoint-webpartpages-webpartpageuserexception-the-file-is-not-checked-out/