Wednesday, May 30, 2007

"Microsoft Surface" is here...


Surface is here - http://www.microsoft.com/surface/

“With Surface, you can actually grab data with your hands, and move information between objects with natural gestures and touch…”

“You can plan a day of sightseeing without leaving your hotel lobby…”



Explore...
Cheers - DJ

Tuesday, May 29, 2007

Tool to convert vb.net code to c# - Sharp Develop

Ever felt the need for a tool to convert "vb.net code to c#"? Try Sharp Develop.

#develop (short for SharpDevelop) is a free IDE for C#, VB.NET and Boo projects on Microsoft's .NET platform. It is open-source, and you can download both sourcecode and executables from this site.
Check the download section and more on http://www.icsharpcode.net/OpenSource/SD/ for tools to convert your VB.net code to C# and vice versa as well! Cheers - DJ

How do i import data from Outlook, lotus notes or any other data source into CRM 3.0?

How do i import data from Outlook, lotus notes or any other data source into CRM 3.0?

Every organization has data stored online about customers, products, leads, contacts, contracts, sales literature, competitors, and more. Perhaps you transferred this data to Microsoft Dynamics CRM 3.0 as part of your initial implementation or found or purchased data after everyone was already using Microsoft CRM. However you got the data, you can automate the process of importing it into Microsoft CRM so that no one has to manually re-enter the data.

Microsoft CRM includes five tools for importing data, each of which is designed for specific source data:

• Bulk Import Wizard

• Data Migration Framework

• Data Migration Wizard for Microsoft Office Outlook with Business Contact Manager

• Microsoft Dynamics CRM Connector for Microsoft Dynamics GP

• Microsoft CRM SDK
---------------------------------------------------------------
• Bulk Import Wizard -
The Bulk Import Wizard is useful for importing lists of names you have purchased or collected by other means. The data to import must be stored in a comma-delimited values (CSV) file or in a text file delimited with semicolons, colons, or tabs. The Wizard can be used only to import data into the Lead, Account, Contact, and Campaign Response areas of Microsoft CRM, including importing any custom attributes for these areas. Leads, accounts, and contacts can be imported directly to a marketing list. For example, one common use of the Bulk Import Wizard is to import contacts that have been exported from Microsoft Outlook into a CSV file. Another common use is to import data from a marketing list you purchased.
The Bulk Import Wizard cannot import notes and attachments!

• Data Migration Framework -
Data Migration Framework helps you to import data from any other data source. it is free and provided by Microsoft. Download Data migration framework

Check 5 ways to import data into CRM 3.0 as well.
HTH - Dipesh

Tuesday, May 22, 2007

How to set status of an custom entity to inactive?

How to set status of an built in entity like Account or custom entity to inactive?

