Fragmentos de código: Subir un documento con metadatos
Warning: Use of undefined constant template_directory - assumed 'template_directory' (this will throw an Error in a future version of PHP) in /homepages/19/d221002526/htdocs/mundosharepoint/wp-content/themes/balic/single.php on line 9
Miércoles, 11 de julio de 2007
En esta nueva sección iré publicando pequeños fragmentos de código de ejemplo para realizar tareas en Sharepoint.
En nuestro 1er ejemplo de código vemos como se realizaría la carga de un documento con metadatos.
//Using required, especially System.IO; using System.Collections.Generic; using System.Collections; using System.Text; using Microsoft.SharePoint; using System.IO; namespace DocImport { public class DocManagement { //Some variables private string _DestUrlPath = string.Empty; private string _DestFolder = string.Empty; private SPSite _site = null; private SPWeb _web = null; public DocManagment(string DestUrl, string DestFolder) { _DestUrlPath = DestUrl; _DestFolder = DestFolder; _site = new SPSite(_DestUrlPath); _web = _site.OpenWeb(); } private bool _uploadDocument(string pdfFile, string txtFile) { try { //This is mandatory for avoiding an error _web.AllowUnsafeUpdates = true; //Use the list as a folder SPFolder folder = _web.GetFolder(_DestFolder); SPFileCollection files = folder.Files; //Get the file FileStream fStream = File.OpenRead(pdfFile); HashTable MetaDataTable = new HashTable(); MetaDataTable.Add("nom de colonne", "valeur"); //Set the destination url for SharePoint string url = _DestUrlPath + _DestFolder + "/" + Path.GetFileName(pdfFile); //Add document to the list with metadata, and overwrite an existing document with the same name SPFile currentFile = files.Add(url, fStream, MetaDataTable, true); fStream.Close(); return true; } catch (Exception x) { throw new Exception(x.Message); } } }
Via: Antoine’s blog for MOSS 2007 : SharePoint 2007: Upload a Document with Its Meta-Data
Etiquetas de del.icio.us: sharepoint