Friday, November 16, 2012

C# Plugin for Dynamics CRM 2011 How to : from create to install



Too to use: 

CRM plugin Registry tool 2011

steps: 

1. visual studio 2010 
New > Project > Class library > "Name your plugin"
2. Add References (Verweise) : microsoft.xrm.sdk from your sdk installed location
Ready now !

3. Name your class like : public class XYZ : IPlugin 
4. Start with the following code to have the talk with your CRM. The function Execute is your starting point. 
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (!context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) return;
Entity entity = (Entity)context.InputParameters["Target"];
// if (entity.LogicalName != "account") return;

try
{
#region init
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
this.service = serviceFactory.CreateOrganizationService(context.UserId);
Entity oEntity = context.PostEntityImages["img"];
#endregion
}
}

-Every edit in the code requires update in the Plugin Reg too

-Prior to Every debug needs to attach (anhängen) the exe file from Debug>process attach  
5. What is oEntity ? This is an image for your post entries to a textfield (for example). The edits you do after the entity loads.

Only the fields those being affected are considered, therefore the changes are recorded as an image. You need to register this image as well as the events (for ex. update and create of an entity) along with the project's successful build file.
For details: http://msdn.microsoft.com/en-us/library/gg309580.aspx
Connect CRM : http://crm234

a. Register a Plug-in Assembly

b.Location example : C:\Program Files\Microsoft Dynamics CRM\Server\bin\assembly\ ...dll or (pdb)

c. Register the Plug-in for an Event

d. we set the plugin as asynchronous. Which means the plugin actions won't effect on priority saving; so that it won't make the system slow.

6. To debug (Erstellen) add a file named copy.cmd inside \bin\debug and type like: 

xcopy "XYZ.dll" "C:\Program Files\Microsoft Dynamics CRM\Server\bin\assembly" /y /v
xcopy "XYZ.pdb" "C:\Program Files\Microsoft Dynamics CRM\Server\bin\assembly" /y /v

-- Right click prject>properties>Buildereignis>type : copy.cmd in the region : Befehlszeile für Postbuildereignis

--Here the successful builds (.dll) and the project file (.pdb) will be overwritten

      --CRM server gonna use this .dll file for the targeted execution.

7. Signature (Signiung): Must be set default which is user specific.
Install plugin to CRM
*********************
Remember where you kept your XYZ.dll file

1. Go to solution > Plugin Assemblys > Add Existing Elements> Add XYZ.dll file to the solution

2. click>SDK message>Add your Registered events (create,update)

Friday, November 9, 2012

Microsoft Dynamics CRM 2011 : At a glance - What can it do?

I was looking for some basic and important information on MSCRM 2011, hope the link below is one of them: 
 http://www.dynamicsexchange.com/CRM-2011/CRM-Overview.aspx#CRMvideos

C# : Read pdf intearactive form text fields, Write those fields values in CSV and XML format

Create a pdf interactive form using adobeFormsCentral>save it>add it in your project.
-- Download iTextSharp >unzip it>find core iTextSharp.dll>add it as reference in your project >finally include this library for your functions> there you are .. ready..

public string pdfInputFile = "//~Files/pdfTest2.pdf"; 
public string pn, nam, ph;

    private void ReadPDF()
    {
        PdfReader pdfRdr = new PdfReader(pdfInputFile);
        AcroFields frm = pdfRdr.AcroFields;
        var fkeys = frm.Fields.Keys;

        pn = frm.GetField("txtID");
        nam = frm.GetField("txtName");
        ph = frm.GetField("txtPhone");
    }


// Write and save an CSV file from the pdf fields values

    private void WriteCSV()
    {
        StreamWriter swFromFile = new StreamWriter(@"c:\temp\temp.csv");
        swFromFile.WriteLine("\"ID\";\"Name\";\"Phone\"");
        swFromFile.WriteLine("\"" + pn + "\";\"" + nam + "\";\"" + ph + "\"");
        swFromFile.Flush();
        swFromFile.Close();
    }


// Write and save an XML file from the pdf fields values

    private void WriteXML()
    {

        XmlWriterSettings settings = new XmlWriterSettings();
        settings.Indent = true;
        try
        {
            XmlDocument doc1 = new XmlDocument();
            doc1.LoadXml("<root><ID></ID><Name></Name><Phone></Phone></root>");

            XmlNode xID = doc1.SelectSingleNode("/root/ID");
            xID.InnerText = pn;
            XmlNode xNam = doc1.SelectSingleNode("/root/Name");
            xNam.InnerText = nam;

            XmlNode xPh = doc1.SelectSingleNode("/root/Phone");
            xPh.InnerText = ph;

            doc1.Save(@"c:\temp\temp.xml");

           }
        catch (Exception ex)
        {
            lblmsg.Text = ex.Message;
        }
        txtFileName.Text = "xml writen from pdf";

    }

Friday, July 27, 2012

Creating an exe/Setup for Asp.net Project

Create Setup Project
  1. Go to file menu > click Add > new project >now “Add New Project” dialog will appear.
  2. Select the “Other Project Types” and click “Setup and Deployment” projects,Choose “Setup Project” give name project name in name text box finally click OK.
  3. New project appear in solution explorer,for eg., you have give the name “MyEXE” file will be displays with given name.
  4. Right click the MyEXE > go View > click “File System”
  5. You can see the “File System on TargetMachine”under three folders Application Folder User’s Desktop User’s Program Menu
  6. Select Application Folder and right click Add>Project Output>select Primary output
  7. Select User’s Desktop right click on the right side pane>click create new shortcut>select output file from Application folder>change the file name from primary output name to MyEXE Same procedure follows the user’s program menu also
  8. If you want to change the Manufactures name, just right click the project go to properties
  9. Finally Build the new project After successfully Build the project myEXE(Setup) will be appear in Application Debug or Release folder(depend upon the properties settings) EXE or installer will be available on his physical path…

Saturday, July 7, 2012

This is the test of the blog posting. Will be coming soon...