Showing posts with label WSS. Show all posts
Showing posts with label WSS. Show all posts

Tuesday, 16 October 2012

LINQ to SharePoint: linq query filter on multivalue lookup

Situation:
I have a SharePoint Foundation 2010 environment with a document library. One of the metadata on the documents is a multivalue lookup to a category list.
I used SPMetal to create entity classes for easy usage of linq to the different lists and libraries inside the SharePoint site.
Problem:
Inside a visual web part, I was trying to execute a linq query on the document library, filtering on a given category.
Example code:

QualityDataContext dc = new QualityDataContext(SPContext.Current.Web.Url);
// some other steps made
var mySelectedCat = dc.MyCategories.OrderBy(p => p.Title).Where(p => p.id == "CategoryOfInterestID")

var docs = dc.MyDocLib.OrderBy(p => p.Title).Where(p => p.Categories.Contains(mySelectedCat));

This goes wrong because in this situation linq is messing up with the "p.Categories" en the entity "mySelectedCat"

Solution:
I have searched a lot, without getting a right, easy solution. Some mentioned to use the 'old' "SPWeb, SPList, SPQuery and so on"-way. Others where trying to believe you that the sample above is working.
Sorry folks, it's not. The problem is that querying on the multivalue lookup just works after the data has been retrieved. So I uses the ToList() method to the 'docs' part, just before filtering. For performance reasons, I first get the whole list (I just needed the whole list) and then do the filtering on the moment I needed it.
So this results in the following piece of code that I am using to fill a tree view, grouped on main category and sub category with links to documents.
Note the 'ToList()' I am using, twice just straight in the beginning of the using section. This is doing the trick.