Below is the code sample for SetState/Status to inactive for a system entity...[C#]

// Standard CRM Service Setup
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Create the request object.
SetStateAccountRequest state = new SetStateAccountRequest();

// Set the properties of the request object.
state.AccountState = AccountState.Inactive;
state.AccountStatus = -1;

// EntityId is the GUID of the account whose state is being changed.
state.EntityId = new Guid("AD618DB2-F0DB-4A6A-8C4B-2F2213EAA38E");;

// Execute the request.
SetStateAccountResponse stateSet = (SetStateAccountResponse)service.Execute(state);

If you want to set the status/state to a dynamic entity then use the following -
SetStateDynamicEntityRequest req = new SetStateDynamicEntityRequest();

req.Entity = new Property();

//Primary key of record
req.Entity.Id = new Guid("{AAD5DA71-34E3-DB11-90D0-0003FF873FE6}");
req.Entity.Name = "new_customentity";

req.State = "inactive";
req.Status = -1;
//req.State = "active";
//req.Status = 1;

service.Execute(req);


you have to use these provided classes to get the status inactive for a particular record in CRM. You cannot use StatusCode and StateCode to set these values directly to the entity as it did not reflected to me on the UI grid. However, Execute did wrk. Thanks - Dipesh

"Scribe" ...answer to migration from legacy systems

1> Want to migrate contacts from Outlook into your CRM application?
2> Want to migrate data from existing CRM apps like Siebel and sf.com into your CRM?
3> Want to automatically feed leads into Microsoft Dynamics CRM from a Web site?
4> Want to populate customers in Microsoft Dynamics CRM with financial and order history data from ERP?
5> Want to proactively monitor key customer activity through automated alerts sent to e-mail, cell phone, or Microsoft Dynamics CRM?
6> Want to enhance and validate data from third-parties via Web Services or data feeds
7> Want to synchronize customer data in real time between Microsoft Dynamics CRM and other applications ?

Check the Scribe tool that allows you to do all this in real short time compared to spending your own development cycle! Follow the simple installation steps outlined here - http://blogs.msdn.com/mscrmfreak/archive/2007/04/22/Improved-Scribe-Installation-Guide.aspx

Cheers -Dipesh Joshi

Thursday, May 17, 2007

Write Callouts using VS 2005 using this template...

knock knock... I was trying to write my first callout because i need to send some real time data to third party application from my CRM. So on click of Save (postCreate) i wanted to do something. Anyways, my box has got no VS 2003 installed and i learnt that callouts can only be written in VS 2003 because CRM was built in .net 1.1 framework. So i thought ok, i need to install VS 2003 ... means already crunching space woes adds up! but then i found this great atricle on Arash's blog which tells me that i need not install VS 2003...viola! :)

You can write callouts using VS 2005 if you got .net framework 1.1 only! Arash has written a template that you can download it from here - http://blogs.msdn.com/arash/attachment/719626.ashx (its a .msi, so fully automated) and you are good to go. Check his article here - http://blogs.msdn.com/arash/archive/2006/08/25/719626.aspx

If you choose to create your own template then visit Jomo's blog - http://blogs.msdn.com/jomo_fisher/articles/410896.aspx He has explained it beautifully here. You need to know MSBUILD a little to get this manually done. I prefered MSI built by Arash ...it helped me a lot! Cheers - Dipesh Joshi

Changing the web service URL dynamically in .net

How do I change the web service URL's dynamically across projects in VS.net?

If you do not want to hard code your web service URL's into your project then there's a way out!
1> You can add web reference in VS.net and change the web service property to dynamic.

What we did -
2> Create a utility class and added this static method -
public static CrmService GetCrmService()
{
CrmService crmService = new CrmService();
crmService.Url = Client.Sample.Data.Properties.Settings.Default.Client_Sample_Data_CrmWebService_CrmService;
crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;
crmService.PreAuthenticate = true;

return crmService;
}

3> In the same utility class add Settings file (VS 2005) and add webservice URL's there. Settings is a user friendly GUI ...so add webservice_URL = "\Test.asmx".

4> Save the settings file. The changes once saved would get synced up/updated in app.config available in Utility project. All settings should reflect in applicationSettings in App.config.

5> Copy this section of application settings into your web.config or any config file under any project... reference the utility class (.dll) we just created.

6> Call the static method from your app/project and you should copy paste applicationSettings from utility app.config into your config file.

You should now be good to go. Just change the URL's in your web.config file and without compiling you should be good to go.

Cheers - Dipesh Joshi

GhostDOC VS addin to generate XML documents...

One of the tools that you would like to have as an MS Visual Studio addin - GhostDOC !

XML comments are invaluable tools when documenting your application. Using XML comments, you can mark up your code and then, using a tool like nDoc, you can generate help files or MSDN-like Web documentation based on those comments. The only problem with XML documentation is the time it takes to write it you often end up writing similar statements over and over again. The goal of GhostDoc is to automate the tedious parts of writing XML comments by looking at the name of your class or method, as well as any parameters, and making an educated guess as to how the documentation should appear based on recommended naming conventions. This is not a replacement for writing thorough documentation of your business rules and providing examples, but it will automate the mindless part of your documentation generation.

http://www.roland-weigelt.de/ghostdoc/

After installing GhostDoc, you can right-click on the method declaration and choose Document this.

Don't stop hereyou should add additional comments stating where the person is being saved to or perhaps give an example of creating and saving a person.
Adding these extra comments is much easier since the basic, redundant portion is automatically generated by GhostDoc. GhostDoc also includes options that allow you to modify existing rules and add additional rules that determine what kind of comments should be generated.

GhostDoc was written by Roland Weigelt and can be downloaded for VS 2005, VS Orcas as well from www.roland-weigelt.de/ghostdoc

HTH, Thanks - Dipesh

Wednesday, May 16, 2007

Filtered Views in CRM 3.0

Did you know that apart from FetchXML (v 1.2 carry on) and Query Expression (v 3.0 faster, powerful approach) we also have FilteredViews in CRM 3.0 by which we can query the CRM database.

FetchXML and QueryExpression give you information from CRM database via CRM web service but FilteredViews allow you to retrieve data from CRM directly hitting the SQL. Microsoft does not recommend you to access the CRM - SQL database directly for any manipulations but if you want to just retrieve(read) the records from CRM entities(built in + custom) it's absolutely fine to do so using Filtered Views.

One of the reason we would like to use FilteredViews is because we needed information from multiple entities. You cannot use QueryExpression for that in CRM 3.0 but sure can use FetchXML.
See my previous post

The problem with FetchXML is the flat structure it returns (as i mentioned in my prev posts). With FilteredViews you have the liberty to work the way you did in SQL server. You get the power of SQL DML usage and ADO.net (can also use features like GroupBy, multiple joins easily etc.)

However do NOT attempt to insert/update records directly into CRM database.

Here's an explanation on FilteredViews -

If you were to browse the Microsoft CRM SQL database (with a tool such as SQL Server Enterprise Manager or SQL Query Analyzer), you might notice multiple data objects related to Accounts, including:

1> AccountBase table
2> AccountExtensionBase table
3> AccountLeads table
4> Account view
5> FilteredAccount view

When you want to write your own custom report about Accounts, you might wonder which of these database objects includes the information you're looking for.

Fortunately, instead of forcing you to spend hours investigating what types of entity data CRM stores and what relationship exists between these objects, CRM has simplified reporting for us by offering "filtered views". Filtered views perform the cumbersome task of denormalizing multiple tables and relationships into a streamlined view of entity and system data. In addition, filtered views respect the CRM security settings so that users who query filtered views (or run reports that query filtered views) will see only the data that they're allowed to see.

Two different users viewing the same report might see entirely different results depending on the Microsoft CRM security settings. This feature will save you hours by trying to manually determine the security and data settings of each custom report.

These objects (as listed above) are also created for all custom entities that we create in CRM.

Also, filtered views translate lookup fields and picklist values, and they calculate all datetime values in both Coordinated Universal Time (UTC) and the user's localized value.

HTP, Cheers - Dipesh

Connection string with Windows and SQL Server authentication...

Useful one thought of sharing this - Here's a whole site with information on just Connection strings for different databases.
ConnectionStrings.com

Quick one for .net/SQL -
Integrated Security=True - If you want to use windows authentication (takes windows credentials)
SqlConnection connection = new SqlConnection("Data Source=;Initial Catalog=;Integrated Security=True; ");

Integrated Security=False - If you want to use SQL server authentication (provide user name and password and this loging shud be present in SQL 2005)
SqlConnection connection = new SqlConnection("Data Source=;Initial Catalog=;Integrated Security=False; Uid = <'sql login name'> Pwd =<'sql pwd'> ");
Credits - Gaurav for healthy discussion. Cheers - Dipesh

IIS Logs and Log Parser utility...

Did you know ... in addition to the Windows Server 2003 system and security logs, you should configure IIS to log site visits. When users access your server running IIS 6.0, IIS logs the information. The logs provide valuable information that you can use to identify any unauthorized attempts to compromise your Web server.

Depending on the amount of traffic to your Web site, the size of your log file (or the number of log files) can consume valuable disk space, memory resources, and CPU cycles. You might need to balance the gathering of detailed data with the need to limit files to a manageable size and number. If you are planning to put thousands of Web sites on one Web server with high traffic volumes and disk writes, you might want to use centralized binary logging to preserve server resources. Also, consider limiting log size by changing the frequency of log file creation.

For more information check MS site here - http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/b344f84e-bc77-4019-859c-9d483bc85c77.mspx?mfr=true

Ok, you can convert your IIS logs into SQL database as well so that you can do more efficent reporting
Also, you can write your custom logging modules and have logs displayed on ASP page as well. Check all about IIS logging here -


Do you need a tool to do all this - "Log Parser" (command line utility) :)
Log Parser allows you to do universal query access to text-based data such as log files, XML files and CSV files, as well as key data sources on the Windows® operating system such as the Event Log, the Registry, the file system, and Active Directory®.

