Jak za pomocą kodu przesyłać dane do biblioteki dokumentów w MOSS 2007?
Poniżej zamieściłem przykład kodu w C# dzięki któremu możliwe jest stworzenie aplikacji przenoszącej zawartości folderu do biblioteki dokumentów w Microsoft Office SharePoint Server 2007:
// open site and get the spweb
SPSite site = new SPSite(Insert your site URL here);
SPWeb web = site.OpenWeb();
// open document library as a folder
SPFolder docoLibFolder = web.GetFolder(Insert the name of the document library here);
// upload document
FileStream fStream = File.OpenRead(Insert the path of the document to load here);
Byte[] Contents = new byte[Convert.ToInt32(fStream.Length)];
fStream.Read(Contents, 0, Convert.ToInt32(fStream.Length));
SPFile uploadedFile = docoLibFolder.Files.Add(documentNumber, Contents);
// check the document in if it is checked out
// (depends on the security settings of the document library)
if (uploadedFile.CheckOutStatus != SPFile.SPCheckOutStatus.None)
{
uploadedFile.CheckIn(Insert Comments Here);
}
Note that the file is returned to you when you add it to the ‘Files’ collection. Once you’ve got the SPFile you can get the actual SPListItem and add meta-data if required.
SPListItem listItem = uploadedFile.Item;
źródło: http://mosschampions.com/blogs/moss/archive/2007/01/04/How-to-Upload-a-Document-into-MOSS-2007-Programmatically.aspx