using (QualityDataContext dc = new QualityDataContext(SPContext.Current.Web.Url))
{
 var cats = dc.MyCategories.OrderBy(p => p.Title).ToList();
 var docs = dc.MyDocuments.OrderBy(p => p.Title).ToList();

 SPTreeView tv = new SPTreeView();

 var mainCat = cats.OrderBy(p => p.Category).GroupBy(p => p.Category);
 
 // Step through the main categories
 foreach (var item in mainCat)
 {
  TreeNode catNode = new TreeNode{ Text = item.Key, Value = item.Key };
  
  var subCats = cats.OrderBy(p => p.Title).Where(p => p.Category == item.Key);

  // Step through the sub categories
  foreach (var subCat in subCats)
  {
   TreeNode subCatnode = new TreeNode { Text = subCat.Title, Value = subCat.Id.ToString() };
   var subdocs = docs.Where(p => p.Categories.Contains(subCat));

   if (subdocs.Count() > 0)
   {
    foreach (var doc in subdocs)
    {
     string docUrl = doc.Path + "/" + doc.Naam;
     subCatnode.ChildNodes.Add(new TreeNode { Text = doc.Naam, ToolTip = doc.Title, NavigateUrl = docUrl, Target = "_blank" });
    }
    subCatnode.Collapse();
    catNode.ChildNodes.Add(subCatnode);
   }
  }
  tv.Nodes.Add(catNode);
 }
 this.Controls.Add(tv);

Monday, 30 August 2010

Issues regarding ItemAdding and ItemUpdating EventReceivers when not firing

Today I succeeded in creating working event receivers for my custom list in a MOSS 2007 environment.
I had some difficulties to get those EventReceivers fired. I started with ItemAdding and ItemUpdating events. Those where installed and fired correctly.
But I actually needed the ItemAdded and ItemUpdated events. So I switched to them. And there the problems started.

One big problem is the caching (or something like that) of the elements.xml file of the feature (between brackets: don't forget to change the events in the elements.xml file!). Upgrade of the solution won't work!

You need to uninstall and remove the feature from the solution store. Make sure that all files of the feature are gone from the 12-hive\template\features\-folder.
To make sure that you really get rid of all the old version feature settings, do a IISRESET /NOFORCE. Until I did this, SharePoint remembers some settings of the old version feature. This is quit anoying and frustating and took me a while to get this sort out.

Thursday, 20 May 2010

Is SharePoint a PITA?

Sometimes SharePoint drives me crazy. But not only me. Google, our big friend shows the following results on some search terms:
  • moss 2007 problem: about 53.400.000
  • moss 2007 errors: about 8.160.000
  • moss 2007 bug: about 28.000.000
  • moss 2007 failed: about 4.560.000
  • moss 2007 failure: about 8.420.000
  • moss 2007 not working: about 23.300.000

  • sharepoint problem: about 8.270.000
  • sharepoint error: about 3.380.000
  • sharepoint bug: about 1.920.000
  • sharepoint failed: about 892.000
  • sharepoint failure: about 1.240.000
  • sharepoint not working: about 16.300.000

  • wss 3.0 problem: about 334.000
  • wss 3.0 errors: about 237.000
  • wss 3.0 bug: about 78.500
  • wss 3.0 failed: about 90.500
  • wss 3.0 failure: about 855.000
  • wss 3.0 not working: about 289.000
Do these numbers say something? I don't know. Is SharePoint a PITA? Well sometimes it definitely is!

Wednesday, 12 May 2010

A Solution for: SharePoint 2007 Workflow 'Failed on start'

The Problem:
I struggled some time to get my out-of-the-box (OOB) workflow working on a MOSS 2007 environment (Win2K3 64-bit). I got always the error 'Failed on Start'. The log file on the 12-hive shows two records like this:

w3wp.exe (0x0AF4) 0x0724 Windows SharePoint Services Workflow Infrastructure 72fs Unexpected RunWorkflow: System.ArgumentException: Value does not fall within the expected range. at Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties..ctor(SPWorkflow workflow, Int32 runAsUserId, String associationData, String initiationData) at Microsoft.SharePoint.Workflow.SPWinOEWSSService.MakeActivation(SPWorkflow workflow, SPWorkflowEvent e) at Microsoft.SharePoint.Workflow.SPWinOeEngine.RunWorkflow(Guid trackingId, SPWorkflowHostService host, SPWorkflow workflow, Collection`1 events, TimeSpan timeOut) at Microsoft.SharePoint.Workflow.SPWorkflowManager.RunWorkflowElev(SPWorkflow originalWorkflow, SPWorkflow workflow, Collection`1 events, SPRunWorkflowOptions runOptions)


w3wp.exe (0x0AF4) 0x0724 Windows SharePoint Services Workflow Infrastructure 98d7 Unexpected System.ArgumentException: Value does not fall within the expected range. at Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties..ctor(SPWorkflow workflow, Int32 runAsUserId, String associationData, String initiationData) at Microsoft.SharePoint.Workflow.SPWinOEWSSService.MakeActivation(SPWorkflow workflow, SPWorkflowEvent e) at Microsoft.SharePoint.Workflow.SPWinOeEngine.RunWorkflow(Guid trackingId, SPWorkflowHostService host, SPWorkflow workflow, Collection`1 events, TimeSpan timeOut) at Microsoft.SharePoint.Workflow.SPWorkflowManager.RunWorkflowElev(SPWorkflow originalWorkflow, SPWorkflow workflow, Collection`1 events, SPRunWorkflowOptions runOptions)

The Solution:
I search a lot, but didn't find a working solution. Finally I found it. It turns out that I had changed the account for the SharePoint - 80 application pool (don't remember why, but I did). But, I did this on IIS 7 and not using the Central Administration (CA).
Well, this was a wrong action. Changing the account of one of the SharePoint application pools must be done using the Central Administration (Serviceaccounts on the 'operations' page inside the CA).
And again, a big SharePoint miracle occured: the workflows started to work!

Friday, 12 March 2010

SharePoint 2007: Create and manage custom theme in a flexible way

Recently I started to create a custom theme. As you may know, when you change the theme of a site, SharePoint will get a copy of the chosen theme and place that in the content database.
And that is exactly not what I was looking for. I just want to have one single place where my custom theme is located so I can easily manage and change the theme. This will affect than all sites that are (already) using my custom theme.

Here is how to do this:
  1. Go to 12-hive\TEMPLATES\
  2. A good starting point is to make a copy of an existing theme that’s close to what you want to have. For example make a copy of the VINTAGE folder.
  3. Rename it to e.g. MYCUSTOMTHEME.
  4. Inside this folder, rename the VINTAGE.INF file to MYCUSTOMTHEME.INF.
  5. Open this MYCUSTOMTHEME.INF and replace all ‘vintage’ text into ‘mycustomtheme’ (without quotes).
  6. Add an entry for the MYCUSTOMTHEME in the SPTHEMES.XML

    <Templates>
    <TemplateID>mycustomtheme</TemplateID>
    <DisplayName>My Custom Theme</DisplayName>
    <Description>This is my cool customized theme</Description>
    <Thumbnail>images/thmycustomtheme.gif</Thumbnail>
    <Preview>images/thmycustomtheme.gif</Preview>
    </Templates>

    (Note: the thmycustomtheme.gif image can be created when you are done with customization of your theme. Place this file on 12-hive\TEMPLATE\IMAGES\)

  7. Instead of leaving the theme images and stylesheets inside the MYCUSTOMTHEME folder (12-hive\TEMPLATE\THEMES\MYCUSTOMTHEME) we need to move the images and stylesheets to be able to edit and see our changes immediate.
    a). Create subfolders called MYCUSTOMTHEME inside the following folders:
    i. \12\TEMPLATE\IMAGES\
    ii. \12\TEMPLATE\LAYOUTS\1033\STYLES\ (note: 1033 is dependent on your language)
    b). Move all images from the 12\TEMPLATE\THEMES\MYCUSTOMTHEME to 12\TEMPLATE\IMAGES\MYCUSTOMTHEME.
    c). Move the theme.css (and when using MOSS, mossExtensions.css) to \12\TEMPLATE\LAYOUTS\1033\STYLES\MYCUSTOMTHEME\. These two files you will use for your customizations.
    d). Go to 12\TEMPLATE\THEMES\MYCUSTOMTHEME\. There is one file left (mycustomtheme.inf).
    e). Create a new (text)file, called theme.css and open it.
    f). Add the following lines of code:

    @import "/_layouts/1033/STYLES/mycustomtheme/mossextensions.css";
    @import "/_layouts/1033/STYLES/mycustomtheme/theme.css";

    g). Now, when you set a site theme to your ‘mycustomtheme’, the theme.css you just created (with the import statements) are stored in the content database, but the site will use the the css-files on your file system. Now you are ready to edit your css files.
  8. Remember to refer to the images like: url(“/_layouts/images/mycustomtheme/)
