以编程方式将网站另存为模板 - 在临时目录中生成解决方案文件时出错

时间:2014-04-28 14:35:27

标签: sharepoint sharepoint-2013 sitetemplate

我有一个要求,我需要以编程方式创建网站模板。 当我试图以编程方式将网站另存为模板时,我收到以下错误。 "在临时目录" 中生成解决方案文件时出错。 我已经完全控制了c:\ windows \ temp目录。我正在使用以下方法:

oWeb.SaveAsTemplate(templateName, templateTitle, tmplDesc, true);

(或)

string solutionFileUrl = SPSolutionExporter.ExportWebToGallery(oWeb,templateName, templateTitle,tmplDesc,SPSolutionExporter.ExportMode.FullReuse,true);

面临同样的问题。

我可以将root web保存为模板,如SPContext.Current.Web.SaveAsTemplate(templateName,templateTitle,tmplDesc,true); 但我需要将子网站保存为模板。

以下是我的ULS日志转储

  

System.Runtime.InteropServices.COMException:列表不存在。该   您选择的页面包含不存在的列表。它可能有   被另一个人删除了   user.0x81020026,   StackTrace:at   Microsoft.SharePoint.SPListCollection.EnsureListsData(Guid webId,   String strListName)at   Microsoft.SharePoint.SPListCollection.ItemByInternalName(Guid webId,   String listName)at   Microsoft.SharePoint.WebPartPages.ListViewWebPart.EnsureList()at   Microsoft.SharePoint.WebPartPages.ListViewWebPart.EnsureListAndView(布尔   requireFullBlownViewSchema)at   Microsoft.SharePoint.WebPartPages.ListViewWebPart.ShouldSerializeTitle()   在   Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterListViewWebPart.Write14_ListViewWebPart ...   ...(String n,String ns,ListViewWebPart o,Boolean isNullable,   布尔值needType)at   Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterListViewWebPart.Write15_WebPart(对象   o)在System.RuntimeMethodHandle.InvokeMethod(对象目标,   Object []参数,Signature sig,Boolean构造函数)at   System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,   Object []参数,Object []参数)at   System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags   invokeAttr,Binder binder,Object []参数,CultureInfo文化)
  在System.Xml.Serialization.TempAssembly.InvokeWriter(XmlMapping   mapping,XmlWriter xmlWriter,Object o,XmlSerializerNamespaces   namespaces,String encodingStyle,String id)at   System.Xml.Serialization.XmlSerializer.S ... ... erialize(XmlWriter   xmlWriter,Object o,XmlSerializerNamespaces名称空间,String   encodingStyle,String id)at   Microsoft.SharePoint.WebPartPages.WebPart.SerializeXml(XmlWriter的   writer,XmlSerializer xmls,Boolean shouldSerializeAll)at   Microsoft.SharePoint.WebPartPages.WebPart.SerializeWebPartXml(布尔   shouldExcludeSpecialProperties,TextWriter writer)at   Microsoft.SharePoint.WebPartPages.WebPart.WriteXmlAsUtf8(布尔   shouldExcludeSpecialProperties)at   Microsoft.SharePoint.WebPartPages.SPWebPartManager.GetWebPartXml(的WebPart   webPart,布尔值shouldUTF8Encode,布尔值   shouldExcludeSpecialProperties,布尔导出)at   Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager.ExportWebPart(的WebPart   webPart,XmlWriter编写者)   Microsoft.SharePoint.SPSolutionExporter ...   .... GetFilesInFolderTree(SPFolder文件夹,SortedList 2 filesInFolder, List 1个webViews)at at   Microsoft.SharePoint.SPSolutionExporter.GetFilesInFolderTree(SPFolder   文件夹,SortedList 2 filesInFolder, List 1 webViews)at   Microsoft.SharePoint.SPSolutionExporter.GetFilesInFolderTree(SPFolder   文件夹,SortedList 2 filesInFolder, List 1 webViews)at   Microsoft.SharePoint.SPSolutionExporter.GetFilesInWeb(字符串   workflowTemplateName)at   Microsoft.SharePoint.SPSolutionExporter.GenerateSolutionFiles()at   Microsoft.SharePoint.SPSolutionExporter.ExportWebAsSolution()at   Microsoft.SharePoint.SPSolutionExporter.ExportWebToGallery(SPWeb web,   String solutionFileName,String title,String description,ExportMode   exportMode,Boolean includeContent,String workflowTemplateName,   String destina ... ... tionListUrl,Action`1 solutionPostProcessor,   布尔值activateSolution)at   Microsoft.SharePoint.SPWeb.SaveAsTemplate(String strTemplateName,   String strTemplateTitle,String strTemplateDescription,Boolean   fSaveData)at   TemplateIssueProject.ProjectTemplate<> c__DisplayClass9.b__6()   在   Microsoft.SharePoint.SPSecurity<> c__DisplayClass5.b__3()   在   Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated   secureCode)at   Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback   secureCode,Object param)at   Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated   secureCode)at   TemplateIssueProject.ProjectTemplate.SaveTemplate(String webName,   String templateName,String template ...... ... Title,String tmplDesc)
  在TemplateIssueProject.ProjectTemplate.SiteCreation(String siteName)   在   TemplateIssueProject.TemplateIssewebpart.TemplateIssewebpart.btnSubmit_Click(对象   发件人,EventArgs e)at   System.Web.UI.WebControls.Button.RaisePostBackEvent(字符串   event.Web.UI.Page.ProcessRequestMain的EventArgument(布尔值   includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)
  在System.Web.UI.Page.ProcessRequest(布尔值   includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)
  在System.Web.UI.Page.ProcessRequest()处   System.Web.UI.Page.ProcessRequest(HttpContext context)at   ASP.WKPSTD_ASPX__1961116010.ProcessRequest(HttpContext context)at at   System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecut ...   ... ionStep.Execute()at   System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean&   完成同步)   System.Web.HttpApplication.PipelineStepManager.ResumeSteps(例外   错误)   System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext的   context,AsyncCallback cb)at   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest   wr,HttpContext context)at   System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr的   rootedObjectsPointer,IntPtr nativeRequestContext,IntPtr moduleData,   Int32标志)在   System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr的   rootedObjectsPointer,IntPtr nativeRequestContext,IntPtr moduleData,   Int32标志)在   System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletio ...   ... n(IntPtr pHandler,RequestNotificationStatus& notificationStatus)
  在System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr)   pHandler,RequestNotificationStatus& notificationStatus)at   System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr的   rootedObjectsPointer,IntPtr nativeRequestContext,IntPtr moduleData,   Int32标志)在   System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr的   rootedObjectsPointer,IntPtr nativeRequestContext,IntPtr moduleData,   Int32标志)

     

System.NullReferenceException:未将对象引用设置为实例   一个对象。在   Microsoft.SharePoint.SPSolutionExporter.GetFilesInFolderTree(SPFolder   文件夹,SortedList 2 filesInFolder, List 1 webViews)at   Microsoft.SharePoint.SPSolutionExporter.GetFilesInFolderTree(SPFolder   文件夹,SortedList 2 filesInFolder, List 1 webViews)at   Microsoft.SharePoint.SPSolutionExporter.GetFilesInFolderTree(SPFolder   文件夹,SortedList 2 filesInFolder, List 1 webViews)at   Microsoft.SharePoint.SPSolutionExporter.GetFilesInWeb(字符串   workflowTemplateName)at   Microsoft.SharePoint.SPSolutionExporter.GenerateSolutionFiles()at   Microsoft.SharePoint.SPSolutionExporter.ExportWebAsSolution()

     

访问/SitePages/MyTaskPage.aspx时出现应用程序错误,错误=错误   在临时目录中生成解决方案文件在   TemplateIssueProject.ProjectTemplate.SiteCreation(String siteName)
  在   TemplateIssueProject.TemplateIssewebpart.TemplateIssewebpart.btnSubmit_Click(对象   发件人,EventArgs e)at   System.Web.UI.WebControls.Button.RaisePostBackEvent(字符串   event.Web.UI.Page.ProcessRequestMain的EventArgument(布尔值   includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)

     

System.InvalidOperationException:生成解决方案文件时出错   临时目录。在   TemplateIssueProject.ProjectTemplate.SiteCreation(String siteName)
  在   TemplateIssueProject.TemplateIssewebpart.TemplateIssewebpart.btnSubmit_Click(对象   发件人,EventArgs e)at   System.Web.UI.WebControls.Button.RaisePostBackEvent(字符串   event.Web.UI.Page.ProcessRequestMain的EventArgument(布尔值   includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)

请建议/提供建议。

此致

2 个答案:

答案 0 :(得分:0)

下面的代码用于将网站保存为模板(根级/子网站)

using System.Management;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
Add Reference to your solution from the below path.

Reference Path: C:\Windows\winsxs\msil_system.management.automation_31bf3856ad364e35_7.1.7601.18071_none_a682d4c5c360dacf\System.Management.Automation.dll

RunspaceInvoke oRunSpaceInvoke = new RunspaceInvoke();
                    FullWebUrl = SPContext.Current.Site.Url + "/" + objTemplate.strWebName;
                    strScriptToSaveTemp = @"Add-PSSnapin Microsoft.SharePoint.PowerShell ; Set-ExecutionPolicy -ExecutionPolicy RemoteSigned ;" +
                                    "$oWeb = Get-SPWeb " + FullWebUrl + " ; $oWeb.SaveAsTemplate('" + objTemplate.strTemplateTitle + "','" + objTemplate.strTemplateName + "','" + objTemplate.strTemplateDesc + "',1) \n";
oRunSpaceInvoke.Invoke(strScriptToSaveTemp).ToString();

此致 马赫什 http://sharepointchampion.blogspot.in/2014/05/save-site-as-template-programatically.html

答案 1 :(得分:0)

如果您通过功能添加了任何字段,并且您的字段已覆盖=" FALSE",则网站导出将失败。如果需要将其设置为TRUE,则应该只使用Overwrite,因为默认值为FALSE。

这似乎是一个SharePoint错误。

您可能会在ULS日志中看到此属性。