Download it from here -
http://www.microsoft.com/downloads/details.aspx?familyid=890cd06b-abf8-4c25-91b2-f8d975cf8c07&displaylang=en

CRM 3.0 does not have functionality inbuilt for profiling transactions? To get reports like ...which user accessed Contacts, Case or a particular page number of times or any unauthorized access we need to use IIS logs to meet the needs. Credits to Ronald for sharing this info
Thanks - DJ

Friday, May 11, 2007

Thursday, May 10, 2007

Advanced Find to generate FetchXML for you....(single entity)

You can use Advanced Find in CRM tool to generate FetchXML for you instead of manually writing the string or using any other tool.

You can just open the Advanced find page and build the query as you like. Then run the query to see if it returns the data as you wish it should. If you are satisfied with the results and you want to know what query was sent into the CRM Framework, then press F11 to get the address bar and enter this script below and press enter.

javascript:prompt("my query:", resultRender.FetchXml.value);

I was able to get this working for single entity though.. for multiple entities i had a tough time. But the tool i mentioned in my earlier post http://archdipesh.blogspot.com/2007/05/how-to-retrieve-multiple-attributes.html helps me for multiple entities! Thanks - Dipesh

how to retrieve multiple attributes from multiple entities in CRM 3.0?

How to retrieve multiple attributes from multiple entities in CRM 3.0?

For all those who have tried using QueryExpression to retrieve attributes from multiple entities i am sure it is a hard try! But with no fault of your's this seems to be the limitation within CRM 3.0 as QueryExpression just returns one object. So really in CRM 3.0 if you want to return multiple attributes from more than 1 entity you will have to use the CRM 1.2 - FetchXML technique. Here's how the fetchXML looks.
Entities in example include - Property (parent) related to child Meeting Room entity and meeting room is related to Events entity.

You can use Count to restrict the number of records spitted.
Really, if you feel this is all confusing you can use James tool - http://jamesdowney.net/fetchxml.aspx to create an fetchXML for you real quick. It is free!



here's a sample code for FetchXML -
try
{
//set the CRM service instance
CrmService crmService = new CrmService();
crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Retrieve the results.
string result = crmService.Fetch(fetchXML); //fetchXML is the string shown above
return result;
}
catch (System.Web.Services.Protocols.SoapException ex)
{
return ex.Message;
}

CRM gurus say that they MS will try to overcome this limitation in Titan release. Till then this workaround works fine!
1 issue i found hard to meet my requirement was that it spits back flat structure rather than defined hirearchy. The parent record( property in example above) is returned as an XMl element with every child record. I am not sure how do we achieve GroupBy similar to SQL in FetchXML?! Thanks - Dipesh

Tuesday, May 08, 2007

Writing your own Code Snippet...

You can write your code snippet and create a library for day to day coding tasks. This post on ArashSichanie explains you simple yet effective steps to do so.
http://blogs.msdn.com/arash/archive/2006/07/14/666114.aspx
This snippet in example can be used for CRM activity. Cheers - Dipesh

Creating an XML Document using XMLDom and returning string as response...

Some answers are so straight forward but you just dont find them when you need them. I am happy that i am maintaining this blog and hopefully the next time when i need these answers i come back here.... :)

This is the XML i am trying to create -


//Create XML document
XmlDocument xmlDoc = new XmlDocument();

//Write down the XML declaration
XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);

// Create the root element
XmlElement rootNode = xmlDoc.CreateElement("PropList");
xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);
xmlDoc.AppendChild(rootNode);

//
//Create an XML element
XmlElement parentNode = xmlDoc.CreateElement("Prop");
//Create an XML attribute
XmlAttribute idAttribute = xmlDoc.CreateAttribute("PropID");
idAttribute.Value = i.ToString();
//Associate the attribute to the element
parentNode.SetAttributeNode(idAttribute);

xmlDoc.DocumentElement.PrependChild(parentNode);

//MEMSG
//Create an XML element
XmlElement newCityHocn = xmlDoc.CreateElement("CityHocn");
newCityHocn.InnerText = "MEMSG";
//Add this element as an child to Prop
parentNode.AppendChild(newCityHocn);

