DataFormWebPart 迁移问题

近来, 项目组一同事,要把一个网站中的DataFormWebPart迁移到另外一个网站下,

这个DataFormWebPart 的SPDataSource 的DataSourceMode="List",也就是针对但列表查询,

默认情况下,SPDataSource 和 DataFormWebPart 的很多属性和参数都是ListID(GUID),这就意味着,你迁移的时候要

修改ListID,

网络上很多关于怎么迁移的方案,但是自己试试,并不是那么好使。

http://blogs.msdn.com/b/joshuag/archive/2008/11/10/easily-making-the-data-form-web-part-reusable.aspx

http://blog.jussipalo.com/2011/11/challenge-youre-working-with-sharepoint.html

http://www.cnblogs.com/jhobo/archive/2008/09/01/1281090.html

 
大致说的都是 修改SPDataSource 的ListID 为ListName,然后导出然后怎么地
我也测试许久,
最后是把几乎所有的ListID都修改成ListName,然后复制到另外一个网站的页面, 经常出错,
很多时候你修改DataFormWebPart 的ListName会报错,
 
最后一次成功是把机会所有的ListName设为空值,仅仅SPDataSource 的ListID修改为ListName并有值。
但是导出后,再导入还是报错。
 
最后想到为啥不在导出后直接修改.webpart文件,
于是,测试,
到处成.webpart文件后,把所有的ListID修改成ListName留空,除了SPDataSource 的和DataFormWebPart 的一个属性
还删除一个ListID的属性。
 
