1
votes

I'm creating an app that will be configurable by the end-user to access SharePoint lists, on various different SharePoint sites, that are entered by the user.

All of the examples for reading SharePoint lists I've come across online are of the form:

  1. Open or create a Visual Studio project.
  2. In Solution Explorer, right-click the References node, and then click Add Service Reference.
  3. In the Address box, type the URL to the target site and append /_vti_bin/ListData.svc. For example, the address for the site intranet.wingtip.com would be http://intranet.wingtip.com/_vti_bin/ListData.svc.
  4. Change the default name in the Namespace box from ServiceReference1 to something more appropriate, such as WingtipSite.
  5. etc, etc, etc

This method creates proxy classes within your project based on the specified server reference. However, in my case, the server/site is not known at design time, only runtime by reading the sites/lists specified by the user. How would one go about doing that (reading the list via http://intranet.wingtip.com/_vti_bin/ListData.svc, but at runtime only)?

Note: I am making this call from a different machine than the one running Sharepoint.

3

3 Answers

2
votes

There are a couple answers.

If the lists schemas will be consistent across all the sites you are querying, you can still use the generated proxy. When you create the DataContext, you just need to pass in the URI to the ListData.svc for the site chosen by the user.

If not, then you can use an ASP.NET WebRequest with an appropriately formatted URI and parse out the ATOM or JSON response that comes back.

For more information on using the REST APIs, check out this talk from the 2009 SharePoint Conference

http://msdn.microsoft.com/en-us/sharepoint/ff462048

0
votes

You can set the URL in your proxy class at runtime with the Url property.

0
votes

SharePoint does not provide a proxy class for their web services. Therefore it's not possible to set the url at runtime. WHat I have had to do is add 2 service references and then paramaterize which one I will access. I use a config setting to determine which one to access. If the site name changes or list changes, then I need to remove the references, re-add them, recompile and redeploy. There is no way to change the SharePoint site/list at runtime. Have been searching for 3 days for an answer. Microsoft does not know how to accomplish this.