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 !