结果成功。
<webParts>
  <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
    <metaData>
      <type name="Microsoft.SharePoint.WebPartPages.DataFormWebPart, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
      <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
    </metaData>
    <data>
      <properties>
        <property name="InitialAsyncDataFetch" type="bool">False</property>
        <property name="ChromeType" type="chrometype">Default</property>
        <property name="Title" type="string">Questions</property>
        <property name="Height" type="string" />
        <property name="CacheXslStorage" type="bool">True</property>
        <property name="XslLink" type="string" null="true" />
        <property name="AllowZoneChange" type="bool">True</property>
        <property name="AllowEdit" type="bool">True</property>
        <property name="XmlDefinitionLink" type="string" />
        <property name="DataFields" type="string">@Title,Question;@EventID,EventID;@Answer,Answer;@AnsweredBy,AnsweredBy;@EventTitle,EventTitle;@Answered,Answered;@Author,Created By;@ID,ID;@ContentType,Content Type;@Modified,Modified;@Created,Created;@Editor,Modified By;@_UIVersionString,Version;@Attachments,Attachments;@File_x0020_Type,File Type;@FileLeafRef,Name (for use in forms);@FileDirRef,Path;@FSObjType,Item Type;@_HasCopyDestinations,Has Copy Destinations;@_CopySource,Copy Source;@ContentTypeId,Content Type ID;@_ModerationStatus,Approval Status;@_UIVersion,UI Version;@Created_x0020_Date,Created;@FileRef,URL Path;@ItemChildCount,Item Child Count;@FolderChildCount,Folder Child Count;</property>
        <property name="AutoRefreshInterval" type="int">60</property>
        <property name="NoDefaultStyle" type="string">TRUE</property>
        <property name="ListDisplayName" type="string" null="true" />
        <property name="AutoRefresh" type="bool">False</property>
        <property name="ViewFlag" type="string">8</property>
        <property name="ListUrl" type="string" null="true" />
        <property name="AllowConnect" type="bool">True</property>
        <property name="Description" type="string" />
        <property name="AllowClose" type="bool">True</property>
        <property name="ShowWithSampleData" type="bool">False</property>
        <property name="ParameterBindings" type="string">
      &lt;ParameterBinding Name="ListID" Location="None" DefaultValue="{C11B955E-DB37-4382-80D2-4E9BD715FBE5}"/&gt; 修改
      &lt;ParameterBinding Name="dvt_apos" Location="Postback;Connection"/&gt;
      &lt;ParameterBinding Name="ManualRefresh" Location="WPProperty[ManualRefresh]"/&gt;
      &lt;ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/&gt;
      &lt;ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/&gt;
      &lt;ParameterBinding Name="dvt_startposition" Location="Postback" DefaultValue=""/&gt;
      &lt;ParameterBinding Name="dvt_firstrow" Location="Postback;Connection"/&gt;
      &lt;ParameterBinding Name="dvt_nextpagedata" Location="Postback;Connection"/&gt;
     </property>
        <property name="Xsl" type="string">&lt;xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal"&gt;
 &lt;xsl:output method="html" indent="no"/&gt;
 &lt;xsl:decimal-format NaN=""/&gt;
      &lt;xsl:param name="dvt_apos"&gt;'&lt;/xsl:param&gt;
      &lt;xsl:param name="ManualRefresh"&gt;&lt;/xsl:param&gt;
      &lt;xsl:param name="dvt_firstrow"&gt;1&lt;/xsl:param&gt;
      &lt;xsl:param name="dvt_nextpagedata" /&gt;
      &lt;xsl:variable name="dvt_1_automode"&gt;0&lt;/xsl:variable&gt;
      &lt;xsl:template match="/"&gt;
       &lt;xsl:choose&gt;
        &lt;xsl:when test="($ManualRefresh = 'True')"&gt;
    &lt;table width="100%" border="0" cellpadding="0" cellspacing="0"&gt;
     &lt;tr&gt;
      &lt;td valign="top"&gt;
       &lt;xsl:call-template name="dvt_1"/&gt;
      &lt;/td&gt;
      &lt;td width="1%" class="ms-vb" valign="top"&gt;
       &lt;img src="/_layouts/images/staticrefresh.gif" id="ManualRefresh" border="0" onclick="javascript: {ddwrt:GenFireServerEvent('__cancel')}" alt="Click here to refresh the dataview."/&gt;
      &lt;/td&gt;
     &lt;/tr&gt;
    &lt;/table&gt;
   &lt;/xsl:when&gt;
        &lt;xsl:otherwise&gt;
         &lt;xsl:call-template name="dvt_1"/&gt;
   &lt;/xsl:otherwise&gt;
       &lt;/xsl:choose&gt;
 &lt;/xsl:template&gt;
      &lt;xsl:template name="dvt_1"&gt;
       &lt;xsl:variable name="dvt_StyleName"&gt;Table&lt;/xsl:variable&gt;
       &lt;xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/&gt;
       &lt;xsl:variable name="dvt_RowCount" select="count($Rows)"/&gt;
       &lt;xsl:variable name="RowLimit" select="10" /&gt;
       &lt;xsl:variable name="FirstRow" select="$dvt_firstrow" /&gt;
       &lt;xsl:variable name="LastRow" select="$FirstRow + $dvt_RowCount - 1" /&gt;
       &lt;xsl:variable name="IsEmpty" select="$dvt_RowCount = 0" /&gt;
       &lt;xsl:variable name="dvt_IsEmpty" select="$dvt_RowCount = 0"/&gt;
       
       &lt;xsl:choose&gt;
        &lt;xsl:when test="$dvt_IsEmpty"&gt;
         &lt;xsl:call-template name="dvt_1.empty"/&gt;
   &lt;/xsl:when&gt;
        &lt;xsl:otherwise&gt;
    &lt;table border="0" width="100%" cellpadding="2" cellspacing="0"&gt;
     &lt;tr valign="top"&gt;
      &lt;xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1"&gt;
       &lt;th class="ms-vh" width="1%" nowrap="nowrap"&gt;&lt;/th&gt;
      &lt;/xsl:if&gt;
      &lt;th class="ms-vh" nowrap="nowrap"&gt;Question&lt;/th&gt;
      &lt;th class="ms-vh" nowrap="nowrap"&gt;ID&lt;/th&gt;
     &lt;/tr&gt;
     &lt;xsl:call-template name="dvt_1.body"&gt;
      &lt;xsl:with-param name="Rows" select="$Rows"/&gt;
      &lt;xsl:with-param name="FirstRow" select="1" /&gt;
      &lt;xsl:with-param name="LastRow" select="$LastRow - $FirstRow + 1" /&gt;
     &lt;/xsl:call-template&gt;
    &lt;/table&gt;
   &lt;/xsl:otherwise&gt;
       &lt;/xsl:choose&gt;
       &lt;xsl:call-template name="dvt_1.commandfooter"&gt;
        &lt;xsl:with-param name="FirstRow" select="$FirstRow" /&gt;
        &lt;xsl:with-param name="LastRow" select="$LastRow" /&gt;
        &lt;xsl:with-param name="RowLimit" select="$RowLimit" /&gt;
        &lt;xsl:with-param name="dvt_RowCount" select="$dvt_RowCount" /&gt;
        &lt;xsl:with-param name="RealLastRow" select="number(ddwrt:NameChanged('',-100))" /&gt;
       &lt;/xsl:call-template&gt;
      &lt;/xsl:template&gt;
      &lt;xsl:template name="dvt_1.body"&gt;
       &lt;xsl:param name="Rows"/&gt;
       &lt;xsl:param name="FirstRow" /&gt;
       &lt;xsl:param name="LastRow" /&gt;
       &lt;xsl:for-each select="$Rows"&gt;
        &lt;xsl:variable name="dvt_KeepItemsTogether" select="false()" /&gt;
        &lt;xsl:variable name="dvt_HideGroupDetail" select="false()" /&gt;
        &lt;xsl:if test="(position() &amp;gt;= $FirstRow and position() &amp;lt;= $LastRow) or $dvt_KeepItemsTogether"&gt;
         &lt;xsl:if test="not($dvt_HideGroupDetail)" ddwrt:cf_ignore="1"&gt;
          &lt;xsl:call-template name="dvt_1.rowview" /&gt;
         &lt;/xsl:if&gt;
        &lt;/xsl:if&gt;
       &lt;/xsl:for-each&gt;
 &lt;/xsl:template&gt;
      &lt;xsl:template name="dvt_1.rowview"&gt;
  &lt;tr&gt;
   &lt;xsl:if test="position() mod 2 = 1"&gt;
    &lt;xsl:attribute name="class"&gt;ms-alternating&lt;/xsl:attribute&gt;
   &lt;/xsl:if&gt;
   &lt;xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1"&gt;
    &lt;td class="ms-vb" width="1%" nowrap="nowrap"&gt;
     &lt;span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDelims(string(@ID))" ddwrt:ammode="view"&gt;&lt;/span&gt;
    &lt;/td&gt;
   &lt;/xsl:if&gt;
   &lt;td class="ms-vb"&gt;
    &lt;xsl:value-of select="@Title"/&gt;
   &lt;/td&gt;
   &lt;td class="ms-vb"&gt;
    &lt;xsl:value-of select="@ID"/&gt;
   &lt;/td&gt;
  &lt;/tr&gt;
 &lt;/xsl:template&gt;
      &lt;xsl:template name="dvt_1.empty"&gt;
       &lt;xsl:variable name="dvt_ViewEmptyText"&gt;There are no items to show in this view.&lt;/xsl:variable&gt;
  &lt;table border="0" width="100%"&gt;
   &lt;tr&gt;
    &lt;td class="ms-vb"&gt;
     &lt;xsl:value-of select="$dvt_ViewEmptyText"/&gt;
    &lt;/td&gt;
   &lt;/tr&gt;
  &lt;/table&gt;
 &lt;/xsl:template&gt;
      &lt;xsl:template name="dvt_1.commandfooter"&gt;
       &lt;xsl:param name="FirstRow" /&gt;
       &lt;xsl:param name="LastRow" /&gt;
       &lt;xsl:param name="RowLimit" /&gt;
       &lt;xsl:param name="dvt_RowCount" /&gt;
       &lt;xsl:param name="RealLastRow" /&gt;
       &lt;table cellspacing="0" cellpadding="4" border="0" width="100%"&gt;
   &lt;tr&gt;
    &lt;xsl:if test="$FirstRow &amp;gt; 1 or $dvt_nextpagedata"&gt;
     &lt;xsl:call-template name="dvt_1.navigation"&gt;
      &lt;xsl:with-param name="FirstRow" select="$FirstRow" /&gt;
      &lt;xsl:with-param name="LastRow" select="$LastRow" /&gt;
      &lt;xsl:with-param name="RowLimit" select="$RowLimit" /&gt;
      &lt;xsl:with-param name="dvt_RowCount" select="$dvt_RowCount" /&gt;
      &lt;xsl:with-param name="RealLastRow" select="$RealLastRow" /&gt;
     &lt;/xsl:call-template&gt;
    &lt;/xsl:if&gt;
        &lt;/tr&gt;
  &lt;/table&gt;
      &lt;/xsl:template&gt;
      &lt;xsl:template name="dvt_1.navigation"&gt;
       &lt;xsl:param name="FirstRow" /&gt;
       &lt;xsl:param name="LastRow" /&gt;
       &lt;xsl:param name="RowLimit" /&gt;
       &lt;xsl:param name="dvt_RowCount" /&gt;
       &lt;xsl:param name="RealLastRow" /&gt;
       &lt;xsl:variable name="PrevRow"&gt;
        &lt;xsl:choose&gt;
         &lt;xsl:when test="$FirstRow - $RowLimit &amp;lt; 1"&gt;1&lt;/xsl:when&gt;
         &lt;xsl:otherwise&gt;
     &lt;xsl:value-of select="$FirstRow - $RowLimit" /&gt;
    &lt;/xsl:otherwise&gt;
        &lt;/xsl:choose&gt;
       &lt;/xsl:variable&gt;
       &lt;xsl:variable name="LastRowValue"&gt;
        &lt;xsl:choose&gt;
         &lt;xsl:when test="$LastRow &amp;gt; $RealLastRow"&gt;
     &lt;xsl:value-of select="$LastRow"&gt;&lt;/xsl:value-of&gt;
    &lt;/xsl:when&gt;
         &lt;xsl:otherwise&gt;
     &lt;xsl:value-of select="$RealLastRow"&gt;&lt;/xsl:value-of&gt;
    &lt;/xsl:otherwise&gt;
        &lt;/xsl:choose&gt;
       &lt;/xsl:variable&gt;
       &lt;xsl:variable name="NextRow"&gt;
   &lt;xsl:value-of select="$LastRowValue + 1"&gt;&lt;/xsl:value-of&gt;
  &lt;/xsl:variable&gt;
       &lt;td nowrap="nowrap" class="ms-paging" align="right"&gt;
        &lt;xsl:if test="$dvt_firstrow &amp;gt; 1" ddwrt:cf_ignore="1"&gt;
    &lt;a&gt;
         &lt;xsl:attribute name="href"&gt;javascript: &lt;xsl:value-of select="ddwrt:GenFireServerEvent('dvt_firstrow={1};dvt_startposition={}')" /&gt;;&lt;/xsl:attribute&gt;
         Start&lt;/a&gt;
         &lt;xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes"&gt;&amp;amp;nbsp;&lt;/xsl:text&gt;
         &lt;a&gt;
         &lt;xsl:attribute name="href"&gt;javascript: history.back();&lt;/xsl:attribute&gt;
         &lt;img src="/_layouts/images/prev.gif" border="0" alt="Previous" /&gt;
         &lt;/a&gt;
         &lt;xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes"&gt;&amp;amp;nbsp;&lt;/xsl:text&gt;
        &lt;/xsl:if&gt;
        &lt;xsl:value-of select="$FirstRow" /&gt;
         - &lt;xsl:value-of select="$LastRowValue" /&gt;
        &lt;xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:nbsp-preserve="yes" disable-output-escaping="yes"&gt;&amp;amp;nbsp;&lt;/xsl:text&gt;
        &lt;xsl:if test="$LastRowValue &amp;lt; $dvt_RowCount or string-length($dvt_nextpagedata)!=0" ddwrt:cf_ignore="1"&gt;
    &lt;a&gt;
         &lt;xsl:attribute name="href"&gt;javascript: &lt;xsl:value-of select="ddwrt:GenFireServerEvent(concat('dvt_firstrow={',$NextRow,'};dvt_startposition={',$dvt_nextpagedata,'}'))" /&gt;;&lt;/xsl:attribute&gt;
         &lt;img src="/_layouts/images/next.gif" border="0" alt="Next" /&gt;
         &lt;/a&gt;
   &lt;/xsl:if&gt;
       &lt;/td&gt;
      &lt;/xsl:template&gt;
     &lt;/xsl:stylesheet&gt;</property>
        <property name="CacheXslTimeOut" type="int">86400</property>
        <property name="Hidden" type="bool">False</property>
        <property name="ListName" type="string">{C11B955E-DB37-4382-80D2-4E9BD715FBE5}</property> 修改
        <property name="DataSourceID" type="string" />
        <property name="FireInitialRow" type="bool">True</property>
        <property name="ManualRefresh" type="bool">False</property>
        <property name="ViewFlags" type="Microsoft.SharePoint.SPViewFlags, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">Hidden</property>
        <property name="ChromeState" type="chromestate">Normal</property>
        <property name="AllowHide" type="bool">True</property>
        <property name="PageSize" type="int">10</property>
        <property name="SampleData" type="string" null="true" />
        <property name="AsyncRefresh" type="bool">False</property>
        <property name="HelpMode" type="helpmode">Modeless</property>
        <property name="ListId" type="System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">c11b955e-db37-4382-80d2-4e9bd715fbe5</property> 删除
        <property name="UseSQLDataSourcePaging" type="bool">True</property>
        <property name="AllowMinimize" type="bool">True</property>
        <property name="TitleUrl" type="string" />
        <property name="CatalogIconImageUrl" type="string" />
        <property name="DataSourcesString" type="string">&lt;%@ Register TagPrefix="sharepoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %&gt;&lt;%@ Register TagPrefix="webpartpages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %&gt;&lt;sharepoint:SPDataSource runat="server" DataSourceMode="List" SelectCommand="&amp;lt;View&amp;gt;&amp;lt;/View&amp;gt;" UpdateCommand="" InsertCommand="" DeleteCommand="" UseInternalName="True" UseServerDataFormat="True" ID="dataformwebpart2"&gt;&lt;SelectParameters&gt;
