Podemos subir documentos mediante código. Pero lo que puede ser un poco más dificil de ver es cómo subir el documento y algunos metadatos adjuntos. No pasa nada, aquí teneis la solución. El truco es pasarle una tabla hash con los datos que nos interesan.
private bool _uploadDocument(string pdfFile, string txtFile) 
{
try 
{
   //This is mandatory for avoiding an error_web.AllowUnsafeUpdates = true;
   //Use the list as a folderSPFolder folder = _web.GetFolder(_DestFolder);
   SPFileCollection files = folder.Files;
   //Get the fileFileStream fStream = File.OpenRead(pdfFile);
   HashTable MetaDataTable = new HashTable();
   MetaDataTable.Add(”nom de colonne“, “valeur“);
   //Set the destination url for SharePointstring url = _DestUrlPath + _DestFolder + “/” + Path.GetFileName(pdfFile);
   //Add document to the list with metadata, and overwrite an existing documentwith the same name
   SPFile currentFile = files.Add(url, fStream, MetaDataTable, true);
   fStream.Close();
   return true;
} 
catch (Exception x) 
   {throw new Exception(x.Message);}
}
saludos,
Juan Alcalá
No hay comentarios:
Publicar un comentario