Open Sharepoint folder with windows explorer from CRM 2011 - javascript

I've been struggling with this issue for a while now,
and hope maybe someone in the community can provide a resolution.
I have a requirement which is to put a button on the a CRM account form which will have the same logic as the Open With Explorer button in a Sharepoint document library. The logic is required as the users have to do several click in order to get to this button, and open the required account's folder in windows explorer, which are:
Click Documents in navigation of the form, to open SP integration
Click documents in the SP view
Click library
Click the Open With Explorer button
The CRM is integrated with Sharepoint, and when the folder is opened in windows explorer it has the following sample link
http://{sharepoint}/CRM/7F9F72A1-4591-E011-AC6C-00155D773703/Documents/
Where the GUID 7F9F72A1-4591-E011-AC6C-00155D773703, is the account id in CRM.
From my research i have found that the javascript function that achieves this is
NavigateHttpFolder from the sp.js in Sharepoint.
From this function, and this link About Web Folder Behaviors
I've completed the following function.
var httpFolderDiv = document.createElement("SPAN");
function NavigateToFolder() {
document.body.appendChild(httpFolderDiv);
httpFolderDiv.onreadystatechange = NavigateToFolder;
httpFolderDiv.id = "navDiv";
httpFolderDiv.addBehavior("#default#httpFolder");
if (httpFolderDiv.readyState == "complete") {
httpFolderDiv.onreadystatechange = null;
var link = "";
var account = "";
var accountid = "";
var id = Xrm.Page.data.entity.getId().replace("{", "").replace("}", "");
link = "http://{sharepoint}/CRM/" + id + "/Documents/";
try {
httpFolderDiv.navigateFrame(link, "_blank");
} catch (c) {
alert(c.toString());
}
}
}
This function opens up the folder from Sharepoint in windows explorer, but with limitation if only that folder was previously opened directly from Sharepoint.
I believe that the logic I am missing in the code, is that I don't do mapping of the folder, the way sharepoint does.
I am aware that this folder can be mapped manually as a network drive, Connecting WebDAV Server Using Web folders, but this will not do the trick for me as this will have to be done on every client.
How can I achieve this by grabbing the complete logic from SP, or maybe running a console command from javascript to map the folder prior to opening it with the above function.

I know it's been a while, since this has been posted, but I stumbled upon it while searching for the exact same problem.
Here's what worked for me in SharePoint 2013:
<a href='#' onClick="javascript:CoreInvoke('NavigateHttpFolder', '[path to site]/[library name]/', '_blank');">
Click to open in Explorer
</a>
It's essentially the same function used by SharePoints own functionality.

Related

Javascript works in Adobe Reader but not in Nitropdf

I have setup an interactive PDF form with a Javascript button to submit the form by email, extracting data input by the user. The button works fine in Adobe Reader but does nothing in NitroPDF. Is there a problem with the code (see below)?
var cToAddr = this.getField("ComboBox1").value
var cSubLine = "Property Transaction Form " + this.getField("Text1").value
var cBody = "The attached file is the filled-out form. Please open it to review the data."
this.mailDoc({bUI: true, cTo: cToAddr, cSubject: cSubLine, cMsg: cBody})
With the plethora of PDF viewers out there that implement only some of the Acrobat JavaScript API - some more, some less - I recommend testing for the existence of any functions that your document requires before trying to use them. Wrap your code in the snippet below to let the user know that they are using a less capable viewer than what you've programmed the document for.
if (typeof this.mailDoc == 'function') {
// The viewer can mail documents
}
else {
// Warn the user somehow
}

activex outlook bring to front

