Click here to Skip to main content
15,905,913 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I got Network error to check if a file exists using the piece of code (sourced from )[^]below:
function UrlExists(url) {   // where url = 'http://xxxxx/fileName.png'  
    var http = new XMLHttpRequest();
    http.open('HEAD', url, false);
    http.send();
    return http.status != 404;
}

How to debug this Network error?
I also tried an alternative approach as shown below:
JavaScript
var fso = new ActiveXObject("Scripting.FileSystemObject");
fileBool = fso.FileExists("\\myNetworkFolder\myFile.png");

But the objective can' be created even though I use IE as the browser. How can the ActiveXObject be used?
Thanks if you can help.

What I have tried:

Got Network error to check if a file exists
Posted
Updated 29-Apr-16 2:27am
v3
Comments
ZurdoDev 28-Apr-16 16:21pm    
1. What is the exact error?
2. No, ActiveX only runs in IE.
Sergey Alexandrovich Kryukov 28-Apr-16 20:22pm    
This "alternative approach" with ActiveX is enough reason for a security-savvy users to black-list such site or Web application. :-)
—SA

1 solution

This name, "\\myNetworkFolder\myFile.png", is not generally accessible from the Web application. This is the UNC path name which might be accessible, in particular, through the Windows sharing service executed by other hosts of the same LAN:
Path (computing) — Wikipedia, the free encyclopedia[^].

But the server-side code is executed in the sandboxed environment which only allows access to the file system objects under the root directory set up for your site. This is done for serious security reasons.

If you really want to store images on a separate hosts, there are some (potentially heavier) alternatives. First of all, please see:
Connecting Web Sites to UNC Network Shares[^].

Also, you can serve-up those images on another host through as standard FTP server or another HTTP server. The you can access the data by your Web application's server-side code:
FtpWebRequest Class (System.Net)[^],
HttpWebRequest Class (System.Net)[^],
WebRequest Class (System.Net)[^].

But first of all, I would think about moving all these images to the location of your Web site. Why not keeping it simple?

—SA
 
Share this answer
 
Comments
s yu 29-Apr-16 10:43am    
SA: Thanks for your solution. I did work per your advisory - published the files in the shared folder in a website. Its url looks like 'http://xxxxx/fileName.png' and the image displays well if it is put on the browser directly. As stated in my post, I got network error (XMLHttpRequest: Network Error 0x80070005, Access is denied) on the line: http.send(); and the http.status is always 0. I will check my server. Thanks again.
Sergey Alexandrovich Kryukov 29-Apr-16 11:43am    
That's great. To check in the access problem, just check the file system permission on the file in question and all its parent directories. Make sure the file is acceptable as read-only to everyone.
Will you accept my solution formally then?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900