Getting Total Record Count in CRM 2011

by Chinmay 4. September 2012 01:29

Many a times I run into this particular situation and somehow I observe people still retrieve all records and then loop through to get the total number of records. It is very easy to get it using the code given below.

QueryExpression query = new QueryExpression("account");
            query.ColumnSet = new ColumnSet(true);
            query.Criteria.AddCondition(new ConditionExpression("accountid", ConditionOperator.NotNull));
            query.PageInfo = new PagingInfo();
            query.PageInfo.Count = 1;
            query.PageInfo.PageNumber = 1;
            query.PageInfo.ReturnTotalRecordCount = true;

            EntityCollection result = this.ServiceProxy.RetrieveMultiple(query);
            int totalRecords = result.TotalRecordCount;

Tags: , , ,

Releasing CrmXpress RunAs GUI tool

by Chinmay 4. November 2011 17:59

It's been a long time since I thought to put this to public. I have used this tool for a quite a long time now. Basically, it allows you to create profiles with username and password. Now being CRM developer many a times you would want to launch CRM Web interface with another user's credentials. Generally, you would do so by using Run As or by creating a shortcut that will ask for credentials when it is clicked OR by disabling automatic logon in intranet zone.

I wanted to come up with a lot easier way to achieve this. That's why I made a simple utility that stores usernames and credentials and set of applications in a profile. You can create as many profiles as you want and add as many applications as you need. Credentials you provided are encrypted and stored with user settings. To add application, all you need to do is drag and drop a shortcut of the application or the application itself on to CrmXpress Run As Gui tool.

You can download it from here : http://www.crmxpress.net/Tools/CrmXpress.Win.RunAsGUI.zip

Your feedback is really important for me to provide feature upgrades/bugfixes.

Kindly note that I have tested this utility on Win7/Server2K8/Server2K8R2 x86/x64 editions with .NET Framework 2.0.

Here are steps to start using this tool.

  1. Launch CrmXpress.Win.RunAsGui.exe
  2. Click on Add. It will auto fill current user name and domain/workgroup name.
  3. Enter password.
  4. Click on Save. Your default user profile is now created.
  5. Click on Add again. It will auto fill current user name and domain/workgroup name. Change the name with any other domain/workgroup user name of your choice.
  6. Enter password for the user name that you have entered.
  7. Click on Save.
  8. Now you will have two profiles and you can access them via Profiles drop down list.
  9. Drag any application shortcut on to the CrmXpress.Win.RunAsGui's User Interface.
  10. The application will be added to the applications list for a given profile and it will be launched with credentials of whichever user profile you have selected.

 

Disclaimer 

  • This program is provided as is without any guarantees or warranty.
  • Although the author has attempted to find and correct any bugs in the free software programs, the author is not responsible for any damage or losses of any kind caused by the use or misuse of the programs.
  • The author is under no obligation to provide support, service, corrections, or upgrades to this free software program.

Tags: , , , , ,

.Net | C# | Download | Link | Tool

Visual Studio Task List and Comment Tokens

by Chinmay 4. May 2011 06:14

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

Process Nested XML using C#

by Chinmay 20. April 2011 09:36

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

Dynamics CRM 2011 Developer Training Kit Released

by Chinmay 13. February 2011 03:15

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: , , , , ,

.Net | C# | Code | CRM 2011 Beta | CRM 5.0 | Download | Link | Tutorial

Free ebook: Programming Windows Phone 7, by Charles Petzold

by Chinmay 9. November 2010 11:01

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: , , , , , , , ,

.Net | Code | Download | Link | Microsoft | News | Tutorial

Free ebook: Moving to Microsoft Visual Studio 2010

by Chinmay 26. October 2010 09:17

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: , , , , , ,

.Net | Code | Download | Link | Microsoft | Visual Studio 2010

All-In-One Code Framework - Awesome Code Repository

by Chinmay 20. September 2010 11:31

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

FileSystemWatcher implementation

by Chinmay 9. August 2010 22:37

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: , , ,

.Net | C# | Code

On The Fly Code Compilation & Execution in C#

by Chinmay 6. August 2010 06:12

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 code
var 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 code
CompilerResults 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 | C# | Code

About Me

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.

#1
#2
#3
Questions Answered
Overall Points
quot;


Subscribe in a reader

Calendar

<<  May 2013  >>
MoTuWeThFrSaSu
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

View posts in large calendar