我有一段相同的行爲。最後,我們編寫了一個cmd工具,它運行「stsadm - o addsolution」,然後將所有xml文件添加到Web部件庫以用於Web部件。
有源(編輯小位):
string cmd_StsAdm = @"C:\Program files\Common files\Microsoft Shared\web server extensions\12\BIN\stsadm.exe";
string url_Site = "http://localhost";
string url_Web = "http://localhost";
if (string.IsNullOrEmpty(url_Web)) { url_Web = url_Web; }
Console.WriteLine("Deleting sharepoint solution");
string args_DeleteSolution = string.Format("-o deletesolution -name \"{0}\" -override", startInfo.fileNameWsp);
ShellWait(cmd_StsAdm, args_DeleteSolution);
string filePathWsp = "**** path to wsp file ****";
Console.WriteLine("Adding sharepoint solution");
string args_AddSolution = string.Format("-o addsolution -filename \"{0}\"", filePathWsp);
ShellWait(cmd_StsAdm, args_AddSolution);
Console.WriteLine("Deploy sharepoint solution");
string args_DeploySolution = "-o deploysolution -name \"{0}\" -local -allowGacDeployment -url \"{1}\" -force";
args_DeploySolution = string.Format(args_DeploySolution, startInfo.fileNameWsp, url_Web);
ShellWait(cmd_StsAdm, args_DeploySolution);
int counter = 0;
foreach (CWebPartVytvoreniInfo wpRslt in solutionInfo.WebParts) {
counter++;
string msg = string.Format("Aktivace web part {0} - {1} z {2}", wpRslt.Info.Nazev, counter, solutionInfo.WebParts.Count);
Console.WriteLine(msg);
string args_ActivateFeature = "-o activatefeature -id {0} -url {1}";
args_ActivateFeature = string.Format(args_ActivateFeature, wpRslt.Info.ID, url_Site);
ShellWait(cmd_StsAdm, args_ActivateFeature);
}
Console.WriteLine("Connecting to sharepoint site");
using (Microsoft.SharePoint.SPSite site = new Microsoft.SharePoint.SPSite(url_Site)) {
Microsoft.SharePoint.SPList ctg_WebParts = site.GetCatalog(Microsoft.SharePoint.SPListTemplateType.WebPartCatalog);
counter = 0;
foreach (WebPartInfo wpInfo in solutionInfo.WebParts) {
counter++;
string dirPath = System.IO.Path.Combine(wpInfo.DirectoryPath);
string fileName = wpRslt.Info.Nazev + ".webpart";
string filePath = System.IO.Path.Combine(dirPath, fileName);
string msg = string.Format("Uploading file '{0}' - {1} z {2}", fileName, counter, solutionInfo.WebParts.Count);
Console.WriteLine(msg);
using (System.IO.FileStream fstrm = OtevritSoubor(filePath)) {
ctg_WebParts.RootFolder.Files.Add(fileName, fstrm, true);
}
}
}
謝謝,在我的情況下,功能文件來自一個已啓動的項目,並且我添加的webparts沒有包含在這些功能中,所以我像你說的那樣添加了它,它像一個魅力一樣工作。 – 2015-02-06 10:20:00