SharePoint Dragons

Nikander & Margriet on SharePoint

Retrieve folder using client object model that has space in its name

You have to be a little bit careful when you’re retrieving a SharePoint folder name using the client object model that has a space in its name. The correct way to do it is to replace the space with “%20”:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Microsoft.SharePoint;

using Microsoft.SharePoint.Client;

namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            try

            {

                //string folderName = “/MyDox/Test”;

                string folderName = “/MyDox/Name%20withSpace”;

                ClientContext context = new ClientContext(“http://astro“);

                Web web = context.Web;

                List list = context.Web.Lists.GetByTitle(“MyDox”);

Folder folder = web.GetFolderByServerRelativeUrl(folderName);               

context.Load(context.Web);

                context.Load(list);

                context.Load(folder);               

                context.ExecuteQuery();

                Console.WriteLine(folder.Name);

            }

            catch (Exception err)

            {

                Console.WriteLine(err.Message);

            }

        }

    }

}

About these ads

2 responses to “Retrieve folder using client object model that has space in its name

  1. Bjoern H Rapp June 20, 2012 at 9:38 pm

    Hi Margriet. Nice sample, although I’d guess this line: List list = context.Web.Lists.GetByTitle(“MyDox”); and the corresponding Load() are leftovers.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 378 other followers

%d bloggers like this: