开发者

Document XML data Sharepoint 2010 Silverlight

I have a document libraries where I save documents (je开发者_如何学编程). (from silverlight too, but that problem is already solved)

I want to use the object model of Sharepoint 2010 from a silverlight application to get the XML data of a document with ID=...

First I serialize a class and upload to the document library and then I want to get it...

That XML must contain an object to deserialize with XMLSerializer...

How can I do it?


First you'll want to get acquainted with the Silverlight Client Object Model, here's a starter, but there's quite a few others out there:

http://praveenbattula.blogspot.com/2010/03/sharepoint-2010-silverlight-client.html

Then you'll want to find oout how to query a list using CAML, and using the items in your resultset to get the Document in the library you're after.

You'll probably then want to stream the contents (using SPListItem.File.OpenBinaryStream()) into a reader of some sort so you can deserialize.


Here is a good set of information regarding the SharePoint Client Object Model:

http://msdn.microsoft.com/en-us/library/ee857094.aspx

Here is a specific example of how to query a list (e.g. Document Library) with the Client Object Model:

http://msdn.microsoft.com/en-us/library/ee857094.aspx#SP2010ClientOM_Using_CAML_Query_List

I really like this example on the .NET by Example site:

http://dotnetbyexample.blogspot.com/2011/03/sharepoint-client-object-model-sites.html

I liked the idea of creating the SharePointHelper class as a wrapper for the Client Object Model. It provides many examples including "Download a file from a document library"


I do it first:

  using (ClientContext ctx = new ClientContext("http://med02ws:47205/Documentos"))
                {
                    Web web = ctx.Web;

                    List docs = web.Lists.GetByTitle(tipo);

                    DocumentoObtenidoSP = docs.GetItemById(id);

                    ctx.Load(DocumentoObtenidoSP);
                    ctx.ExecuteQueryAsync(OnCargarDocumentoSucceess, OnSharepointFailure);
                }

     private void OnCargarDocumentoSucceess(object sender, ClientRequestSucceededEventArgs e)
{
                WebClient wc = new WebClient();
                wc.OpenReadCompleted += new OpenReadCompletedEventHandler(WebClient_OpenFileReadCompleted);
                wc.OpenReadAsync(new Uri("http://med02ws:47205" + DocumentoObtenidoSP.FieldValues["FileRef"].ToString()));
}

private void WebClient_OpenFileReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
//In e.Result you got the stream to XML Deserialize using the XMLSerializer
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