b33bs 0 Posted January 26, 2011 Report Share Posted January 26, 2011 Bom dia povo, sou novo aqui no Forum e também no que diz respeito a Sharepoint 2010. Ora, tenho um sharepoint 2010 instalado num servidor ao qual tenho acesso, mas queria, via csharp tentar aceder e sacar (tipo, getBytes() ou algo assim do genero) um documento duma determinada libraria, mas para ja nao tou a ter sucesso. Ja consegui criar programas que me permitam entrar no Sharepoint, consigo ter acesso a todas as listas e libraries, mas nao consigo aceder aos documentos. Acho que me esta a faltar algo, mas pra ja nao consigo encontrar nada na net que me ajude. alguma sugestao?? Obrigado, Abraco Link to post Share on other sites
b33bs 0 Posted January 27, 2011 Author Report Share Posted January 27, 2011 Boas a todos... ja consegui ter acesso a documentos e fazer download para o meu PC... Obrigado.. abraço Link to post Share on other sites
jpaulino 90 Posted January 27, 2011 Report Share Posted January 27, 2011 E qual foi a solução ? Link to post Share on other sites
b33bs 0 Posted January 31, 2011 Author Report Share Posted January 31, 2011 Ca vai a solucao: Criei uma console app using System; using System.IO; using System.Linq; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; using Microsoft.SharePoint.Client; using ClientOM = Microsoft.SharePoint.Client; namespace ConsoleApplication1 { class Program { static private void CopyStream(Stream source, Stream destination) { byte[] buffer = new byte[100000]; int bytesRead; do { bytesRead = source.Read(buffer, 0, buffer.Length); destination.Write(buffer, 0, bytesRead); } while (bytesRead != 0); } static void Main(string[] args) { ClientContext clientContext = new ClientContext("http://ServidorSharepoint"); List sharedDocumentsList = clientContext.Web.Lists.GetByTitle("Shared Documents"); CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = @"<View> <Query> <Where> <Contains> <FieldRef Name='FileLeafRef'/> <Value Type='Text'>.pdf</Value> </Contains> </Where> <RowLimit>1</RowLimit> </Query> </View>"; ListItemCollection listItems = sharedDocumentsList.GetItems(camlQuery); clientContext.Load(sharedDocumentsList); clientContext.Load(listItems); clientContext.ExecuteQuery(); if (listItems.Count > 0) { for (int i = 0; i < listItems.Count; i++) { ClientOM.ListItem item = listItems[i]; Console.WriteLine("\n nome do documento: {0}", item["FileLeafRef"]); FileInformation fileInformation = ClientOM.File.OpenBinaryDirect(clientContext, (string)item["FileRef"]); using (MemoryStream memoryStream = new MemoryStream()) { CopyStream(fileInformation.Stream, memoryStream); long len; len = memoryStream.Length; byte[] buffer = new byte[len]; buffer = memoryStream.GetBuffer(); try { FileStream fs = new FileStream(@"c:\" + (string)item["FileLeafRef"], FileMode.Create, FileAccess.ReadWrite); BinaryWriter bw = new BinaryWriter(fs); bw.Write(buffer); bw.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } } else Console.WriteLine("Document nao encontrado."); Console.ReadLine(); } } } Link to post Share on other sites
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now