Accessing document library in Sharepoint 2010 from Silverlight application...


I have a silverlight web gallery application that I embeded into sharepoint .. I am picking up the images for viewing from the webserver but i want to change it to a list in sharepoint ... the obstacles I am facing are 1- Since silverlight does not support other dlls i can not reference Microsoft.Sharepoint library to silverlight application... so i can not have SPWEB,SPSITE objects whic allow me to access the library.. I am a newbie so I really need step by step way to access document library... I am told that I need to write a web service if so how can I  do that since i am a newbie i havent done that before how can i do that step by step guide ??  another thing they advised me to use.. silverlight client object model how can i do this with that if that would be easier step by step guide I need again... or what can be an alternative pls i need help with this..
fatihdiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vikas413Commented:
HI, you can use built in SP webservices to access Document libraries of SharePoint site...
here is the useful links for that
get items using web service: http://dotnetdreamer.com/2009/06/04/moss-web-services-accessing-sharepoint-list-data/
above alternative is old way to do it i.e. MOSS 2007 way. ;)

Now in SharePoint 2010 they have came up with client obejct model which can be used from Silverlight itself. the dll can be found @ 14 hive i.e. '14\isapi\Microsoft.SharePoint.Client.dll'

here is a best blog series whch you can use to start up and develope you application

http://andreasglaser.net/post/2010/01/17/SharePoint-2010-Client-Object-Model-e280a6-becoming-a-SP2010-developer-Part-1.aspx

let me know if you need any further information on this..


0
MsShadowCommented:
Follow what Vikas said. For what you are trying to accomplish I would follow the client object model post, there are specific client dll's for Silverlight (they also work with SL 4)
0
fatihdiAuthor Commented:
hi i still have problem i am able to add

using Microsoft.SharePoint.Client;   to using namespace part of the program and I am able to  create ClientContext object and point it to the site i am using.  Now site, site.lists  comes as recognized keywords in my silverlight application, after adding Microsoft.Sharepoint.Client.Silverlight and Microsoft.Sharepoint.Client.Silverlight.Runtime dlls but now i need the code to get inside a sharepoint document library and get the images that are located in this document library and use images in my silverlight application  i used


            ClientContext ctx = new ClientContext("http://sharepoint-one");
            Web site = ctx.Web;
            ctx.Load(site);
            ctx.Load(site.Lists);
            //ctx.Load(site, x => x.Lists.Where(l => l.Title != null));
            ctx.ExecuteQuery();
            foreach (List list in site.Lists)
            {

            }
        }

this code but it gave error stating list is not initialized? i know i need to use something similar ,i am a newbie so i dont know how to achieve this what is the code for me to achieve what i want?


// old version i need to change it for taking the p11.jpg from document library

 this._thumbnails.Add(
             new Thumbnail
             {

                 //Picture = PREFIX +
                 //    "0/03/JROppenheimer-LosAlamos.jpg" +
                 //    "/200px-JROppenheimer-LosAlamos.jpg"

                 Picture = PREFIX + "p11.jpg"
             }
         );


.. I want to take the pictures from the document library instead of web server etc.. in my silverlight application .. How can I achieve this ? I need source code for retriving the files inside the document library and provide it to my web gallery silverlight application in the attachment you can see that i was adding the pictures with this.thumbnails.Add object  now instead i need to make use of the ClientContext ,Site.Lists etc ... to achieve this...... pls i need help ..I am attaching the code I used to achieve it but it gave an error that list collection did not initialize ?? please check the snapshot as well thank you for helping....


5.JPG
0
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

MsShadowCommented:
Take a look at this example, it explains it indepth.
Imho you should remove the ExecuteQuery line, but aint got time to check it in detail.