&lt;webpartpages:DataFormParameter ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{C11B955E-DB37-4382-80D2-4E9BD715FBE5}" Name="ListID"&gt;&lt;/webpartpages:DataFormParameter&gt;
&lt;asp:Parameter DefaultValue="0" Name="StartRowIndex"&gt;&lt;/asp:Parameter&gt;
&lt;asp:Parameter DefaultValue="0" Name="nextpagedata"&gt;&lt;/asp:Parameter&gt;
&lt;asp:Parameter DefaultValue="10" Name="MaximumRows"&gt;&lt;/asp:Parameter&gt;
&lt;/SelectParameters&gt;
&lt;UpdateParameters&gt;
&lt;webpartpages:DataFormParameter ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{C11B955E-DB37-4382-80D2-4E9BD715FBE5}" Name="ListID"&gt;&lt;/webpartpages:DataFormParameter&gt;   修改
&lt;/UpdateParameters&gt;
&lt;InsertParameters&gt;
&lt;webpartpages:DataFormParameter ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{C11B955E-DB37-4382-80D2-4E9BD715FBE5}" Name="ListID"&gt;&lt;/webpartpages:DataFormParameter&gt;   修改
&lt;/InsertParameters&gt;
&lt;DeleteParameters&gt;
&lt;webpartpages:DataFormParameter ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{C11B955E-DB37-4382-80D2-4E9BD715FBE5}" Name="ListID"&gt;&lt;/webpartpages:DataFormParameter&gt;    修改
&lt;/DeleteParameters&gt;
&lt;/sharepoint:SPDataSource&gt;
</property>
        <property name="DisplayName" type="string" />
        <property name="PageType" type="Microsoft.SharePoint.PAGETYPE, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">PAGE_NORMALVIEW</property>
        <property name="Width" type="string" />
        <property name="ExportMode" type="exportmode">All</property>
        <property name="Direction" type="direction">NotSet</property>
        <property name="ViewContentTypeId" type="string" />
        <property name="HelpUrl" type="string" />
        <property name="XmlDefinition" type="string" />
        <property name="Default" type="string" />
        <property name="TitleIconImageUrl" type="string" />
        <property name="MissingAssembly" type="string">Cannot import this Web Part.</property>
      </properties>
    </data>
  </webPart>
</webParts>
 
希望对有类似需求的人有帮助。

你可能感兴趣的:(form)