WebPartPagesWebService.SaveWebPart - Méthode
Enregistre les modifications apportées à un composant WebPart dynamique existant.
Espace de noms : WebSvcwebpartpages
Assembly : STSSOAP (dans STSSOAP.dll)
Syntaxe
'Déclaration
<SoapDocumentMethodAttribute("https://microsoft.com/sharepoint/webpartpages/SaveWebPart", RequestNamespace := "https://microsoft.com/sharepoint/webpartpages", _
ResponseNamespace := "https://microsoft.com/sharepoint/webpartpages", _
Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Sub SaveWebPart ( _
pageUrl As String, _
storageKey As Guid, _
webPartXml As String, _
storage As Storage _
)
'Utilisation
Dim instance As WebPartPagesWebService
Dim pageUrl As String
Dim storageKey As Guid
Dim webPartXml As String
Dim storage As Storage
instance.SaveWebPart(pageUrl, storageKey, _
webPartXml, storage)
[SoapDocumentMethodAttribute("https://microsoft.com/sharepoint/webpartpages/SaveWebPart", RequestNamespace = "https://microsoft.com/sharepoint/webpartpages",
ResponseNamespace = "https://microsoft.com/sharepoint/webpartpages",
Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public void SaveWebPart(
string pageUrl,
Guid storageKey,
string webPartXml,
Storage storage
)
Paramètres
pageUrl
Type : System.StringL'URL de la page source.
storageKey
Type : System.GuidGUID qui identifie le composant WebPart.
webPartXml
Type : System.Stringstring qui contient les informations XML sur le composant WebPart.
storage
Type : WebSvcwebpartpages.StorageUne valeur Storage qui indique comment le composant WebPart est stocké
Remarques
Pour accéder à ses méthodes et le service WebPartPagesWebService , définissez une référence Web à http://Virtual_Server_Name:Port_Number/_vti_adm/WebPartPages.asmx.
Exemples
L'exemple de code suivant montre une méthode définie localement AddWebPart ajoute un composant WebPart et en modifiant ensuite en appelant les méthodes AddWebPart et SaveWebPart du service de Pages de composants WebPart via un proxy. Cet exemple de code et le proxy font partie d'un exemple plus développé fourni pour le service des Pages de composants WebPart.
Private Sub AddWebPart()
' NOTE: The Web Service we are using is defined on MyServer/_vti_bin
' Declare and initialize a variable for the WebPartPages Web Service.
Dim svc = New Microsoft.Samples.WebPartPagesSvcClient.WebpartpagesSvc.WebPartPagesWebService()
' Authenticate the current user by passing their default
' credentials to the Web Service from the system credential cache.
svc.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim pageUrl As String = "http://MyServer/Shared%20Documents/SampleStart.aspx"
' Create Web Part XML inline.
Dim webPartXml As String = "<?xml version=""1.0"" encoding=""utf-16""?>" + ControlChars.Lf + " " + _
"<WebPart xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" https://schemas.microsoft.com/WebPart/v2"">" + ControlChars.Lf + " " + _
"<Title>Content Editor Web Part</Title>" + ControlChars.Lf + " " + _
"<FrameType>Default</FrameType>" + ControlChars.Lf + " " + _
"<Description>Use for formatted text, tables, and images.</Description>" + ControlChars.Lf + " " + _
"<IsIncluded>true</IsIncluded>" + ControlChars.Lf + " " + _
"<ZoneID>Header</ZoneID>" + ControlChars.Lf + " " + _
"<PartOrder>1</PartOrder>" + ControlChars.Lf + " " + _
"<FrameState>Normal</FrameState>" + ControlChars.Lf + " " + _
"<Height />" + ControlChars.Lf + " " + _
"<Width />" + ControlChars.Lf + " " + _
"<AllowRemove>true</AllowRemove>" + ControlChars.Lf + " " + _
"<AllowZoneChange>true</AllowZoneChange>" + ControlChars.Lf + " " + _
"<AllowMinimize>true</AllowMinimize>" + ControlChars.Lf + " " + _
"<IsVisible>true</IsVisible>" + ControlChars.Lf + " " + _
"<DetailLink />" + ControlChars.Lf + " " + _
"<HelpLink />" + ControlChars.Lf + " " + _
"<Dir>Default</Dir>" + ControlChars.Lf + " " + _
"<PartImageSmall />" + ControlChars.Lf + " " + _
"<MissingAssembly />" + ControlChars.Lf + " " + _
"<PartImageLarge>/_layouts/images/mscontl.gif</PartImageLarge>" + ControlChars.Lf + " " + _
"<IsIncludedFilter />" + ControlChars.Lf + " " + _
"<Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>" + ControlChars.Lf + " " + _
"<TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>" + ControlChars.Lf + " " + _
"<ContentLink https://schemas.microsoft.com/WebPart/v2/ContentEditor"" />" + ControlChars.Lf + " " + _
"<Content https://schemas.microsoft.com/WebPart/v2/ContentEditor""><![CDATA[<P>Hello</P>]]></Content>" + ControlChars.Lf + " " + _
"<PartStorage https://schemas.microsoft.com/WebPart/v2/ContentEditor"" />" + ControlChars.Lf + _
"</WebPart>"
' Add Web Part, store the new WebPart GUID into a variable.
Dim newPartId As Guid = svc.AddWebPart(pageUrl, webPartXml, WebpartpagesSvc.Storage.Shared)
' Edit the Web Part XML just a bit.
Dim sb As New System.Text.StringBuilder(webPartXml)
sb.Replace("Hello", "Hello world!!")
sb.Replace("<Title>Content Editor Web Part</Title>", "<Title>Autogenerated Web Part!</Title>")
' Call SaveWebPart to update the contents of the Web Part XML.
svc.SaveWebPart(pageUrl, newPartId, sb.ToString(), WebpartpagesSvc.Storage.Shared)
Console.WriteLine("A new Web Part with ID [{0}] was added to the page [{1}]", newPartId.ToString(), pageUrl)
Console.WriteLine("-----Hit enter-----")
Console.ReadLine()
End Sub 'AddWebPart
private void AddWebPart()
{
// NOTE: The Web Service we are using is defined on MyServer/_vti_bin
// Declare and initialize a variable for the WebPartPages Web Service.
WebpartpagesSvc.WebPartPagesWebService svc = new Microsoft.Samples.WebPartPagesSvcClient.WebpartpagesSvc.WebPartPagesWebService();
// Authenticate the current user by passing their default
// credentials to the Web Service from the system credential cache.
svc.Credentials = System.Net.CredentialCache.DefaultCredentials;
string pageUrl = "http://MyServer/Shared%20Documents/SampleStart.aspx";
// Create Web Part XML inline.
string webPartXml = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\n" +
"<WebPart xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"https://schemas.microsoft.com/WebPart/v2\">\n" +
"<Title>Content Editor Web Part</Title>\n " +
"<FrameType>Default</FrameType>\n " +
"<Description>Use for formatted text, tables, and images.</Description>\n " +
"<IsIncluded>true</IsIncluded>\n " +
"<ZoneID>Header</ZoneID>\n " +
"<PartOrder>1</PartOrder>\n " +
"<FrameState>Normal</FrameState>\n " +
"<Height />\n " +
"<Width />\n " +
"<AllowRemove>true</AllowRemove>\n " +
"<AllowZoneChange>true</AllowZoneChange>\n " +
"<AllowMinimize>true</AllowMinimize>\n " +
"<IsVisible>true</IsVisible>\n " +
"<DetailLink />\n " +
"<HelpLink />\n " +
"<Dir>Default</Dir>\n " +
"<PartImageSmall />\n " +
"<MissingAssembly />\n " +
"<PartImageLarge>/_layouts/images/mscontl.gif</PartImageLarge>\n " +
"<IsIncludedFilter />\n " +
"<Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>\n " +
"<TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>\n " +
"<ContentLink xmlns=\"https://schemas.microsoft.com/WebPart/v2/ContentEditor\" />\n " +
"<Content xmlns=\"https://schemas.microsoft.com/WebPart/v2/ContentEditor\"><![CDATA[<P>Hello</P>]]></Content>\n " +
"<PartStorage xmlns=\"https://schemas.microsoft.com/WebPart/v2/ContentEditor\" />\n</WebPart>";
// Add Web Part, store the new Web Part GUID into a variable.
Guid newPartId = svc.AddWebPart(pageUrl, webPartXml,
WebpartpagesSvc.Storage.Shared);
// Edit the Web Part XML.
System.Text.StringBuilder sb = new System.Text.StringBuilder(webPartXml);
sb.Replace("Hello", "Hello world!!");
sb.Replace("<Title>Content Editor Web Part</Title>", "<Title>Autogenerated Web Part!</Title>");
// Call SaveWebPart to update the contents of the Web Part XML.
svc.SaveWebPart(pageUrl, newPartId, sb.ToString(),
WebpartpagesSvc.Storage.Shared);
Console.WriteLine("A new Web Part with ID [{0}] was added to the page [{1}]",
newPartId.ToString(), pageUrl);
Console.WriteLine("-----Hit enter-----");
Console.ReadLine();
}