http://fyeomans.wordpress.com/2009/12/30/simple-sharepoint-2010-silverlight-client-object-model-example/
0
fatihdiAuthor Commented:
Thanks for the link it is really nice it accessed the list and displays the details about the list .. But what i specifically need to get is the items inside the list how can i achieve this I need this part of the code . I need a code to get the items inside a specific list or document library... I dont need the properties of the list to display How can I get the actual item inside the list and give this file as an input for my silverlight application to display the object?? your link just shows the way  to display all the list in a site and the properties of the list..what about retrieving the items inside a list? .. thank you in advance!!!
0
fatihdiAuthor Commented:
thank you for the links guys ... I will try them but from the one of the first links when i try to view the title of a  list ... I got an error, the details of the error are in the attachment ,it says property or field is not initialized ..what does that mean? I dont want to initiazilze it bring me the title of the list or the items of the list i am requesting this but i get an error stating property or field is not initialized.. pls check the screenshot  i have the error there what am i doing wrong?
1.jpg
0
MsShadowCommented:
change context.Load(_list) to
context.Load(_list, l => l.Title);
0
vikas413Commented:
replace your line of

context.ExecuteQueryAsync(.......);

with

context.ExecuteQuery();

and then try it out..

what has happen,is you have made async call and immediately after calling you are trying to use list properties.. which will be initiated only after call is over and you can access that in delegate function which you have provided in 'ExecuteQueryAsync'.i.e.something like onlistdetalisrequsetsuccess....

if you want to access properties in same method then use ExecuteQuery() function instead.. which is synchronized and return only after loading all properties of list..

hope this will help you to understand why that error was there..


it's quite tricky to work with client OM.. you need to understand that you need to executequery only with the last object which you want to load.. as in above

0
fatihdiAuthor Commented:
and also again i modified the code a little bit..I found the function GetItems of the list and tried to get the count of it to test if i am able to access to list information but it failed stating that The collection has not been initialized. It has not been requested or the request has not been executed.It may need to be explicitly requested.
2.jpg
0
vikas413Commented:
ClientContext clientContext = new ClientContext("http://myserver");
Web web = clientContext.Web;
List list = web.Lists.GetByTitle("Employee");
CamlQuery query = new CamlQuery();
query.ViewXml = @"<View>
    <Query>
      <Where>
        <Eq>
          <FieldRef Name='FirstName'/>
          <Value Type='Text'>Sohel</Value>
        </Eq>
      </Where>
    </Query>
  </View>";

ListItemCollection listItems = list.GetItems(query);
clientContext.Load(listItems, li => li.Include(i => i["FirstName"],i=>i["LastName"]).Where(i=>i["FirstName"].ToString()=="sohel");
clientContext.ExecuteQuery();

use above code..
and have you tried to go through any of above links which are posted in by various experts..?

0
fatihdiAuthor Commented:
@ MsShadow and Vikas413

what you recommmended just made my code different errors... @ Vikas413...after i did what you said i got the error:  the method or property that is called may block the UI thread and it is not allowed. Please use background thread to invoke the method or property for example using system.threading.threadpool.queueuserworkitem method to invoke the method or property... please see the error snapshot.. thank you very much by the way..you are helping me alot.. i am sorry i am a newbie to that..
3.jpg
0
fatihdiAuthor Commented:
@vikas
              I think i am getting too general answers let me specify my case, I have a picture library, in  this picture library i will have jpg images I want to display each of them in my silverlight webpart inside sharepoint..   so i dont have a condition First Name= sohel i will take everything one by one from document library and use it in silverlight app. ...how should the CAML query look like then?  and also clientContext.Load() command how should it look like? in the above code you have given
0
vikas413Commented:
here is the post which explains how to use client OM from silverlight application .. and I have created silverlight project out of it.. and instead of deploying it using SP empty project template..you can directly upload xap file in some document library and target it to silverlight webpart as explained in blog..

after this you only need to do one thig.. showing your images from picture List .. above solution can give you url of each image.. you can target source property of image to that url as well.

hope this will solve all your problems.. you need to just copy paste the code in proper place to create silverlight project
0
vikas413Commented:
one more ready made solution from where you can use some part..
http://karinebosch.wordpress.com/2009/01/22/22/
0
fatihdiAuthor Commented:
@vikas you said here is the post that explains how to use client OM but there is no post ?? i guess you forgot to provide the link can you pls check. and thanks by the way...
0
fatihdiAuthor Commented:
hi vikas?? where is the post that you mentioned above?
0
vikas413Commented:
Sorry for that
was out of town and no internet access..;(

here is that link

http://www.synergyonline.com/blog/blog-moss/Lists/Posts/Post.aspx?ID=118
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.