//1000121
//Create an XML element
XmlElement newSecFacilityID = xmlDoc.CreateElement("SecondaryFacilityID");
newSecFacilityID.InnerText = "1000121";
//Add this element as an child to Prop
parentNode.AppendChild(newSecFacilityID);
//


// Save to the XML file
//xmlDoc.Save(@"D:\test.xml");

//return string
xmlDoc.OuterXML;

If you are creating a web service and you want to return string as an response to the web method then use xmlDoc.OuterXML instead of saving to a file. String response will help non .net platforms to consume from web service as well.

Others - http://www.mastercsharp.com/article.aspx?ArticleID=69&&TopicID=9

Thanks - Dipesh

Orcas Beta 1 VPC download...Step 1

Rock on Orcas Beta ... if you want to get started this is the starting point -

1> Download the Base image (one-time only): VSCTPBase.exe (1.12 GB)

2> Download all parts of the Visual Studio Code Name Orcas Beta 1. The first part is a self-extracting EXE and will prompt for the other parts. Find the download for OrcasBeta1VSTS_VPC_8PartsTotal.part01.exe here - (700 MB)

http://www.microsoft.com/downloads/details.aspx?FamilyId=36B6609E-6F3D-40F4-8C7D-AD111679D8DC&displaylang=en

Find the steps to follow on the above URL as well to get your VPC working... no install needed. Get going now!

Thanks - Dipesh

Monday, May 07, 2007

Code snippets for daily coding tasks...

I am sure most of them know this .... but thought worth pointing this out -

IntelliSense Code Snippets are reusable, task-oriented blocks of code. Visual Studio 2005 includes code snippets covering tasks ranging from creating a custom exception, to sending an e-mail message, to drawing a circle. A set of Visual Basic and Visual C# Code Snippets are included in the Visual Studio 2005 box – additional Code Snippets can be found below.
http://msdn2.microsoft.com/en-us/vstudio/aa718338.aspx

Thanks - Dipesh

Saturday, May 05, 2007

Is there an easy way to change the default 5555 port CRM uses and are there any implications?

Is there an easy way to change default 5555 port CRM uses and are there any implications?

You can easily change the port settings in 2 places:
1> In IIS, go into the properties of the CRM website and enter the default port 80 or any preferred used port number.
2> In the registry under the MSCRM hive, update the ServerURL regkey.
That's it!

"You can also setup an IIS web site using the desired port prior to the install and have CRM use that website during the install vs. creating its own. There is no way to override the install’s use of 5555 for the site it creates though.

Due to some of the nuances of what CRM does with the site and how it handles host headers and such, it may be easier to uninstall/reinstall in this manner than to try to mess with the port."

Thanks to Will and Matt for explaining this. Hope this helps. Thanks - D

Thursday, May 03, 2007

ReSharper 2.5.2 Maintenance Release

The new evaluation scheme deserves a special mention. Simply put, we've made evaluation easier by eliminating evaluation licences. Just download, install and enjoy ReSharper for 30 days. We only ask for one thing: after you've tried the software, please select Submit Feedback from ReSharper menu and tell us your thoughts.
The full list of changes and enhancements is available at
http://www.jetbrains.com/resharper/releaseNotes252.html?rs252nl

You can download version 2.5.2 at
http://www.jetbrains.com/resharper/download/index.html?rs252nl

The latest maintenance release features multiple bugfixes and several enhancements, which include:
- Better ASP.NET support
- Join/split string context action
- Improved stability
- New evaluation scheme
The new evaluation scheme deserves a special mention. Simply put, we've made evaluation easier by eliminating evaluation licences. Just download, install and enjoy ReSharper for 30 days.
Cheers - Dipesh

Announcing: CRM SDK V3.0.7 Updated

Announcing an update to the Microsoft CRM 3.0 SDK! Download version 3.0.7 of the SDK to get new and updated sample code, topic enhancements, and bug fixes. Here are few of the changes you’ll find in this version:
Learn best practices for writing code that performs better by creating multiple threads and using unsafe connection sharing.
In the Sample Code section, you’ll find new samples that show you how to:
Create a customer relationship
Create an opportunity and set a picklist
Perform a bulk delete operation
You can download the updated SDK from this location: www.microsoft.com/downloads/details.aspx?FamilyId=9C178B68-3A06-4898-BC83-BD14B74308C5&displaylang=en. This update will be live on MSDN soon!

Tuesday, May 01, 2007

IE Developer toolbar...

If you're like most Web developers, when you were first learning HTML, you probably spent a great deal of your time playing around with your browser. The fact that you could simply do a "View Source" and see how an interesting web page was implemented was one of the things that helped HTML catch on so quickly. This "code sharing" is undoubtably one of the reasons the Web was able to grow as quickly as it did.
Unfortunately, these days it's not so easy to take a look at the magic going on behind the scenes of the average web page. With the emphasis on usability and appearance, the previously simple HTML has become incresingly difficult to read and these days most web pages are made up of a combination of several files and use often use as much CSS and client-side script as they do HTML. Using "View Source" simply doesn't cut it anymore. Luckily Microsoft has realized this fact and is building a tool to help developers analyze these increasingly complex web documents. It's called the Internet Explorer Developer Toolbar. In this article I'll give you a quick introduction to this powerful new tool and examine some of it's most useful features.

These features enable you to:
1 Explore and modify the document object model (DOM) of a Web page.
2 Locate and select specific elements on a Web page through a variety of techniques.
3 Selectively disable Internet Explorer settings.
4 View HTML object class names, ID's, and details such as link paths, tab index values, and access keys.
5 Outline tables, table cells, images, or selected tags.
6 Validate HTML, CSS, WAI, and RSS Web feed links.
7 Display image dimensions, file sizes, path information, and alternate (ALT) text.
8 Immediately resize the browser window to a new resolution.
9 Selectively clear the browser cache and saved cookies. Choose from all objects or those associated with a given domain.
10 Choose direct links to W3C specification references, the Internet Explorer team weblog (blog), and other resources.
11 Display a fully featured design ruler to help accurately align and measure objects on your pages.
12 Find the style rules used to set specific style values on an element.
13 View the formatted and syntax colored source of HTML and CSS.

Download the beta version from here - http://www.microsoft.com/downloads/details.aspx?FamilyID=e59c3964-672d-4511-bb3e-2d5e1db91038&displaylang=en

Check for details on IE developer tool here - http://www.15seconds.com/issue/070208.htm

- D

Convert XML data to object and back using serialization

Introduction -
This article shows you how to convert an XML to a class object and retriving back.

Saving XML to a class object is called serialization and reading back using the reverse process is called as deserialization.
1> Assuming you have a sample xsd, to convert a class from XSD, we would run the following command:

xsd C:\Contact.xsd /t:lib /l:cs /c from VS.net command prompt.
2> /// auto generated code from xsd command ran above...
using System.Xml.Serialization;
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public class Contact
{        
public ContactInfo;
}
public class ContactInfo
{        
public string Code;        
public string FirstName;        
public string LastName;        
public string Email;
}
 
3> Now, we could save an contact XML data to this class using this simple function:
public Contact ContactObject(string xml)  
{   
StringReader stream = null;   
XmlTextReader reader = null;   
try   
{    
// serialise to object    
XmlSerializer serializer = new XmlSerializer(typeof(Contact));
stream = new StringReader(xml); // read xml data    
reader = new XmlTextReader(stream);  // create reader    
// covert reader to object    
return (Contact)serializer.Deserialize(reader);   
}   
}
 
And to get the XML based on the Contact class object, use the following function:
public string ContactXML(Contact cont)  
{   
MemoryStream stream = null;   
TextWriter writer = null;   
try   
{    
stream = new MemoryStream(); 
// read xml in memory    
writer = new StreamWriter(stream, Encoding.Unicode) ;    
// get serialise object    
XmlSerializer serializer = new XmlSerializer(typeof(Contact));    
serializer.Serialize(writer, cont); 
// read object    
int count = (int) stream.Length; 
// saves object in memory stream    
byte[] arr = new byte[count];    
stream.Seek(0, SeekOrigin.Begin);    
// copy stream contents in byte array    
stream.Read(arr, 0, count);    
UnicodeEncoding utf = new UnicodeEncoding(); 
// convert byte array to string    
return utf.GetString(arr).Trim();   
}   
}
 
Hope this helps for all working on XML!
Thanks - DJ