Wednesday, July 22, 2009

Parsing SharePoint delimited Multiple Value Lookup field values from web service results

When you query a list that contains a Lookup Column that allows multiple select values the value is returned like the following:

ows_MyMultipleSelectLookupField="1;#Foo;#2;#Foo Bar"

Yes, there’s that delimiter (;#) again.

The following two methods can help you get the Lookup values selected in the item.

/// <summary>
///
Remove the nasty delimiter
/// This can be used when returning multiple select lookup field values from a SharePoint list via a web service
/// Ex: ows_MyMultipleSelectLookupField="1;#Foo;#2;#Foo Bar"
/// returns Foo, Foo Bar
/// </summary>
/// <param name="sFieldValue"></param>
/// <returns>
List of string values</returns>
public static List<string> GetDelimitedLookupValuesList(string sFieldValue)
{
List<string> results = new List<string>();

System.Text.RegularExpressions.Regex regexMultiValueField = new System.Text.RegularExpressions.Regex(@"(?<id>(\d+));[#](?<value>[(\w*)+\s]+)",
System.Text.RegularExpressions.RegexOptions.Compiled);
System.Text.RegularExpressions.Match choice = regexMultiValueField.Match(sFieldValue);

while (choice.Success)
{
results.Add(choice.Groups["value"].Value);
choice = choice.NextMatch();
}

return results;
}

/// <summary>
///
Remove the nasty delimiter
/// This can be used when returning multiple select lookup field values from a SharePoint list via a web service
/// Ex: ows_MyMultipleSelectLookupField="1;#Foo;#2;#Foo Bar"
/// returns {1,Foo} {2,Foo Bar}
/// </summary>
/// <param name="sFieldValue"></param>
/// <returns>
Dictionay of id,value pairs</returns>
public static Dictionary<string, string> GetDelimitedLookupValuesDictionary(string sFieldValue)
{
Dictionary<string, string> results = new Dictionary<string, string>();

System.Text.RegularExpressions.Regex regexMultiValueField = new System.Text.RegularExpressions.Regex(@"(?<id>(\d+));[#](?<value>[(\w*)+\s]+)",
System.Text.RegularExpressions.RegexOptions.Compiled);
System.Text.RegularExpressions.Match choice = regexMultiValueField.Match(sFieldValue);

while (choice.Success)
{
results.Add(choice.Groups["id"].Value, choice.Groups["value"].Value);
choice = choice.NextMatch();
}

return results;
}


Usage:



//returns Foo, Foo Bar
List<string> myValues = GetDelimitedLookupValuesList("1;#Foo;#2;#Foo Bar");

//returns 1,Foo 2,Foo Bar
Dictionary<string,string> myValues = GetDelimitedLookupValuesDictionary("1;#Foo;#2;#Foo Bar");

Thursday, June 18, 2009

Getting SharePoint’s Explorer View in IE8 on Windows Server 2003

If you get this error when viewing a Document Library in SharePoint 2007:

“Please wait while Explorer View is loaded. If Explorer View does not appear, your browser may not support it.”

Most likely your WebClient service is not running on your local machine.  Simply crank it up using the following steps.

  1. Go to START >> RUN
  2. Type services.msc
  3. Locate the WebClient service
  4. Open the Properties

clip_image001

  1. Start up type to Automatic (otherwise on the next boot you will have this issue again)
  2. Click Apply
  3. Click Start
  4. Click OK

Wednesday, June 10, 2009

Getting a client side created InfoPath 2007 form in to a InfoPath Visual Studio project

Do you have an InfoPath form that was created in the InfoPath client and now you want to add it to a Visual Studio InfoPath project?

Here are the basic steps.. Follow along kids.

  1. Extract the source files from your client side form in to a directory called ClientSource. (you should know how to do this)
  2. Create a new InfoPath project in Visual Studio
  3. Close the open xsf file in Visual Studio
  4. Delete all the files under InfoPath Form Template directory in the Visual Studio solution
  5. In the ClientSource directory, edit the manifest.xsf file in NotePad++ or your favorite text editor and make the following changes.
    1. Delete the attributes "publishUrl and "trustLevel" (if exists) of the xsf:DocumentClass element
    2. Delete the properties xsf:property name="componentId" and xsf:property name="xmlToEditName"
    3. Add the sibling <xsf2:managedCode projectPath="path to and including csproj" language="CSharp" version="2.0" enabled="yes"></xsf2:managedCode> under xsf:extensions/xsf:extension/xsf2:solutionDefinition/xsf2:offline
      1. Path to and including csproj, ex: "C:\infopathForms\myIPFormProj\myIPFormProj.csproj”
      2. language value could also be VisualBasic, if you have create a VB project.
    4. Add the attribute scriptLanguage="managedCode"as the first attribute of xsf:applicationParameters/xsf:solutionProperties
    5. Save your changes
  6. Open template.xml in a text editor and make the following change
  7. In your Visual Studio project, right click on InfoPath Form Template folder and choose Add >> Existing Item.
  8. Navigate to your ClientSource directory
  9. Change the object type dropdown to ALL Files (*.*)
  10. Select ALL the files in the directory and click ADD
    1. NOTE: you want to bring in all the files so that you bring in all your data connections, resource files, view styles…
  11. In Visual Studio double click on manifest.xsf
  12. When/If prompted to save changes and publish, blah blah blah… click OK
  13. Build your project

That’s it…

Thursday, April 16, 2009

Sync with SharePoint calendar causes Outlook to crash

This issue is caused when there is an "Exceptions to Recurring Event"

Root Cause:
Older calendar items brought over from SharePoint 2003 that had exception on the recurrence.

Workaround:
Delete all the calendar items that have an "Exception to Recurring Event", except Recurring Events that have an Exception and are Prefixed with "Deleted:" Like as follows:

clip_image001

NOTE: you must follow the instructions below to delete the items with the exception. If you try to delete the items without the instructions below you will get the following error.

clip_image002

How:

  1. Create a view that groups by Recurrence
  2. Look for items where the Recurrence icon has a slash through it
    listitems
  3. Click on the items edit menu and select Edit Item
    clip_image004
  4. The Recurrence section should look like the following (it will have Custom selected)
    clip_image005
  5. Select Yearly, you will be prompted by SharePoint
    clip_image006
  6. Click Ok
  7. Click Ok on the EditForm.aspx page and you will be prompted, again.
    clip_image007
  8. Click Ok
  9. Open the items menu again and select Delete Item
    clip_image008
  10. If you are prompted to send the item to the recycling bin, click OK
    clip_image009
  11. Repeat these steps for all items that have an exception to a recurring event.

If you have cleaned up all the corrupt items, you should be able to sync your SharePoint calendar to Outlook .

Monday, March 23, 2009

Cannot connect to SharePoint list from link in email

I am going to describe the issue using a Task List as an example, but this issue affects all lists in SharePoint that you can connect to Outlook.

After clicking on the “Connect to this Task List” link in an email you receive the following error:

Task 'SharePoint' reported error (0x800401F3): 'Unknown Error 0x800401F3'

Let’s look at the problem:
  1. Click on the “Connect to this Task List” link in the email that was sent from the task list.
    emailLink
  2. In the opened prompt, click "Yes"
    link1
  3. You will get the following error
    image
  4. Click the close button (The red X) and  Navigate to Tools >> Account Settings…
    image
  5. In the Account Settings windows, click on the SharePoint Lists tab, select the list you are getting the error with and click on Remove.
    AccountSettings
  6. Click Yes, when prompted to remove the Task List from the Account Settings list
    image 
  7. Click Close to exit the Account Settings window.
Workaround:
  1. Navigate to the SharePoint Task List
  2. Click Actions >> Connect to Outlook
    image
  3. When prompted “Connect this SharePoint Task List to Outlook”, Click Yes
    CorrectURL
  4. The Task List will now be displayed in Outlook
    tasklists

The Issue:

When you click on the “Connect to this Task list” link in the email you are presented with the following prompt:
link1

When you click on “Connect to Outlook” from SharePoint you are presented with the following prompt:
CorrectURL 

Notice the missing trailing whack in the prompt from the link in the email, that is the issue.

Monday, January 5, 2009

How to add,update,delete site columns by using SharePoint's Webs WebService

I have found examples on how to do this, unfortunately none of them worked.  The missing attribute of ID from the newFields node was the issue with the examples.  The following should give you the idea.

            //webs webservice
wsWebs.Webs websService = new SiteColumnTester.wsWebs.Webs();

//url for the webservice
websService.Url = "http://localhost/sites/Tony/_vti_bin/Webs.asmx";

//credential
websService.Credentials = System.Net.CredentialCache.DefaultCredentials;

//xmldocument object
XmlDocument xDoc = new XmlDocument();

//Fields to be added
XmlNode newFields = xDoc.CreateNode(XmlNodeType.Element, "Fields", "");

//Fields to be updated
XmlNode updateFields = xDoc.CreateNode(XmlNodeType.Element, "Fields", "");

//Fields to be deleted
XmlNode deleteFields = xDoc.CreateNode(XmlNodeType.Element, "Fields", "");

//When adding a new field, make sure to give it an ID or it will not create the field
newFields.InnerXml = "<Method ID='1'><Field ID='{1C8452A0-F3BD-4a70-85D7-B35BF5EC8CE8}' Name='fieldName' DisplayName='fieldDisplayName' Hidden='FALSE' Type='Text'/></Method>";
//Update a field
updateFields.InnerXml = "<Method ID='2'><Field Name='fieldName' DisplayName='fieldDisplayName' Type='Text' Group='Tony'/></Method>";
//Delete a field
deleteFields.InnerXml = "<Method ID='3'><Field Name='fieldName'/></Method>";

XmlNode UpdateColumnsResponse = websService.UpdateColumns(newFields, updateFields, deleteFields);

MessageBox.Show(UpdateColumnsResponse.OuterXml);

Happy Coding!