jueves, 12 de septiembre de 2013

Sharepoint - Subir ficheros a Sharepoint

Metodo principal

     listService.Lists listados = new listService.Lists();
            Copy.Copy copy = new Copy.Copy();
            listados.UseDefaultCredentials = true;
            copy.UseDefaultCredentials = true;
            listados.Url = "http://127.0.0.1/_vti_bin/Lists.asmx";
            copy.Url = "http://127.0.0.1/_vti_bin/Copy.asmx";
            string nombre = "README.txt";
            Copy.CopyResult[] cResultArray = null;
            string destination = "Documents/directorio 1" + "/" + nombre;
            string[] destinationUrl = { destination };
            Copy.FieldInformation documentTypeField = new Copy.FieldInformation();
            documentTypeField.DisplayName = "DocumentType";
            documentTypeField.Type = Copy.FieldType.Text;
            documentTypeField.Value = nombre;
            Copy.FieldInformation titleField = new Copy.FieldInformation();
            titleField.DisplayName = "Title";
            titleField.Type = Copy.FieldType.Text;
            titleField.Value = nombre;
           
            //Associate metadata
            Copy.FieldInformation[] filedInfo = { documentTypeField, titleField };

        
            byte [] datos = GetFileFromFileSystem(@"C:\\Documentation\README.txt");

            copy.CopyIntoItems(destination, destinationUrl, filedInfo, datos, out cResultArray);
          


     //La respuesta si fue bien te viene en cResultArray


Metodos accesorios


///
        /// Read file and return bytes
        ///

        /// file path
        /// file bytes
        private byte[] GetFileFromFileSystem(string path)
        {
            byte[] fileBytes = null;
            if (File.Exists(path))
            {
                //read the file.
                using (FileStream fs = File.Open(path, FileMode.Open))
                {
                    fileBytes = new byte[fs.Length];
                    fs.Position = 0;
                    fs.Read(fileBytes, 0, Convert.ToInt32(fs.Length));
                }
            }
            return fileBytes;
        }

No hay comentarios:

Publicar un comentario