I was making a simple console application to upload a zip file (with a WSP Listener solution) in the document library. This document library was located in the central admin, so I also wanted to find the central admin web application dynamic. I came up with the next solution:
// Set the path to the zip file and the name of the document library
string path = "c:\temp\testfile.zip";
string documentLibraryName = "WSPListener document library";
// Get the central administration web application and the upload folder
SPWeb centralAdminWeb = SPAdministrationWebApplication.Local.Sites[0].OpenWeb();
SPFolder uploadFolder = centralAdminWeb.Folders[documentLibraryName];
bool replaceExistingFiles = true;
SPFolder myLibrary = centralAdminWeb.Folders[documentLibraryName];
// Open a file stream to add the file in the document library
using (FileStream fileStream = File.OpenRead(path))
{
SPFile spFile = myLibrary.Files.Add(fi.Name, fileStream, replaceExistingFiles);
myLibrary.Update(); // save the file
// Get the corresponding SPItem to update some properties and start the installation
SPListItem item = spFile.Item;
item["InstallationStartTime"] = null;
item["InstallationEndTime"] = null;
item["InstallationStatus"] = "Install";
item["InstallationResult"] = "";
item.Update();
}
As you can see, it's very easy :)
83ff7ddb-fce2-4884-98d5-67e8c0112289|0|.0