The following pictures shows where the customtheme folders are located:


Monday, 8 March 2010

Release date SharePoint 2010 and Office 2010

Last Saturday, Microsoft announced the release date of both SharePoint 2010 en Microsoft Office 2010. Arpan Shah wrote:
"Today, we officially announced that May 12th, 2010, is the launch date for SharePoint 2010 & Office 2010. In addition, we announced our intent to RTM (Release to Manufacturing) this April 2010."

For consumers, Office 2010 will be available online and on retail shelves this June.
You can read more at http://blogs.technet.com/office2010/archive/2010/03/04/get-office-today-or-tomorrow.aspx and http://sharepoint.microsoft.com/businessproductivity/proof/pages/2010-launch-events.aspx

Tuesday, 2 March 2010

Site Tips: Branding SharePoint (WSS3.0 and MOSS2007)

Yesterday I started with branding SharePoint for one of our customers. Creating a custom theme is not that easy as it should be. I will come back later on that.
I found some useful sites on the internet. I want to share this one in particular with you:
This is a nice overview of the used style elements in SharePoint sites. You can easily find the corresponding element that are used in the stylesheets ( e.g. .ms-topnavselected) by using the index or screenshots.
The main site, http://www.heathersolomon.com/blog/articles/sp2007.aspx, shows a lot of information about the structure and customizations of sites.