How to bring the outlook application in front which is opened from JavaScript using ActiveX.The following is the code in which I need to bring outlook window on the top (i.e. bring to front), because it is opening behind the I.E. browser.
// Open outlook e-mail client application with the corresponding subject and the attachment link
function openOutlook(emailSubject, emailAttach) {
try {
var app = new ActiveXObject('Outlook.Application');
var objNS = app.GetNameSpace('MAPI');
var mailItem = app.CreateItem(0);
mailItem.Subject = (emailSubject);
mailItem.to = 'test#test.com';
mailItem.display();
mailItem.Attachments.add(emailAttach);
}
catch (ex) {
alert('Outlook configuration error : ' + ex.message);
}
}
So far, I've tried changing mailItem.display(); to mailItem.display(false); and mailItem.display(true); and open-word-from-javascript-and-bring-to-front but it didn't help and there seems to be a glitch here i.e. when I change the code this way and run the app then outlook window comes on the top, but if I open it in another system or open after restarting the system then it doesn't work, I think maybe windows OS is making it come on the top somehow.
Try to use the Activate method of the Inspector class right after calling the Display() method. It activates an inspector window by bringing it to the foreground and setting keyboard focus.
As of Windows Vista, Windows will not activate a window of an application that is not running in a foreground; it will instead flash the taskbar button.
If you were using C++ or Delphi (or even .Net) you could work around that using AttachThreadInput (see how to make the Outlook Compose window top most?), but you cannot do that from JavaScript.
You can try to use Redemption (I am its author) and its SafeInspector.Activate method, but that means Redemption would need to be installed where you client script runs.
var app = new ActiveXObject('Outlook.Application');
var objNS = app.GetNameSpace('MAPI');
var mailItem = app.CreateItem(0);
mailItem.Subject = "test"
mailItem.to = 'test#test.com';
mailItem.display();
mailItem.Attachments.add(emailAttach);
app.ActiveExplorer.Activate();
var sInspector = new ActiveXObject('Redemption.SafeInspector');
var oInspector = mailItem.GetInspector;
sInspector.Item = oInspector;
sInspector.Activate();

Browser Link and Web Forms (Design mode doesn't work for ASP.NET Web Forms)

I have been playing around with the new Browser Link feature in visual studio 2013. However, I am not able to get the "Design Mode" feature working for "Web Form" pages. It works fine when I am browsing a MVC page. However, as soon as I add a web form to the project, it get an alert in my browser saying that
"Design mode doesn't work for ASP.NET Web Forms".
I can also inspect and refresh the page (from the Browser Link Dashboard).
I tried to debug the JavaScript code injected into the browser to see where it's happening. If you turn your F12 developer on, and search for "Design Mode", you will see it in a js file (the path looks like "/foo/browserlink").
map = browserLink.sourceMapping.getCompleteRange(target);
if (map && map.sourcePath) {
if (isValidFile(map.sourcePath.toLowerCase())) {
current = target;
$(target).addClass(selectedClass);
browserLink.sourceMapping.selectCompleteRange(current);
}
else {
enableDesignMode(false);
alert("Design Mode doesn't work for ASP.NET Web Forms");
}
}
and then the "isValidFile" has the following body
function isValidFile(sourcePath) {
var exts = [".master", ".aspx", ".ascx"];
var index = sourcePath.lastIndexOf(".");
var extension = sourcePath.substring(index);
for (var i = 0; i < exts.length; i++) {
if (exts[i] === extension)
return false;
}
return true;
}
How can I get this working for my Web forms application?
So the injected javascript is actively looking for web-form based pages (aspx, ascx, master) and firing the alert accordingly. I guess it means exactly what it says!
I couldn't find any additional documentation on this so I tweeted Mads Kvist Kristensen (Web Tools team) for clarification. Not sure if this will be added at a later date? Looks like an awesome feature would love to use it in my web forms app?

Search for injected script code on the Windows Server for my ASP.NET site

My site was probably hacked. I am finding script.js from bigcatsolutions.com in my page. It triggers a popup of an affiliate program. The script isn't on the page by default and I want to know how can I find where it was injected. The script sometimes injects other ad sites.
In chrome I see this:
The injected script code:
function addEvent(obj, eventName, func) {
if (obj.attachEvent) {
obj.attachEvent("on" + eventName, func);
} else if (obj.addEventListener) {
obj.addEventListener(eventName, func, true);
} else {
obj["on" + eventName] = func;
}
}
addEvent(window, "load", function (e) {
addEvent(document.body, "click", function (e) {
if (document.cookie.indexOf("booknow") == -1) {
params = 'width=800';
params += ', height=600';
params += ', top=50, left=50,scrollbars=yes';
var w = window.open("http://booknowhalong.com/discount-news", 'window', params).blur();
document.cookie = "booknow";
window.focus();
}
});
})
My site is moved from my hosting company to Amazon EC2 Windows 2013 Server and still have the issues, so it means that the code still resides on the server somewhere. My site was build using ASP.ENT / C#.
Things I did:
tried to search the original aspx and aspx.cs code files
Have you checked the IIS logs to see if they are hitting a specific page and injecting it there?
Do you load any data from a database? You could check in the tables and see if anything out of the ordinary appears there.
It is unlikely that the .aspx pages have actually been physically modified and even more unlikely that the DLL have been as .aspx.cs files are compiled in to your BIN folder as DLL's. The more likely scenario is that you have an unsecure page that a malicious site is injecting its script into. The other possible attack vector is that you have had malicious code via SQL injection and are loading it each time.
After deep searching and I missed it in the first run, I found that the script was injected into the ASP.NET masterpage.
I ran a search to search for a specific string in all the files and that's how I found it. It seems that the server itself was breached and the hacker put the code into several websites.
So for those of you who have this type of problem, I recommend running a text search and try to find the URL that is tights to the running script.
Hope that helps and thanks for your time.

Checking if user has a certain extension installed

I just found out that the Screen Capture by Google extension makes my website's window.onresize event not fire.
I want to perform a javascript check to see if the user has ScreenCapture installed and if so, warn the user of the problem.
A year ago I think I heard of some javascript code that could do this, maybe using some google API, but I don't remember.
Any insight on this? I haven't developed any extensions so I don't really know how they work.
[EDIT]
So I have been asked to show some code. As seen in my previous question ( window.onresize not firing in Chrome but firing in Chrome Incognito ), the problem occurs on any window.onresize event function, so I don't think my code really matters.
Also, there is quite a lot of my code, I don't know how much of it to paste or if it would be helpful.
var debounce = function (func, threshold, execAsap)
{
var timeout;
return function debounced () {//alert("1.1 Y U NO WORK?");
var obj = this, args = arguments;
function delayed () {
if (!execAsap)
func.apply(obj, args);
timeout = null;
}
if (timeout)
clearTimeout(timeout);
else if (execAsap)
func.apply(obj, args);
timeout = setTimeout(delayed, threshold || 100);
};
};
window.onresize = debounce(function (e) { //alert("1.2 Y U NO WORK?");
flag = true;
var point = window.center({width:1,height:1});
doCenter(point);
// does something here, but only once after mouse cursor stops
}, 100, false);
I would like to stress that the problem is not due to the debounce. window.onresize = t; function t (e) { alert("wtf?");} won't work either.
[EDIT2]
Here's the result:
var screenCapture = null;
var screenCaptureImg = document.createElement("img");
screenCaptureImg.setAttribute("src", "chrome-extension://cpngackimfmofbokmjmljamhdncknpmg/images/arrow.png");
/*
* Add event listeners for both "load"- and "error"-event
* Set the variable showing the existence of the extension by
* setting it to "true" or "false" according to the fired event
*/
screenCaptureImg.addEventListener("load", doLoad, false);
function doLoad(e){
screenCapture = true; //removeImgTag(e);
alert("I've so cleverly detected that your Chrome has the ScreenCapture extension enabled. \n\nThis extension interferes with my website's DOM and long story short, it won't be able to scale properly.\n\nSo please disable it. \nConsider this extension: \"Disable All Extensions Plus\", it's a handy selective disabler.");
}
screenCaptureImg.addEventListener("error", function(e){
screenCapture = false; //removeImgTag(e);
}, false);
/*
function removeImgTag(e) {
e.currentTarget.parentNode.removeChild(e.currentTarget);
}
*/
Note that I couldn't get removeImgTag to work, because (at least in chrome), I don't seem to have access to the document object in order to create or remove elements from my page, from within these event functions. This is also why I'm displaying an alert instead of elegantly writing up a document.getElementById("something").innerHTML=...
To detect if an extension is installed in Chrome, you can check for a known resource included in the extension such as an image. Resources for the extension are referenced using the following URL pattern:
chrome-extension://<extensionID>/<pathToFile>
The basic detection technique involves creating a hidden image tag and attaching load and error events to it to see if the image loads (as described here for Firefox):
extensionImg.setAttribute("src", "chrome-extension://<INSERT EXTENSION ID HERE>/images/someImage.png"); // See below for discussion of how to find this
/*
* Add event listeners for both "load"- and "error"-event
* Set the variable showing the existence of the extension by
* setting it to "true" or "false" according to the fired event
*/
extensionImg.addEventListener("load", function(e) {
extensionExists = true;
removeImgTag(e);
}, false);
extensionImg.addEventListener("error", function(e) {
extensionExists = false;
removeImgTag(e);
}, false);
function removeImgTag(e) {
e.currentTarget.parentNode.removeChild(e.currentTarget);
}
Check the installation directory of the extension in the Chrome configuration to find a likely target for detection. On my Linux workstation extensions are located in:
~/.config/chromium/Default/Extensions
You can see that I have 3 extensions installed right now:
~/.config/chromium/Default/Extensions$ ls
cpecbmjeidppdiampimghndkikcmoadk nmpeeekfhbmikbdhlpjbfmnpgcbeggic
cpngackimfmofbokmjmljamhdncknpmg
The odd looking names are the unique IDs given to the extension when it is uploaded to the Chrome webstore. You can obtain the ID either from the webstore or by going to the Extensions tab (wrench -> Extensions) and hovering over the link to the extension in question, or "Screen Capture (by Google)" in this case (note the asterisked extension ID):
https://chrome.google.com/webstore/detail/**cpngackimfmofbokmjmljamhdncknpmg**
In the extension directory there will be one or more versions; you can ignore this. Within the version directory is the actual content of the extension:
~/.config/chromium/Default/Extensions/cpngackimfmofbokmjmljamhdncknpmg/5.0.3_0$ ls
account.js images page.js sina_microblog.js
ajax.js isLoad.js picasa.js site.js
background.html _locales plugin style.css
editor.js manifest.json popup.html ui.js
facebook.js notification.html sha1.js upload_ui.js
hotkey_storage.js oauth.js shortcut.js
hub.html options.html showimage.css
i18n_styles page_context.js showimage.html
In the case of the Screen Capture extension there are a number of images to use:
~/.config/chromium/Default/Extensions/cpngackimfmofbokmjmljamhdncknpmg/5.0.3_0/images$ ls
arrow.png icon_128.png icon_save.png print.png
copy.png icon_16.png line.png region.png
cross.png icon_19.png loading.gif screen.png
custom.png icon_32.png loading_icon.gif sina_icon.png
delete_account_icon.png icon_48.png mark.png toolbar_bg.png
down_arrow.png icon_close.png picasa_icon.png upload.png
facebook_icon.png icon_copy.png popup_bg.jpg whole.png
These can be referenced under this URL:
chrome-extension://cpngackimfmofbokmjmljamhdncknpmg/images/arrow.png
This technique obviously depends on the stability of the content of the extension. I recommend using an image that looks likely to remain through all versions.
As mentioned above, the same technique can be used to detect Firefox extensions. In this case the content URL looks like this:
chrome://<EXTENSION NAME>/content/<PATH TO RESOURCE>
On my Linux workstation Firefox extensions are located in:
~/.mozilla/firefox/<USER PROFILE ID>/extensions
Where <USER PROFILE ID> looks something like this: "h4aqaewq.default"
You can see that I have 2 extensions installed right now, one of which is a directory installation and the other of which is a XPI (pronounced "zippy") file:
~/.mozilla/firefox/h4aqaewq.default/extensions$ ls
{3e9a3920-1b27-11da-8cd6-0800200c9a66} staged
firebug#software.joehewitt.com.xpi
The "staged" directory is where Firefox keeps extensions that will be updated (I think). The GUID directory with the brackets is a directory-based extension installation, and the .xpi file is Firebug.
Note: XPI is going away (see the link above). It's basically a zip file that can be opened and inspected by anything that understands zip. I used Emacs.
Finding the extension ID in Firefox is a bit more involved. Go to "Tools -> Add-ons", click the Extensions tab, click the "More" link next to the extension description, then click the "reviews" link to go to the Firefox extension site and get the ID from the URL (note the asterisked extension ID):
https://addons.mozilla.org/en-US/firefox/addon/**firebug**/reviews/?src=api
There's probably an easier way to do this; suggestions welcome.
TODO: how to find a likely image in a Firefox extension.
As an extra note, in Chrome you can only communicate with an extension via the shared DOM of the page: Host page communication

Categories

Resources