Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Opening pdf and tif using javascript function in ASP.net 3.5

Posted on 2009-04-02
2
Medium Priority
?
524 Views
Last Modified: 2012-05-06
Hi,

I am trying to write code that will open images with pdf and tif extensions.  The idea is for the code to look for a tif file with the name.  If it doesn't find it then it should look for a pdf.  If both are present it should open them both.  I can get the tif and pdf codes to work separately but not together.  Any assistance you all could provide would be great!

Thanks
<script type="text/javascript">
function notEmpty(){
	var myTextField = document.getElementById('TextBox1');
	if(myTextField.value != "") {
		var path = "\\\\server1.com\\users\\CkImgs\\" + myTextField.value + ".tif";
		window.open(path,'mywindow2')
//		var path = "\\\\server1.com\\users\\CkImgs\\" + myTextField.value + ".jpg";
//		window.open(path,'mywindow')
	}	
	
}
</script>

Open in new window

0
Comment
Question by:Blessed7777
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 29

Accepted Solution

by:
David H.H.Lee earned 1000 total points
ID: 24057609
Hi Blessed7777,
One of the attempt is using xmlhttp object to verify the file existence based on specified file location.
http://www.w3schools.com/XML/xml_http.asp

Here is attempt



<script type="text/javascript">
var blnFound=false;//check the file existance
 
function notEmpty(){
 
        var myTextField = document.getElementById('TextBox1');
        if(myTextField.value != "") {
		
                var path = "\\\\server1.com\\users\\CkImgs\\" + myTextField.value + ".tif";
                CallFile(path);
		
		if(blnFound==false){
        		path = "\\\\server1.com\\users\\CkImgs\\" + myTextField.value + ".pdf";
			CallFile(path);
		}
	}       
        
}
 
function CallFile(strLocation){
 
//inital xmlhttp
var xmlhttp=false;
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
 
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
 
 xmlhttp.open("GET", strLocation,true);
 
 xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4) {
     if (xmlhttp.status==200)  {
       blnFound=true;
       window.open(strLocation,'mywindow2')//open your document here
     }else if (xmlhttp.status==404) {blnFound=false;//file not exist}
   }
 }
 xmlhttp.send(null)
 
}
</script>
<input type=text id="TextBox1" value="testFile"/>
<script>
notEmpty();
</script>

Open in new window

0
 

Author Closing Comment

by:Blessed7777
ID: 31565988
Thanks x com that did the trick :)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question