SharePhone

Today I released a basic version of SharePhone, my WP7 library for working with SharePoint sites. Binaries and source code can be found here: Codeplex

I’m currently porting this code from a more functional Silverlight project so I apologize if the source is a bit messy.

Anyway, the current release lets you open up any SharePoint 2007/2010 web and its sub webs and work with their lists and list items.

Here’s a short example how:

First we instantiate our context and supply the URL for the root web.

ClientContext ctx = new ClientContext("http://sharepointdev");
//supply credentials if needed
ctx.Settings.Credentials = new CredentialSettings { Domain = "<domain>", UserName = "<user>", Password = "<password>" };

Then we get our root web object (remember, Silverlight requires any web service call to be made asynchronously which is why this is the only method available in this library).

ctx.GetRootWeb((object s, SPWebLoadCompletedEventArgs result) => {
    SPWeb rootWeb = result.Webs[0];               
});

Next, let’s load all the lists available at the root web:

web.Lists.LoadCompleted += (object sender, SPListLoadCompletedEventArgs e) => {
    Deployment.Current.Dispatcher.BeginInvoke(() => {
        list1.ItemsSource = e.Lists;
    });
};
web.Lists.LoadAll();

list1 is a ListBox and it’s defined like this in XAML:

            <ListBox Name="list1">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Title}" Style="{StaticResource PhoneTextNormalStyle}"/>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

And we have our lists neatly listed out on our phone, ready to continue working with them. sample

Most of the operations on collections, such as sub webs on a web or lists or even list items in a list requires you first to load the collection like in the previous example (web.Lists.LoadAll()). The reason why I don’t load this data on first call is because I want to keep the data traffic at a minimum. Basically you load what you need and nothing more.

Next post I’ll show an example how to read list items, update the data and post them back to SharePoint using strong typed custom classes.

Advertisements

5 Responses to SharePhone

  1. MarkR says:

    I’m not sure what is going on.

    When I run this code against couple of my SP sites. I’m not getting any information back. It’s like it’s not find the SPWeb or List and there is no error occurring.

    It might be due to some SP Settings? blocking your code from accessing the site?

    Is their a SP site I run this code against to actually see this work?

    Thanks,
    Mark

    • Frode Hus says:

      If there’s no error occuring and no data returned, it sounds like no connection is being made. If there was an issue talking to SharePoints web services, such as error in the XML or not reaching the server, an exception should have been raised.
      You could use Fiddler (www.fiddler2.com) to sniff around on the network traffic and see what is being sent to your server and what is returned.

      An easy check to see if the web services are accessible is to open /_vti_bin/Webs.asmx in your favorite browser and see if you get a web service description up. If everything looks ok, I would need to have a look at your code and see if there’s any issues there…

  2. MarkR says:

    Actually, you can do the /_vti_bin/Webs.asmx in a broswer and it does work.

    And I’m following the posted code above with the proper values.

    E.G. – this is an open site… http://www.wssdemo.com/_vti_bin/Webs.asmx
    no need for credentials even.

    Still can’t get this dll to work with it.

    Thanks,
    Mark

    • Frode Hus says:

      I just did a quick test on the site you linked to and got an exception right away. Thing is, even though you are allowed to browse the Webs.asmx it won’t allow you to call any of the methods without credentials. The credentials are posted on http://www.wssdemo.com and once I added those to the call, everything worked fine.

      Here’s the code I used to test:
      ClientContext ctx = new ClientContext("http://www.wssdemo.com");
      ctx.Settings.Credentials = new CredentialSettings { Domain = "corp", UserName = "demouser", Password = "pass@word1" };

      ctx.GetRootWeb((object sender, SPWebLoadCompletedEventArgs e) => {
      e.Webs[0].Lists.LoadCompleted += new SPListLoadCompleted(Lists_LoadCompleted);
      e.Webs[0].Lists.LoadAll();
      });

      • MarkR says:

        Thanks for your help.

        I was using “http://www.wssdemo.com/”

        and not “http://www.wssdemo.com”.

        I had one extra forward slash at the end. Been fighting this most of the day.

        Thanks,
        Mark

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

%d bloggers like this: