Home

Nov 26, 2010

Export Import & Publish Programmatically

1. Export Customization

ExportXmlRequest request = new ExportXmlRequest(); 
request.ParameterXml = @"<importexportxml><entities></entities> <nodes> <node></node>
</nodes> <securityroles></securityroles> <settings></settings> <workflows></workflows>
</importexportxml>";
// Execute the request.
ExportXmlResponse response = (ExportXmlResponse)service.Execute(request);
// Create an instance of StreamWriter to write text to a file.
// The using statement also closes the StreamWriter.
using (StreamWriter sw = new StreamWriter(Path.Combine(strLocation, "Customizations_Backup.xml")))
// Write the customization XML to the file
sw.Write(response.ExportXml);


2. Modify the customization file.
3. Create the import request.


ImportXmlRequest importRequest = new ImportXmlRequest();            
// Define the location of the customization XML.
string customizationPath = Path.Combine(path, "Customizations_Backup.xml");
// Pass the stream of customization XML to the import request.
using (StreamReader sr = new StreamReader(customizationPath))
{
string customizationXml = sr.ReadToEnd();
importRequest.CustomizationXml = customizationXml;
}
// Execute the import.
ImportXmlResponse importResponse = (ImportXmlResponse)service.Execute(importRequest);



4. Publish Customization



// Create the request.            
PublishXmlRequest publishRequest = new PublishXmlRequest();
publishRequest.ParameterXml = @"<importexportxml>
<entities>
</entities>
<nodes/>
<securityroles/>
<settings/>
<workflows/>
</importexportxml>"
;
// Execute the request.
PublishXmlResponse publishResponse = (PublishXmlResponse)service.Execute(publishRequest);

Refer this link as well


http://msdn.microsoft.com/en-us/library/cc155973.aspx

No comments: