Close

Open local file/folders in Dynamics CRM 2013

This post is quite old, and this method may not work for you!
I would advise that you have a look at two alternative solutions :

For some reason, you might want to open a location using the file:// protocol in Dynamics CRM.

Result :

result2

In our case, we have 100K+ heavy scan files (>2MB/file) on a network share. Of course, I could publish them on an http server or on Sharepoint, but the engineering and sales department using these files need a very ergonomic and reliable access, and the IT department needs to be able to process all the files extremely quickly. Thus, a link that opens a folder directly on windows explorer best suits our needs (and all users are either in our LAN or connected via VPN). On top of that, we have to deal with access security, and our use case is not supported by default with the CRM/Sharepoint integration.

Of course, the first thing that comes to mind is to use the URL type for the field :

url-type2

But you will soon find out that there is a constraint on the protocols allowed…

url-validation2

Another solution is to embed an iFrame directly in the form. In our case, the results were very poor : we had refresh issues with the scroll, and no navigation (enter into a folder => no way to go back).

Ok, so let’s dive in, and make it work…

If you want to add a nice icon for the link, you can find one easily on : https://www.iconfinder.com/

In case you need to scale it, you can use The Gimp :

gimp-resize

Then, add it as a web resource :

webresource-img3

Now, create a new webresource : an html page with a small embedded javascript to update the dynamic URI.

html-webres3

Content of the webpage (you might want to do better than that, js in another webres, headers…) :

<html>
  <head>
    <meta charset="utf-8">
  </head>
  <body>
    <a id="doclink" style="border: 0px currentColor;" href="http://www.example.com" target="_blank">
      <img style="border: 0px currentColor;" src="stsr_folders_icon.png">
    </a>
    <script language="javascript" type="text/javascript">
      var linkval = window.parent.Xrm.Page.data.entity.attributes.get("stsr_documents").getValue();
      var a = document.getElementById('doclink');
      a.href = "file:"+linkval;
    </script>
  </body>
</html>

Using window.parent.Xrm.Page.data.entity.attributes.get(“stsr_documents”).getValue() enables you to access a value in a field. In my case, I used a field “stsr_documents” to store the full path to the documents, so that it remains easy to verify and quick to load (it would be possible to make asynchronous request to the webservice to build the path asynchronously from the js, but this is inefficient and error-prone).

The javascript replaces “http://www.example.com by the local file:// location, using the value found in the stsr_documents field. By the way, there should be a straightforward way to do it, js gods please comment 🙂

Insert this simple HTML page into the form :

html-webres-reg

Publish…

If you run into any cache problem, or if you need to debug your javascript, you may use F12 on internet explorer.

debug

Ok, that’s all : please comment if you have any improvement ideas. Thank you.

18 thoughts on “Open local file/folders in Dynamics CRM 2013

  1. When I try to run through your tutorial I end up with a box that has the JS script in it. How do you like the icon to this? And how do you define exactly where the location is for the item?

    Thanks!

    1. Dear Meghan,

      Tank you for your comment, and sorry for the late reply : there was a lot of spam in the comments, I missed your post.

      You end up with a box containing the JS : when you edit the content of the web resource, make sure that you write the HTML in the “source” tab, not in the “rich text” tab.

      Source tab

      To add the icon, I used the “img” tag in the link : see the HTML code in the post.

      The location is in fact the uri you would write in explorer to find your file or folder. Example : \\my-server\my-share\my-file.docx

      Don’t hesitate if you need more information.

  2. Hi Raphael,
    Thanks for this great help, i still have probs though pointing to a local folder. Following your example, it add´s the Ip of the CRM Server destroying the link.

    Could you give another example?

    Is it possible to use more than one field in linkval?
    If so, could you make an example

    1. Dear Morty,

      Sorry for the late reply : did you find a solution in the meantime?
      If not : what is your CRM version, and could you share the code that creates the URL, as well as the resulting URL?

      Thank you, have a nice day.

  3. Hi Raphael,

    I have copied your instruction word for word, but it seems it will not redirect and is coming up with an error.
    SEC7134: Resource ‘file://********/Company/Account%20Managers’ not allowed to load.
    I’m a little bit lost and uncertain what to do.

    Many thanks
    Ollie

    1. Hi Ollie,

      A few ideas to find the cause of the issue :

      1. Could you just copy your file://xxx link in an explorer windows (the file browser, not IE), and check that you have access?
      If it works, we can exclude a firewall problem.

      2. If it is not a firewall issue, is it a browser issue? => Did you try with Internet Explorer? This method is not supported by Chrome without an external plugin.

      You may find this post useful : https://stackoverflow.com/questions/34901523/file-url-not-allowed-to-load-local-resource-in-the-internet-browser

      If this is an option for you, you could use WebDAV. A solution with WebDAV would be far more compliant with web standards.

      Have a nice day.

  4. Hi Raphael,

    Thanks for such a quick response;

    1, I can copy the location into the browser and it relocates to the file explorer normally.

    2, I use Edge as standard but I have tried Internet Explorer and Chrome to no avail.

    I’ve had a look through that link but I’m uncertain as to where I’m going wrong.

    Any advice would be appreciated.

    Many thanks
    Ollie

    1. Hi Ollie,

      Could you post a print-screen of the link that appears when you “hover” with the mouse cursor on top of the link created by the CRM page?

      Thank you

  5. Hello Raphael,

    I am using Dynamics 365, and I implemented this approach.
    1. I fill a line of text field with the local path.
    2. I create a web resource which generates html link.
    3. I use javascript to catch the local path and modify the href of the html link to point to the local path.

    My issue is that this approach only works correctly in google chrome using localLinks extension, but it does not work on IE 11 (I am using windows 10), and I did not try any other browsers, but I would like to make it work on as much browsers as possible.

    Thank you very much!

    1. Hello Jorge,

      We use this code and the link in Internet explorer 10 and 11 on Windows 7, 8 and 10 every day, for 150+ users.
      I re-tested now on my computer with IE version 11.608…, update version 11.0.46, Windows 10 Pro Version 1703 : it works fine.
      Maybe something on your security settings?
      I’m still not convinced about this “file://” approach, I hope we will find a better solution soon 🙂

      Have a nice day,

  6. I have tried to get this working and everything looks fine – but clicking the link does nothing. The tooltip looks correct too. I’m using CRM Online.
    I tested on IE/Chrome on my work laptop and a vanilla Azure VM with the same results
    On Chrome F12 debugging shows an error : Not allowed to load local resource: file://SERVERPATH
    After searching online this appears to be a common issue with newest versions of browsers. Does this still work for you?

    1. Hi Harj,

      Please see my comment from 2017/11/14 at 9:41 am : nothing has changed in the meantime. Still working fine on latest, but still not the best solution…
      If you find another way to make it work with a supported protocol, please let us know!

      Have a nice day,

  7. I have tried the same .but its not working for me.
    Web resource code is here:


    click here

    var a = document.getElementById(‘doclink’);
    a.href = “file://DESKTOP-BE9Q40V/Sharefolder”;

  8. Copied code and updated where necessary (field name and .png name). Tested in latest version Chrome, IE, Edge, and Firefox and works in none of them. Chrome just says “NOt allowed to access local resources” and the other browsers don’t do anything at all. You can type the URI that is created (hover over the folder icon to get the URI) into each of the browsers and it will bring up the directory. Reading up on it, all modern web browsers block local resources from being loaded on click. It would seem this method is depricated.

    1. Hi Ishraqiyun,

      I would reply the same as I replied to Rskadk : this post is becoming old… please evaluate “cleaner” solutions like Sharepoint integration (since OneDrive works much better now) or Azure Blob storage.

      I will update the article to reflect that.

      Thank you.

  9. Im using internet explorer 11. I got it working half way.
    It’s almost working. When i place my mouse curser on the icon I can see the path is file:///C:/ (The C:/ is matching what I wrote into the path field)
    But nothing is happening if I click on the icon.
    If I paste the link into internet explorer tab and hit enter it will open windows explorer.

    What can be wrong?

    1. Hi rskadk,

      Honestly, this post is very old… Altough I know some people still use this hack.
      I would advise that you have a look at two alternative solutions : Sharepoint document management integration with Dynamics and Azure Blob storage.
      Here are links to nice articles regarding those solutions. I will update the article accordingly.
      https://d365blogger.com/2017/07/17/dynamics-365-attachment-management-with-azure-blob-storage/
      https://docs.microsoft.com/en-us/dynamics365/customer-engagement/admin/set-up-dynamics-365-online-to-use-sharepoint-online

      Have a nice day!

Comments are closed.

2015 © Zealots. All rights reserved. Zealots Sàrl, Léman 21, 1005 Lausanne, +4179 856 33 31