CrmXpress
I was recently working with a client where I had to come up with a multi-grid form for Case entity and wanted to display related activities in each grid. And they wanted to display around 6 different types of activities to be available on Case form.After adding the sub-grids I came to notice a strange issue and as such it does make sense to load records as and when we need them, that is not what my client wanted. Basically what was happening is after I added the sub-grids, only first 4 grids will load the data when form is loaded. Fifth grid onwards I will get a link which will ask me to click on it if I need to see records. This is in fact a good solution to avoid loading unnecessary data and improve performance, client was not happy with that solution. And I was asked to come up with a workaround, it is pretty simple trick as such but can come really handy. You might want to polish it a bit like- make sure that you don't click on any other link except the one within the grids and maybe some more checks just in case there are other elements with the same class id.All you need to do is to include this script, on OnLoad of the form along with the jQuery minified library[which you will have to add and make it available on your form.]
function CrmXpress.Scripts.UI.SubGridLoadFix() { $(document).ready(function () { var links = $("a.ms-crm-List-LoadOnDemand") for (i = 0; i <= links.length; i++) { try { links[i].click(); } catch (e) { // Handle for other errors, or safely ignore } } } ); }
Have fun and Happy Coding.
Tags: CRM 2011, Code, jQuery
Code | CRM 2011 | DHTML
As part of my job I do a lot of code review, refactoring and maintenance. Many a times I would leave instructions to my teammates, well I could always write an email or maybe send an excel file for a large codebase. However, I am very fond of using one (not so popular) Visual Studio feature called Task List[http://msdn.microsoft.com/en-us/library/170k1bbs(v=VS.100).aspx]Few reasons I love using Comment tokens are they are much easier to use. They stay with the code and any good developer would want to get rid of a BUGBUG or HACK from his/her code comments. And because they are always there in the IDE it is easy to keep track on the progress as you work through your code.So here it is how you can set up a set of your own comment tokens to use with Task List.1. Click on Tools - > Options -> Environment -> Task List.2. Add as many tokens you want, as shown in the image below
And here is how you will use it in your code.
Tags: .Net, C#, Code, Tutorial, Visual Studio 2010
.Net | C# | Code | Tutorial | Visual Studio 2010
Now let's face this, we all work with Text in our day to day lives [If you don't, kindly do let me know what kind of work you do?] and it is funny how we ignore some basics of the game. I've been myself victim of these traps before but as I spent more time dealing with them I found out some really simple solutions to some really strange problems.
Recently, a friend of mine was testing an MSI Installer which was custom built by his Dev team for automated installation and deployment. One of the purposes of that installer was to auto configure certain server parameters. Now that configuration was done using a VBS. Now they were rushing for a release and timeline was short. As such it was a straight forward process, so he ran the MSI and within a few seconds he was presented with a weird error. And Installer aborted. Now this was not the first time that installer was being used. It was used across teams in that group and was in practice for a while now. I was standing by him when this was going on so I offered him my help and he happily agreed.
Now first thing I did is to check Eventlog. [I work with Microsoft Dynamics CRM most of the times, so this has become my habit] and indeed there was an error recorded under Windows Installer. On checking that error we found out a script necessary to run this setup was failing and due to that failure Setup cannot continue. So we knew that it is coming from
So I asked him to run the script manually by double clicking it. The script instantly gave an error, and the error was there was an invalid character on line 1, position 0. So we opened the file in Visual Studio and it was a simple On Error Resume Next nothing fancy no magic there.
Now the same installer approach was working fine for other teams and my friend just copied the scripts and made his own installer. Now keyword here is "copied", so I asked him from where and how did he copy it? He said he used Remote Desktop. And it striked me that this could be the issue because of the codepage and maybe during the copy something was messed up. I asked him to copy the script file to his notepad and save it as a VBS file and then putting it back. The same file and the same content worked absolutely fine.
Same goes with XML as well, the encoding type specified in header can baffle you sometimes. A perfectly valid XML might also give an error if you try to open it with Internet Explorer 8 or below.
So next time you are facing some weird error in otherwise perfect text file I suggest you try fix the encoding before you dive in somewhere else.
Tags: Tutorial, Code
Code | General | Tutorial
Recently I was helping a friend with a bit tricky piece of code. The task was to process and XML that didn't have namespace and has nested child items with similar names.
<xml> <root> <node> <node>value 1</node> <node>vallue 2</node> </node> <node> <node>value 1</node> <node>vallue 2</node> </node> </root> </xml>
Actual XML was far more complex with a lot of CDATA section and other details. After spending sometime around I had to come up with a way to load this XML into dataset for further processing. As there were no namespace or any other element to identify XML node here is what I came up with at first
public static DataSet GetDatSet(XmlNodeList nodeList) { DataSet dataSet = new DataSet(); XmlReader reader; for (int i = 0; i < nodeList.Count; i++) { reader = new XmlTextReader(nodeList.Item(i).OuterXml, XmlNodeType.Element, new XmlParserContext(null, null, null, XmlSpace.None)); dataSet.ReadXml(reader); } return dataSet; }
but later on due to some other conditions I had to devise another mechanism and finally I settled with some Xpath expressions.
Tags: .Net, C#, Code
.Net | C# | Code
It's been a while since I bloged about my favorite topic i.e. Microsoft Dynamics CRM. Anyways, I intend to start blogging a lot more regularly than before and what else could be a better start than a Developer Training Kit?
Microsoft has release a Developer Training Kit which will help developers to start learning CRM 2011 quickly and is fully loaded with
- Presentations - Videos - Hands On Labs
You can download the kit from here : http://blogs.msdn.com/b/girishr/archive/2011/02/09/dynamics-crm-2011-developer-training-kit.aspx
Tags: C#, Code, CRM 2011 Beta, Link, Tutorial,
.Net | C# | Code | CRM 2011 Beta | CRM 5.0 | Download | Link | Tutorial
This book is a gift from the Windows Phone 7 team at Microsoft to the programming community, and I am proud to have been a part of it. Within the pages that follow, I show you the basics of writing applications for Windows Phone 7 using the C# programming language with the Silverlight and XNA 2D frameworks. For more information, check out this page : http://blogs.msdn.com/b/microsoft_press/archive/2010/10/28/free-ebook-programming-windows-phone-7-by-charles-petzold.aspx
You can download a PDF here (12.5 MB).
You can download an XPS here (26.7 MB).
And you can download the ebook’s sample code here (5.03 MB).
Tags: Windows Phone 7.Net, C#, Code, Download, Link, Microsoft, News, Tutorial,
.Net | Code | Download | Link | Microsoft | News | Tutorial
Microsoft Press has been providing free ebooks on regular interval and this very handy book has come out as a gift to the developers who are moving to Visual Studio 2010.
Here are the links for the book and related code download
You can download a PDF of the book here.
You can download an XPS of the book here.
And you can download the book’s sample code here.
Tags: C#, .Net, Code, Download, Link, Microsoft, Visual Studio 2010
.Net | Code | Download | Link | Microsoft | Visual Studio 2010
Few weeks back I stumbled upon this awesome code library http://1code.codeplex.com/
It has lots of code samples which you could use in your application and also learn various development techniques.
From CodePlex's about us of All-In One Code Framework
Microsoft All-In-One Code Framework delineates the framework and skeleton of Microsoft development techniques through typical sample codes in three popular programming languages (Visual C#, VB.NET, Visual C++). Each sample is elaborately selected, composed, and documented to demonstrate one frequently-asked, tested or used coding scenario based on our support experience in MSDN newsgroups and forums. If you are a software developer, you can fill the skeleton with blood, muscle and soul. If you are a software tester or a support engineer like us, you may extend the sample codes a little to fit your specific test scenario or refer your customer to this project if the customer's question coincides with what we collected.The project has more than 450 code examples that cover 24 Microsoft development technologies such as Azure, Windows 7 and Silverlight 3. The collection grows by six samples per week. You can find the up-to-date list of samples in All-In-One Code Framework Sample Catalog.
Tags: .Net, C#, Code, Download, Tutorial,
.Net | C# | Code | Download | Tutorial
I have been doing a lot of research off late for one of my clients. Recently I ran into an issue where I had to play with FileSystemWatcher class. This good ol' friend of mine is pretty nifty and except few tricks, you can go ahead with a straight forward implementation.
Here is a sample form code that I wrote :
1: namespace Skynet.FSWatch 2: { 3: using System; 4: using System.IO; 5: using System.Text; 6: using System.Windows.Forms; 7: 8: public partial class MainForm : Form 9: { 10: delegate void SetTextCallback(string value); 11: 12: public MainForm() 13: { 14: InitializeComponent(); 15: } 16: 17: private void WatchButton_Click(object sender, EventArgs e) 18: { 19: FileSystemWatcher watcher = new FileSystemWatcher(this.FolderPathTextBox.Text); 20: watcher.EnableRaisingEvents = true; 21: watcher.IncludeSubdirectories = true; 22: watcher.InternalBufferSize = 16384; 23: 24: watcher.Created += new FileSystemEventHandler(FSChangeHandler); 25: watcher.Deleted += new FileSystemEventHandler(FSChangeHandler); 26: watcher.Changed += new FileSystemEventHandler(FSChangeHandler); 27: watcher.Renamed += new RenamedEventHandler(watcher_Renamed); 28: watcher.Error += new ErrorEventHandler(watcher_Error); 29: } 30: 31: void watcher_Renamed(object sender, RenamedEventArgs e) 32: { 33: StringBuilder stringBuilder = new StringBuilder(); 34: stringBuilder.Append("ChangeType : " + e.ChangeType + Environment.NewLine); 35: stringBuilder.Append("OldFullPath : " + e.OldFullPath + Environment.NewLine); 36: stringBuilder.Append("FullPath : " + e.FullPath + Environment.NewLine); 37: 38: stringBuilder.Append("OldName : " + e.OldName + Environment.NewLine); 39: stringBuilder.Append("Name : " + e.Name + Environment.NewLine); 40: 41: this.SetText(stringBuilder.ToString()); 42: } 43: 44: void watcher_Error(object sender, ErrorEventArgs e) 45: { 46: SetText(e.GetException().Message + Environment.NewLine + e.GetException().StackTrace); 47: } 48: 49: void FSChangeHandler(object sender, FileSystemEventArgs e) 50: { 51: StringBuilder stringBuilder = new StringBuilder(); 52: stringBuilder.Append("ChangeType : " + e.ChangeType + Environment.NewLine); 53: stringBuilder.Append("FullPath : " + e.FullPath + Environment.NewLine); 54: stringBuilder.Append("Name : " + e.Name + Environment.NewLine); 55: 56: this.SetText(stringBuilder.ToString()); 57: } 58: 59: private void SetText(string text) 60: { 61: if (this.OutputTextBox.InvokeRequired) 62: { 63: SetTextCallback setTextDelegate = new SetTextCallback(SetText); 64: this.Invoke(setTextDelegate, new object[] { text }); 65: } 66: else 67: { 68: this.OutputTextBox.Text += text; 69: } 70: } 71: 72: private void FolderPathTextBox_DoubleClick(object sender, EventArgs e) 73: { 74: FolderBrowserDialog dialog = GetFolderBrowseDialog("Select a Folder"); 75: DialogResult result = dialog.ShowDialog(); 76: if (result == DialogResult.OK) 77: { 78: this.FolderPathTextBox.Text = dialog.SelectedPath; 79: } 80: } 81: 82: /// <summary> 83: /// Get Browse Folder Dialog 84: /// </summary> 85: /// <returns>Returns FolderBrowse Dialog</returns> 86: public static FolderBrowserDialog GetFolderBrowseDialog( 87: string description) 88: { 89: FolderBrowserDialog dialog = new FolderBrowserDialog(); 90: dialog.Description = description; 91: dialog.ShowNewFolderButton = true; 92: return dialog; 93: } 94: } 95: } 96:
Tags: Code, C#, .Net, Tutorial
I have moved to a different position since last one month and I get to do some R&D and I am trying to coming up with tools which can help Developers to finish their tasks as soon as possible without facing any road blocks.
I was trying to figure out a way to compile and execute code on the fly without storing the output to disk, and after looking at some examples on MSDN I came up with this code.
namespace CrmXpress.CodeDom
{using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms;using Microsoft.CSharp; using System.CodeDom.Compiler; using System.Reflection; public partial class CodeDomForm : Form { public CodeDomForm() { InitializeComponent(); } private void AddButton_Click(object sender, EventArgs e) { CSharpCodeProvider provider = new CSharpCodeProvider(); ICodeCompiler ICC = provider.CreateCompiler(); // You have to add all the valid references here i.e. all the assemblies which you are going to use in your codevar parameters = new CompilerParameters(new[] { "System.Windows.Forms.dll" });// Generate the assembly in memory parameters.GenerateInMemory = true;// This is a class stub string code = "namespace Skynet{class XXX{public void Execute(){{0}}}}";// Replace the placeholder with actual code that you have written in CodeTextBox code = code.Replace("{0}", this.CodeTextBox.Text); // Compile the codeCompilerResults result = ICC.CompileAssemblyFromSource(parameters, code);// If there are any errors, display a message to end user if (result.Errors.Count > 0) { MessageBox.Show(result.Errors[0].ErrorText); } else {// Otherwise using reflection, create instance of XXX class in memory and call the Execute method Assembly assmebly = result.CompiledAssembly; object target = assmebly.CreateInstance("Skynet.XXX"); target.GetType().InvokeMember("Execute", BindingFlags.InvokeMethod, null, target, null);// you can use this sample code to run minor test. If you copy this code right, on click of Add button you should see : "GFYS : 11". /*int x = 5; int y = 6; System.Windows.Forms.MessageBox.Show("GFYS : " + (x + y));*/ } } }}Comments/Questions are welcome.
Tags: .Net, Tutorial, Code, C#
.Net | Tutorial | C# | Code
Powered by BlogEngine.NET 2.5.0.6 Theme by CrmXpress.Net
I've been working on CRM since last 6 years and I am mesmerized by the sheer capabilities of this product. This blog is a medium via which I will try to share my various experiences on CRM, .Net, DHTML and a lot more. If you like my blog please leave a comment and/or rating on the posts.