Friday, October 23, 2009

Progress Bar in Dynamics CRM 4.0

To create a progress bar in Dynamics CRM 4.0 like the one below





You need the following


2.step.gif  
 

3.statusbar.gif - You can get this from the /_imgs/ folder in CRM

For step.gif, right click the .gif file and save it on your system.

crmprogressbar.js

function crmProgressBar(id) {
this.bar = $("#" + id);

this.bar.css({
'height': '23px',
'width': '357px',
'background': 'transparent url(img/statusbar.gif) no-repeat'
});

this.bar.find("div").css({
'height': '19px',
'width': '1px',
'background': 'transparent url(img/step.gif) repeat-x',
'position': 'relative',
'top': '2px',
'left': '3px'
});

this.step = function(percentage) {
var width = parseInt((percentage / 100) * 351);
if (width > 351) { width = 351; }

this.bar.find("div").css({ 'width': width + 'px' });
}
}

To implement follow the steps below.

1.Create a new html file
2.Create a new javascript file and copy the above code into it
3.Include a reference to the jQuery javascript library
4.Include a reference to the javascript in your html file
5.Add a "div" tag to the html file and give it an "id"
6.Add another "div" tag inside the "div" you created in step 4. and put a blank space
7.To initialize the progress bar; create a new variable to hold the progress bar, then create a new instance of the progress bar by specifying the "id" of the div you created in step 4.
eg: var progressBar1 = new crmProgressBar("id-of-div");
8.To step/increment the progress bar use the step() instance method
eg: progressBar1.step(10); // will increment to 10%;



<div id="p1">
<div>
 </div>
</div>

<script type="text/javascript">
var i = 5;
var cpb = null;

$(document).ready(function() {
cpb = new crmProgressBar("p1");
increment();
});

function increment() {
if (i <= 100) {
i += 5;
cpb.step(i);
setTimeout(increment, 1000);
}
}

</script>


Happy Coding..

You can find gperera's entry on Blog

Labels: , , , , ,

Tuesday, October 20, 2009

Backup, Restore & Publish Dynamics CRM Customizations Programmatically

Thanks to gperera in giving out this wonderful class.

Find the excerpts..

Here is a simple class you can use to backup, restore and publish dynamics crm customizations programmatically. Please keep in mind that dynamics crm customizations are additive, which means, if you import a set of customizations lets say a new attribute on the account entity and you restore a backup of the old customizations the new attribute on the account entity that was imported will not be deleted.

CrmCustomizations customizations = new CrmCustomizations(service);

You can backup to an xml file or a zip file by calling the Backup method. Backup method takes care of creating the xml or zip file by looking at the output file extension.

bool backedup = customizations.Backup(@".\customizations_backup.xml");

 or to a zip file

backedup = customizations.Backup(@".\customizations_backup.zip");

To restore a backup call the Restore method. You can pass it a .zip file //or a .xml file path.

bool restored = customizations.Restore(@".\customizations.xml");

Once you have restored you need to publish the customizations, to publish call the Publish method. It will publish all customizations.

bool published = customizations.Publish();

Find the class file below :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Crm.SdkTypeProxy;
using System.IO;
using System.IO.Compression;

public class CrmCustomizations
{
private CrmService _service = null;
public CrmCustomizations(CrmService service)
{
_service = service;
}

public bool Backup(string filePath)
{
bool backedup = false;

if (_service != null)
{
// grab all the customizations first
ExportAllXmlRequest request = new ExportAllXmlRequest();
ExportAllXmlResponse response = _service.Execute(request) as ExportAllXmlResponse;

byte[] data = Encoding.ASCII.GetBytes(response.ExportXml);

// prepare the backup file
if (File.Exists(filePath)) { File.Delete(filePath); }
FileStream fs = File.Create(filePath);

// check if we need to create a zip file
bool createZip = Path.GetExtension(filePath).ToLower().Equals(".zip");
if (createZip)
{
GZipStream gzs = new GZipStream(fs, CompressionMode.Compress, true);
gzs.Write(data, 0, data.Length);
gzs.Close();
}
else
{
fs.Write(data, 0, data.Length);
}
fs.Close();

backedup = true;
}

return backedup;
}

public bool Restore(string filePath)
{
bool restored = false;

if (_service != null && File.Exists(filePath))
{
string customizationXml = ReadData(filePath);
if (!string.IsNullOrEmpty(customizationXml))
{
ImportAllXmlRequest request = new ImportAllXmlRequest { CustomizationXml = customizationXml };
//_service.Execute(request);

restored = true;
}
}

return restored;
}

public bool Publish()
{
bool published = false;

if (_service != null)
{
PublishAllXmlRequest request = new PublishAllXmlRequest();
_service.Execute(request);

published = true;
}

return published;
}

private string ReadData(string filePath)
{
FileStream fs = File.Open(filePath, FileMode.Open);
byte[] data = new byte[fs.Length];

bool isZip = Path.GetExtension(filePath).ToLower().Equals(".zip");
if (isZip)
{
GZipStream gzs = new GZipStream(fs, CompressionMode.Decompress, true);
// decompress
MemoryStream stream = new MemoryStream();
byte[] b = new byte[4096];
while (true)
{
int n = gzs.Read(b, 0, b.Length);
if (n > 0) { stream.Write(b, 0, n); }
else { break; }
}

data = stream.ToArray();

stream.Close();
gzs.Close();
}
else
{
fs.Read(data, 0, data.Length);
}

fs.Close();

return Encoding.ASCII.GetString(data);
}
}

Happy coding...

Labels: , , , , , , , , , ,

Friday, October 2, 2009

'The application is already precompiled' error

Iam not sure about the cause for the eror "The application is already precompiled". I faced this error while publishing the website.


The workaround for this error is to delete the 'PrecompiledApp.config' file (also not sure how it is created in the website directory) in your website directory.

Labels: , , , , , , ,

Thursday, October 1, 2009

Server Explorer Gone Invisible?

Is Server explorer on your visual studio gone invisible and throwing the following error when you are trying to view it?

The Visual Studio Explorers and Designers Package ({8D8529D3-625D-4496-8354-3DAD630ECC1B}) did not load because of previous errors. For assistance, contact the package vendor. To attempt to load this package again, type 'devenv /resetskippkgs' at the command prompt.

Follow these steps to get it back.

1.Close all open instances of Visual Studio.

2.Open the Command Prompt in an Administrator context by navigating to Start\All Programs\Accessories, right-clicking Command Prompt and choosing Run as Administrator.

3.Navigate to the install path of VS2008 - in my case (default on Vista x64) it was *C:\Program Files (x86)\Microsoft Visual Studio 2008 9.0\Common7\IDE*

4.Run the command devenv /setup. It takes a little time, wait till it completes.

5.Start Visual Studio.


You have reset your Visual Studio to the default settings through the above steps.

And you can see the Server Explorer again!!

Labels: , , , , ,