2012-01-17 26 views
5

Tôi đã tạo một phần web tùy chỉnh có thuộc tính bộ sưu tập tùy chỉnh (Tab). Phần web hoạt động bình thường khi bạn chỉnh sửa và lưu thuộc tính tùy chỉnh trên chế độ chỉnh sửa (thông qua trình duyệt). Tôi muốn cập nhật phần web tùy chỉnh của tôi sử dụng dịch vụ web, vì vậy tôi đã xuất khẩu phần web và mất nội dung xml và thông qua nó vì nó là (vì vậy tôi có thể dễ dàng kiểm tra nó), nhưng một lỗi xảy raLỗi XML được định dạng tốt khi lưu phần web tùy chỉnh hơn bằng cách sử dụng dịch vụ web

The file you imported is not valid. 
Verify that the file is a Web Part description file (*.webpart or *.dwp) and that it contains well-formed XML. 

tôi đã xác nhận xml sử dụng validator xml trực tuyến và loại bỏ tuyên bố này

<?xml version="1.0" encoding="utf-16"?> 

vì đây là một trong những gây ra XML không nổi formex theo validator XML, nhưng vẫn không có may mắn, cùng một lỗi xảy ra.

Bất kỳ ý tưởng nào? Tôi không thể tìm ra nó có gì sai với XML đặc biệt trên tài sản Tabs.

Code:

string webPartXml = string.Empty; 
    string pageUrl = currenturl; 

     Guid storageKey = new Guid(webpartid); 

     using (StreamReader sr = new StreamReader(@"C:\tab.txt")) 
     {    
      webPartXml = sr.ReadToEnd();     
     } 
     webPartXml = webPartXml.Replace("&lt;", "<").Replace("&gt;",">"); 

     try 
     { 
      svc.SaveWebPart2(pageUrl, storageKey, webPartXml, WebpartpagesSvc.Storage.Shared, false); 
     }catch(Exception err) 
     { 
      throw; 
     } 

Tab.txt (Tab.webpart)

<webParts> 
    <webPart xmlns="http://schemas.microsoft.com/WebPart/v3"> 
    <metaData> 
     <type name="Test.TabWebPart, Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c9e6068352095bx6" /> 
     <importErrorMessage>Cannot import this web part.</importErrorMessage> 
    </metaData> 
    <data> 
     <properties> 
     <property name="ChromeType" type="chrometype">None</property> 
     <property name="Height" type="unit" /> 
     <property name="PanelHeight" type="int">0</property> 
     <property name="ShowRoundedTabs" type="bool">False</property> 
     <property name="AllowZoneChange" type="bool">True</property> 
     <property name="AllowEdit" type="bool">True</property> 
     <property name="Tabs" type="Test.Tabs, Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c9e6068352095bx6">&lt;?xml version="1.0" encoding="utf-16"?&gt; 
&lt;Tabs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; 
    &lt;TabInfo&gt; 
    &lt;Tab&gt; 
     &lt;Title&gt;HTML-TESTING&lt;/Title&gt;  
    &lt;/Tab&gt; 
    &lt;/TabInfo&gt; 
&lt;/Tabs&gt;</property> 
     <property name="CatalogIconImageUrl" type="string" /> 
     <property name="PanelWidth" type="int">0</property> 
     <property name="AllowConnect" type="bool">True</property> 
     <property name="AllowClose" type="bool">True</property> 
     <property name="HelpMode" type="helpmode">Navigate</property> 
     <property name="ChildTab" type="System.Collections.Specialized.NameValueCollection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934ebb9" /> 
     <property name="Hidden" type="bool">False</property> 
     <property name="Title" type="string">Tab </property> 
     <property name="ChromeState" type="chromestate">Normal</property> 
     <property name="AllowHide" type="bool">True</property> 
     <property name="Description" type="string">for Tab Sample.</property> 
     <property name="AllowMinimize" type="bool">True</property> 
     <property name="TitleUrl" type="string" /> 
     <property name="Width" type="unit" /> 
     <property name="ExportMode" type="exportmode">All</property> 
     <property name="Direction" type="direction">NotSet</property> 
     <property name="HelpUrl" type="string" /> 
     <property name="TitleIconImageUrl" type="string" /> 
     </properties> 
    </data> 
    </webPart> 
</webParts> 

Thông báo lỗi

base {System.SystemException} = {"Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown."} 
InnerText = "The file you imported is not valid. Verify that the file is a Web Part description file (*.webpart or *.dwp) and that it contains well-formed XML." 
InnerXml = "<errorstring xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">The file you imported is not valid. Verify that the file is a Web Part description file (*.webpart or *.dwp) and that it contains well-formed XML.</errorstring>" 

Trả lời

0

Tôi nghĩ rằng đó là khi bạn cố gắng để khôi phục lại xml để gốc phá vỡ nó. Bạn có thực sự cần dòng mã này không:

webPartXml = webPartXml.Replace("&lt;", "<").Replace("&gt;",">"); 

Điều gì xảy ra nếu bạn xóa? Nếu nó không làm việc, tôi muốn giới thiệu gói giá trị trong CDATA-tag để thoát khỏi xml:

string startTabProperty = @"<property name=""Tabs"" type=""Test.Tabs, Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c9e6068352095bx6"">"; 
string endTabProperty = "></property>"; //Note the >< in order to identify correct place 
webPartXml = webPartXml.Replace("&lt;", "<").Replace("&gt;",">"); 
webPartXml = webPartXml.Replace(startTabProperty, startTabProperty + "<![CDATA["); 
webPartXml = webPartXml.Replace(endTabProperty , ">" + "]]>" + "</property>"); 

Chúc may mắn!

0

Viết mã dưới trong Element.xml & thay đổi duy nhất tên danh sách Mô-đun trong listUrl & TitleUrl

<Module> 
<File> 
<AllUsersWebPart WebPartZoneID="wzMain" WebPartOrder="2"> 
    <![CDATA[ 
    <webParts> 
    <webPart xmlns="http://schemas.microsoft.com/WebPart/v3"> 
    <metaData> 
    <type name="Microsoft.SharePoint.WebPartPages.XsltListViewWebPart, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /> 
    <importErrorMessage>Cannot import this Web Part.</importErrorMessage> 
    </metaData> 
    <data> 
    <properties> 
    <property name="ShowWithSampleData" type="bool">False</property> 
    <property name="Default" type="string" /> 
    <property name="NoDefaultStyle" type="string" null="true" /> 
    <property name="CacheXslStorage" type="bool">True</property> 
    <property name="ViewContentTypeId" type="string" /> 
    <property name="XmlDefinitionLink" type="string" /> 
    <property name="ManualRefresh" type="bool">False</property> 
    <property name="ListUrl" type="string" >Lists/Employee_list</property> 
    <property name="TitleUrl" type="string">/Lists/Employee_list</property> 
    </properties> 
    </data> 
    </webPart> 
    </webParts> 
    ]]> 
    </AllUsersWebPart> 
    </File> 
    </Module> 
Các vấn đề liên quan