Monday, 1 March 2010

Install WSS3.0 and MOSS 2007 on Windows 2008 Server R2

Installing SharePoint (either WSS 3.0 or MOSS 2007) on a Windows Server 2008 R2 is not just a 'next-next-finish' action.
At least, I tried it with MOSS 2007 with SP1. It will not work!

You will get the following error message:
Title: Program Compatibility Assistant
Message: No solutions found for Office SharePoint Server 2007 - Please read Microsoft Knowledge Base article: 962935

Don't try to find this KB article (it's here). It doesn't have anything to do with this particular problem.

The work-around for this problem is as follows:
  1. Copy the setup folder of WSS3.0 or MOSS 2007 to the local drive of the server, e.g. C:\Moss_Install
  2. Delete all content in the sub folder "updates"
  3. Download WSS3.0 SP2 (here) and MOSS 2007 SP2 (here)
  4. Open a command prompt and navigate to the folder where you put the both SP2 files
  5. Extract WSS 3.0 SP2 and MOSS 2007 SP2 using the command prompt:
    [filename] /extract:[path to copied setup folder step 1]\Updates /quiet
    Example:
    officeserver2007sp2-kb953334-x64-fullfile-en-us.exe /extract:c:\Moss_Install\Updates
    The SharePoint installation program will automatically read this folder to apply the patches.
  6. Optional: some people mention to delete the wsssetup.dll file. I didn't for the MOSS setup. It just works leaving this file.
  7. Start the setup.exe in the copied setup folder and you are on your way.

Tuesday, 1 September 2009

Your client does not support opening the list with Windows Explorer

In some cases people deals with the problem opening a SharePoint list in the Windows Explorer view. The problem that caused the message “Your client does not support opening the list with Windows Explorer”, can be solved with this:
  1. Download the Windows update 907306 and install this one (http://support.microsoft.com/kb/907306)
    By the way, you need to apply this on the client machine, because it is a local pc security issue

Normally this would be enough. If not, you need to perform the following steps (on the client machine):

  1. Start file explorer and go to Network Places
  2. Add a network place:

    A wizard is started with which you can add a network location:

  3. Type in the url of you SharePoint site
  4. The SharePoint site is now added a a network location and the problem should be solved by now.

Thursday, 18 June 2009

Login prompt for pdf icon in SharePoint

Today I solved a little, but annoying problem. It's about the problem of showing the pdf-icon after the PDF IFilter was installed on WSS 3.0 environment.

The problem was that when a user opened a document library with one or more pdf-documents in it, a login promt was shown. This was very annoying, because even when he entered his credentials again, it still continues to show the login prompt.
After cancelling this login prompt, it seems that the PDF icon was not shown.
After searching the internet, I saw some tips (like custom security settings in IE), but that didn't work out. Even a iisreset, which worked for a while, didn't do the trick.

The actual problem was the security on file level. The pdf icon file on the 12-hive\Template\Images\ had some troubles with the file security. I just opened another image from that directory, and made sure that the security permissions of the PDF icon file were identical with the other file. After fixing this, the problem with the login prompt was solved.

Tuesday, 28 October 2008

Hide Quick Launch Bar in SharePoint

There are several ways to deal with this 'problem'. I read an article about editing the stylesheets, masterpages and so on.
I also saw a post about using a content editor webpart, which is close to the way I am dealing with this issue. I uses a webpart and actually I don't know who's created this one, but it works fine.
It is the 'HideQuickLaunch' webpart.
Add this web part to the site collection where you want use it and add this web part on that page/site you want to hide the Quick Launch bar. That's all.

You can download the dwp-file (zipped) here.