locked
How to access XML file in Dynamics CRM 2011 Plugin? RRS feed

  • Question

  • Hello Friends,

    I am facing a problem while using xml data file in a Dynamics CRM 2011 Plug-in. I have some data in default.xml file which i am using in my plugin. Following image will show show passion of my xml file:

    In On Premise CRM, when i write ds.ReadXml(HttpContext.Current.Server.MapPath("/default.xml")); the error log returns "file cannot be find at "C:/ProgramFiles/Microsoft Dynamics CRM/CRMWeb". And when i write ds.ReadXml("default.xml"); it returns "file cannot be find at "C:/Windows/System32/inetsrv".

    In Online CRM it gives me FileIOPermision error in both condition.

    I am unable to use XML with plugin in Dynamics CRM 2011. Please tell me what I am doing wrong in this code.

    Thanks in advance.

     

     

     

     

     

    Monday, January 9, 2012 11:52 AM

Answers

  • It won't work if you are registering a workflow in database. You don't know from what location crm is running this dll from.

    In crmonline, you are running the plugin in sandbox so you dont have a access to the directories of the machines.

    Your best bet is try creating a xml file as a webresource in crm itself. I generally add the all the configuration values in custom entity in crm.

    Crreate a custom entity called configuration and put all the values in there. You can read this file within the file and you don't have to worry about anything. It will work for all kind of crm installations.

    Just for information.. on on-premise installation, you can register the plugin on disk or crm server. I think it is server/assembly directory. Just verify that.

    I hope this helps.

     


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Amreek Singh Senior CRM Consultant CDC Praxa Sydney, Australia http://mscrmshop.blogspot.com http://crm2011usersettings.codeplex.com

    • Proposed as answer by Amreek Singh Monday, January 9, 2012 12:32 PM
    • Marked as answer by nmathur Monday, January 9, 2012 12:57 PM
    • Edited by Amreek Singh Monday, January 9, 2012 10:13 PM
    Monday, January 9, 2012 12:32 PM
  • Hi,

    When the Plugins run on On Premise CRM, C:/ProgramFiles/Microsoft Dynamics CRM/CRMWeb folder is the folder where you have installed CRM, you should copy your default.xml file into this folder, however this is not recommended when your CRM deployed on multiple servers and also in a server farm.

    Now Plugins for CRM Online runs in an isolated environment, also known as a sandbox, and access to the file system, system event log, certain network protocols, registry, and more is prevented in the sandbox. This means you cannot access any file from Online plugin at all.

    Please refer the SDK sample: Sample: Web Access from a Sandboxed Plug-in

    If you want to pass some config or your xml as unsecure  string, then you can pass these when  you register the Plugin using SDK Plugin Registration tool, and read these

    The Microsoft Dynamics CRM platform supports an optional plug-in constructor that accepts either one or two string parameters. If you write a constructor like this, you can pass any strings of information to the plug-in at run time.

    The following sample shows the format of the constructor. In this example, the plug-in class is named SamplePlugin.

    public SamplePlugin()
    public SamplePlugin(string unsecure)
    public SamplePlugin(string unsecure, string secure)
    


     

     

    The first string parameter of the constructor contains public (unsecure) information. The second string parameter contains non-public (secure) information. In this discussion, secure refers to an encrypted value while unsecure is an unencrypted value. When using Microsoft Dynamics CRM for Microsoft Office Outlook with Offline Access, the secure string is not passed to a plug-in that executes while Microsoft Dynamics CRM for Outlook is offline.

    The information that is passed to the plug-in constructor in these strings is specified when the plug-in is registered with Microsoft Dynamics CRM. When using the Plug-in Registration tool to register a plug-in, you can enter secure and unsecure information in the Secure Configuration and Unsecure Configuration fields provided in the Register New Step form. When registering a plug-in programmatically using the Microsoft Dynamics CRM SDK, SdkMessageProcessingStep.Configuration contains the unsecure value and SdkMessageProcessingStep.SecureConfigId refers to a SdkMessageProcessingStepSecureConfig record that contains the secure value.

     

     


    Thomas T(MCBMSS) If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Monday, January 9, 2012 12:32 PM

All replies

  • It won't work if you are registering a workflow in database. You don't know from what location crm is running this dll from.

    In crmonline, you are running the plugin in sandbox so you dont have a access to the directories of the machines.

    Your best bet is try creating a xml file as a webresource in crm itself. I generally add the all the configuration values in custom entity in crm.

    Crreate a custom entity called configuration and put all the values in there. You can read this file within the file and you don't have to worry about anything. It will work for all kind of crm installations.

    Just for information.. on on-premise installation, you can register the plugin on disk or crm server. I think it is server/assembly directory. Just verify that.

    I hope this helps.

     


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Amreek Singh Senior CRM Consultant CDC Praxa Sydney, Australia http://mscrmshop.blogspot.com http://crm2011usersettings.codeplex.com

    • Proposed as answer by Amreek Singh Monday, January 9, 2012 12:32 PM
    • Marked as answer by nmathur Monday, January 9, 2012 12:57 PM
    • Edited by Amreek Singh Monday, January 9, 2012 10:13 PM
    Monday, January 9, 2012 12:32 PM
  • Hi,

    When the Plugins run on On Premise CRM, C:/ProgramFiles/Microsoft Dynamics CRM/CRMWeb folder is the folder where you have installed CRM, you should copy your default.xml file into this folder, however this is not recommended when your CRM deployed on multiple servers and also in a server farm.

    Now Plugins for CRM Online runs in an isolated environment, also known as a sandbox, and access to the file system, system event log, certain network protocols, registry, and more is prevented in the sandbox. This means you cannot access any file from Online plugin at all.

    Please refer the SDK sample: Sample: Web Access from a Sandboxed Plug-in

    If you want to pass some config or your xml as unsecure  string, then you can pass these when  you register the Plugin using SDK Plugin Registration tool, and read these

    The Microsoft Dynamics CRM platform supports an optional plug-in constructor that accepts either one or two string parameters. If you write a constructor like this, you can pass any strings of information to the plug-in at run time.

    The following sample shows the format of the constructor. In this example, the plug-in class is named SamplePlugin.

    public SamplePlugin()
    public SamplePlugin(string unsecure)
    public SamplePlugin(string unsecure, string secure)
    


     

     

    The first string parameter of the constructor contains public (unsecure) information. The second string parameter contains non-public (secure) information. In this discussion, secure refers to an encrypted value while unsecure is an unencrypted value. When using Microsoft Dynamics CRM for Microsoft Office Outlook with Offline Access, the secure string is not passed to a plug-in that executes while Microsoft Dynamics CRM for Outlook is offline.

    The information that is passed to the plug-in constructor in these strings is specified when the plug-in is registered with Microsoft Dynamics CRM. When using the Plug-in Registration tool to register a plug-in, you can enter secure and unsecure information in the Secure Configuration and Unsecure Configuration fields provided in the Register New Step form. When registering a plug-in programmatically using the Microsoft Dynamics CRM SDK, SdkMessageProcessingStep.Configuration contains the unsecure value and SdkMessageProcessingStep.SecureConfigId refers to a SdkMessageProcessingStepSecureConfig record that contains the secure value.

     

     


    Thomas T(MCBMSS) If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Monday, January 9, 2012 12:32 PM