Unzipping and Modifying Solution Files for Microsoft Dynamics CRM 2011: A Technical Guide

Introduction

Microsoft Dynamics CRM 2011 solution files are packaged as ZIP archives, containing a collection of XML files and other resources that define the configuration and behavior of a CRM solution. Modifying these solution files often involves editing the XML content, which can be a tedious and error-prone process if done manually.

To address this challenge, a Windows Forms application was developed to automate the process of unzipping, modifying, and repackaging CRM solution files. This application provides a user-friendly interface for searching, replacing, and saving changes to XML files within CRM solution packages.

Application Overview

The application consists of three main components:

  1. Unzipping Module: This module handles the extraction of solution file contents from the ZIP archive. It utilizes a third-party library, ICSharpCode.SharpZipLib, to efficiently extract files into a temporary directory.
  2. XML Modification Module: This module enables users to search and replace specific strings within XML files. It employs the XDocument class from the System.Xml.Linq namespace to parse and manipulate XML documents.
  3. Repackaging Module: This module handles the creation of a new ZIP archive containing the modified XML files and other solution resources. It utilizes the same ICSharpCode.SharpZipLib library to efficiently pack files into the new ZIP archive.

Technical Implementation

The application’s functionality is implemented using C# and the Windows Forms development framework. The code structure is organized into separate modules for each of the three main components, ensuring modularity and maintainability.

Unzipping Module

The unzipping module utilizes the FastZip class from the ICSharpCode.SharpZipLib library to extract solution file contents from the ZIP archive. The FastZip class provides a high-performance and efficient method for extracting files from ZIP archives.

C#

FastZip fz = new FastZip();
fz.ExtractZip(textBox1.Text, filepath_xml, null);

XML Modification Module

The XML modification module employs the XDocument class from the System.Xml.Linq namespace to parse and manipulate XML documents. The XDocument class provides a powerful and flexible API for working with XML data.

C#

XDocument xe = XDocument.Load(filepath_xml + "\\" + filename_xml);
var qry = from atr in xe.Descendants().Attributes() where atr.Value.ToString().Contains(textBox4.Text.ToString()) select atr;

Repackaging Module

The repackaging module utilizes the CreateZip method from the ICSharpCode.SharpZipLib library to create a new ZIP archive containing the modified XML files and other solution resources. The CreateZip method provides a convenient and efficient method for creating ZIP archives.

C#

fz.CreateZip(filepath_zip + @"\" + filename_zip + "_new.zip", filepath_xml, true, null);

GitHub Repository: amrvignesh/UnzipandAlterXml (github.com)

Conclusion

The application provides a user-friendly and efficient tool for unzipping, modifying, and repackaging CRM solution files. It simplifies the process of making changes to XML configurations within CRM solutions, reducing the risk of errors and improving productivity.


Posted

in

, ,

by