Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is this possible in ASP?? 3

Status
Not open for further replies.

jdnewton

Technical User
Jan 17, 2003
17
GB
Hi all,

I have an ASP front end database program running from my hard drive in XP Pro which I use to catalogue references.

Due to the tedious process of entering new data, I wonder if it is possible to automate some of the processes.

1) Can I fire up adobe reader automatically when I open my reference web page?

2) Can I open a pre-specified file name in adobe automatically after completion of a form post event - i.e. to load up the next (they are in numerical order already) file when the previous one is finished with?

At present I open both adobe and explorer together - woudl be nice if one triggered the other. After reviewing the pdf and entering data into the web page form I then have to manually locate and load the next pdf into adobe and repeat.

Is any of this feasible (and is it an ASP issue? Javascript?)

Thanks,

JDN
 
not sure if i understand your question completely...but yes you can open a specified file in adobe...

can you elaborate your task?

-DNG
 
The adobe reader is normally a browser-side program rather than a server-side thing. The web server sends a PDF file to the browser and, if you have the adobe reader in the default configuration, the browser will use adobe reader as a plug-in to display the file in the browser window.
 
Sorry, perhaps should have explained better.

The current routine is as follows:

I open my reference database ASP front end web page and then choose to add a new reference (which is a link to another ASP file, a form to enter data to the database).

I then have to open Adobe reader, and locate the next file in order. After reading this I populate the form with relevant data and hit enter.

After passing the data to a blind ASP page to populate the databse it returns me to the start when the process repeats itself.

However the next pdf file is known, and I wonder if I could automatically open the next file in adobe on closure of the asp form file. I guess the same technique could be used to fire adobe with the relevant file when I click the add new reference link at the start.

Does that make it more clear?
 
Does that make it more clear?

no.

A few thoughts jump to mind when reading your posts:
What are you doing with these PDF's -? Why do you open them ? What information is in the pdf that you want to enter into the database ? Why not automate the entire task ? What is the reference too ? Is it a file reference ? A Page Reference ? Why are you adding a reference that links to an ASP page/form ? Do you change these regularly, or create new ones that need to be re-linked ? How do you determine the next file in order ? etc....

All I can glean from your posts is:
1. You have a database with an ASP page
2. You enter links to other asp pages/forms from that page (who knows why..)
3. You then goto said page and enter information from a PDF - what information and why ?
4. This then gets posted to the (same?) database
5. You then rinse and wash,...

And what you're asking is how can it open up the pdf ready for you to enter your information..? right ?

How would we know which pdf to open ? where is the pdf located ? locally or at the server ?

If this is a data entry task, why not automate the upload of the content from the PDF into the database ? - i.e. convert PDF to XML, then parse the XML and post to the database - then you can just send all your files to the server, and press go..

A smile is worth a thousand kind words. So smile, it's easy! :)
 
If the PDF files are located on the same machine as the web page (it sounds like both on your local machine in this case) then yes, you could.

The first thing you would use is the FileSystemObject. This object has methods for getting the contents of a folder as a collection of files. Provided you only have "to review" items in a folder, you could use the FileSystemObject to create a list of the files in the folder and, when your review process is done, move the reviewed PDF to another folder.

The next thing is simply a trick. When you open a link to a PDF in a browser, it automatically tries to open adobe reader to read the document. The only problem is that you don't want it to open the link in your current browser, or you won't be able to enter data in your form. If your only going to use this on your local machine you can use a reference to the full path of the file on your harddrive (C:\yourFolder\yourfile.pdf), if your ever going to use this remotely then you would want to place your "to be reviewed" pdf's in a folder in the web folder.

To solve the need for two windows and the need to easily get to your entry form, you could have a simple index page tat lists all the PDF files in the given folder as links. As long as you place the attribute target="_blank" in your anchor tags, the link will be opened in a new window. You could additionally use a small piece of javascript to direct the current page to the form page, or you could have that as a secondary link on the page.

Example:
Code:
<%
Option Explicit

'create the links
Dim fso, fol, fil
Set fso = Server.CreateObject("Scripting.FileSystemObject")
'if the folder is on your machine and no one else needs to access it
Set fol = fso.GetFolder("C:\YourPath\YourFolder")
'if the folder is in your web path
'Set fol = fso.GetFolder(Server.MapPath("/virtualPath/ToYourFolder"))

For Each fil in fol.Files
   Response.Write "<a href=""file://" & fil.Path & """ target=""_blank"">" & fil.Name & "</a><br/>"
Next

<a href=""formPageLink.asp"">Open Form</a>

'cleanup
Set fil = Nothing
Set fol = Nothing
Set fso = Nothing
%>

The missing piece would be a piece of code you would add after your form submits. Once the form has submitted then you want to add some code that moves the file you just entered info on to a "completed" folder so it will no longer show up in the listing. To do this you would need to pass the name of the file to your form, then modify your form to pass the name of the file to the final page. The easiest way to handle this would be to go back and add the javascript routine I mentioned so we can append the filename to the querystring of the form page:
Code:
<%
Option Explicit

'create the links
Dim fso, fol, fil
Set fso = Server.CreateObject("Scripting.FileSystemObject")
'if the folder is on your machine and no one else needs to access it
Set fol = fso.GetFolder("C:\YourPath\YourFolder")
'if the folder is in your web path
'Set fol = fso.GetFolder(Server.MapPath("/virtualPath/ToYourFolder"))

%>
<html>
<head>
<script language="javascript">
function changePage(fileName){
   window.location = "formPagename.asp?filename=" + fileName;
}
</script>
</head>
<body>
<%

For Each fil in fol.Files
   Response.Write "<a href=""file://" & fil.Path & """ target=""_blank"" [highlight]onClick="changePage('<%=fil.Name%>')"[/highlight]>" & fil.Name & "</a><br/>"
Next

'cleanup
Set fil = Nothing
Set fol = Nothing
Set fso = Nothing
%>
</body>
</html>

Once we have the name of the page in the querystring, you would need to add it to your form as either a hidden input or a querystring value on the form action. Then in your final page you will have the name of the file to move. In the final page you would use the FileSystemObject and Move method to move the file. To keep things easy, you would probably want to do a Response.Redirect back to the index page above after it has finished processing.

Please let me know if you need any more detail or need any additional informaiton. I believe this was basically wat you were looking for, but if not, or if anything was confusing, I apologize.

-T

 

Sorry for the confusion and thanks for your help so far.

In answer to these questions:

A few thoughts jump to mind when reading your posts:
What are you doing with these PDF's -? Why do you open them ? What information is in the pdf that you want to enter into the database ? Why not automate the entire task ? What is the reference too ? Is it a file reference ? A Page Reference ? Why are you adding a reference that links to an ASP page/form ? Do you change these regularly, or create new ones that need to be re-linked ? How do you determine the next file in order ? etc....

All I can glean from your posts is:
1. You have a database with an ASP page
2. You enter links to other asp pages/forms from that page (who knows why..)
3. You then goto said page and enter information from a PDF - what information and why ?
4. This then gets posted to the (same?) database
5. You then rinse and wash,...

And what you're asking is how can it open up the pdf ready for you to enter your information..? right ?

How would we know which pdf to open ? where is the pdf located ? locally or at the server ?

If this is a data entry task, why not automate the upload of the content from the PDF into the database ? - i.e. convert PDF to XML, then parse the XML and post to the database - then you can just send all your files to the server, and press go..

It is essentially a catalogue. I have over 4000 pdfs which are medical literature I have collected relevant to my research and job.

The database is a catalogue of these - it contains the reference details (journal, year, volume etc.) and categorisation of the reference along with keywords and a comment. This allows easy retrieval and grouping of references. This could not be automated.

The database is managed by 6 ASP pages, it all runs off a local server and the PDFs are on the same hard drive (separate partition though). When a PDF is downloaded and stored I assign it a number hence they are all in numerical sequence. When I have downloaded a few I then enter them all into the database.

One page is a simple form to populate with the information and my comments on the PDF. Adobe is open with the relevant PDF at this point. Once this form is posted I then open up the next PDF and repeat until all are entered. The PDFs remain where they are.

The slowest step is entering the info - can't do much about that - and the next slowest is opening up the next PDF in adobe. At present I just type in the next number to call it up.

Thus my query over automation is:

Can I ask Adobe to open with a certain PDF from within an ASP page?

This would help in two situations:

The front ASP page contains links to the other pages (add, edit, search, list etc.). When I click add it would be nice if adobe opened the next PDF in a separate window to the ASP page with the form. The number of the PDF is easy to retrieve and in fact is already available as the front page contains a count of the current total number polled from the database on first opening.

When the form has been posted I would then like adobe to open the next PDF - again easily derived, and close the previous file.

So, can I call an instance of Adobe Reader from within ASP and specify the file to open?

A lesser solution may be to pass the name of then next PDF to the clipboard so it can be pasted into the Adobe file open dialgoue manually to save typing the name in manually.


If the PDF files are located on the same machine as the web page (it sounds like both on your local machine in this case) then yes, you could.

The first thing you would use is the FileSystemObject. This object has methods for getting the contents of a folder as a collection of files. Provided you only have "to review" items in a folder, you could use the FileSystemObject to create a list of the files in the folder and, when your review process is done, move the reviewed PDF to another folder.

The next thing is simply a trick. When you open a link to a PDF in a browser, it automatically tries to open adobe reader to read the document. The only problem is that you don't want it to open the link in your current browser, or you won't be able to enter data in your form. If your only going to use this on your local machine you can use a reference to the full path of the file on your harddrive (C:\yourFolder\yourfile.pdf), if your ever going to use this remotely then you would want to place your "to be reviewed" pdf's in a folder in the web folder.

To solve the need for two windows and the need to easily get to your entry form, you could have a simple index page tat lists all the PDF files in the given folder as links. As long as you place the attribute target="_blank" in your anchor tags, the link will be opened in a new window. You could additionally use a small piece of javascript to direct the current page to the form page, or you could have that as a secondary link on the page.

Tarwn - That is a neat workaround but as my PDFs are already named in numerical sequence it would not really be neccessary to populate a file list.


I hope that lengthy explanation explains my question...
 
That makes more sense.

OK, so the PDF's have random content, that you want to manually archive against some metadata in a database. And these pdfs are downloaded by you to your desktop and then from your desktop, the ASP Pages run and provide a list of the pdfs in a specific directory ? right ?

Then, as Tarwn states above, you can serve the PDF's from the ASP pages with a specific content type that your machine will recognise as PDF, and use the PDF reader inside a new browser window.

You could even (shock) use frames .. with 1 left panel and 2 right panels split horizontally. This will enable you to have a file list on the left, an entry form on the top right and the pdf in the bottom right.

Or some combination of the two.

So,
1. Write a page that shows the links of the files
2. Write a page that sends PDF content correctly to the browser
3. Write a form that accepts your input and posts to the db

Tarwn has already described mostly how to do the above, so I think we need to know whether that is the way you want it to work or not ?

If not, what exactly do you want ?

The only other thing I can think of is for a page to use javascript to open a window with the local file:// url of the pdf.. similar effect.

Hope that helps,

A smile is worth a thousand kind words. So smile, it's easy! :)
 
The only other thing I can think of is for a page to use javascript to open a window with the local file:// url of the pdf.. similar effect.

Hope that helps,

Anyone have a smilie for the 'smaking the palm of you hand against your forehead' manoevure?

If I had perhaps been clearer to start with...

Anyway, a simple JS window.open function called from the add new reference page does just the job.

Why oh why did I not think of that?

Cheers all.
 
Tarwn,

I really like the idea of moving the relevant file automatically once the entry is completed.

At present once the form is completed the data is passed to another ASP (add.asp) page to transfer to the database before then returning to the form with the next PDF opened - that works a treat.

I could easily call a function from the 'add.asp' page to move the relevant PDF to a different folder. The name of the PDF has already been passed across on the form.

Would I need to close the Explorer window containing the PDF before I can move?

I bunged this into the end of the add.asp file as a test (and created the test .txt file) but it does not seem to do anything. What have I done wrong?

Code:
.....

<script language="javascript">
' Move File

Option Explicit

Function Main()

	Dim oFSO
	Dim sSourceFile
	Dim sDestinationFile

	Set oFSO = Server.CreateObject("Scripting.FileSystemObject")

	sSourceFile = "C:\SourceFile.txt"
	sDestinationFile = "C:\temp\SourceFile.txt"

	oFSO.MoveFile sSourceFile, sDestinationFile

	' Clean Up
	Set oFSO = Nothing

	Main = DTSTaskExecResult_Success

End Function

</script>

<%
Response.Redirect "main.asp"
%>

</body>
</html>
 
You shouldn't need to move the explorer window first if your folder is in the webpath and you access the file with http:// because your viewing a temporary copy of the file that your browser downloaded to it's temporary cache folder. However, the same may not be true when using a file:// URI. One quick way to test that would be to open up a browser, put in the URL as file:// with the direct path, and then manually try to move the file. I don't know what the rules are for moving the file because your not only dealing with MS's odd choices of locking, but also whatever type of locking the application that has it open has decided upon. If you can move the file manually, though, you should be ok to move it from a script.

As far as your code is concerned: You have defined a function in your page called Main that moves a given file, but you have not actually executed that function anywhere. Also, the code you have posted between those script tags is neither client-side code or javascript. A cleaned up version of what you have would look like:
Code:
.....
[highlight]<%[/highlight]
[s]<script language="javascript">[/s] 'unnecessary, this isn't client-side or javascript
' Move File

[s]Option Explicit[/s] 'can only be used once as thefirst line of a file

Function Main([highlight]sSourceFile, sDestinationFile [/highlight])
    'moved two args to function declaration for easier use
    Dim oFSO
    Dim sSourceFile
    Dim sDestinationFile

    Set oFSO = Server.CreateObject("Scripting.FileSystemObject")

    [highlight]'Always pays to be careful[/highlight]
    [highlight]If fso.FileExists(sSourceFile) Then [/highlight]
    [highlight]    Main = False[/highlight]
    [highlight]    Exit Function[/highlight]
    [highlight]End If[/highlight]

    [highlight]'personally I would add a check to make sure we aren't overwriting an existing file, butthatsp to you[/highlight]
    oFSO.MoveFile sSourceFile, sDestinationFile

    ' Clean Up
    Set oFSO = Nothing

    [s]Main = DTSTaskExecResult_Success[/s] 'don't know where this is defined or what it is, so replacing it
    [highlight]Main = True[/highlight]
End Function

[s]</script>[/s] 'unnecessary
[s]<%[/s] 'unnecessary since we are inside an ASP block now

[highlight]'call the function and check it's result[/highlight]
[highlight]If Main("C:\myfolder\myfile.pdf","C:\OtherFolder\MyFile.pdf") = false Then[/highlight]
    [highlight]Response.Write "<html><body>Error, I could not move the file!</body></html>"[/highlight]
[highlight]Else[/highlight]
    Response.Redirect "main.asp"
[highlight]End If[/highlight]
%>

[s]</body>[/s]
[s]</html>[/s]

If you are going to do a response.Redirect, there is no point in outputting HTML tags. If buffering is on (which it is by default) then that content will be deleted and the redirect will be sent to the browser instead. If buffering is not on, then you will get a nasty error message about the HTTP headers already being written.
Basically when you response.Redirect the server sends a "site moved" status down to the browser with the address you have specified. These values are defined in the header and the response is set automatically. No content is sent with the response. If, however, you have turned off buffering or force a flush (Response.Flush) then the HTTP headers were built and sent with a 200 OK code, followed by the content already in the buffer. Since you cannot send more then one set of headers, and cannot send the headers after you send content, you will get an error at any attempted redirect that occurs after output.

-T


 
Tarwn,

Fantastic, thanks for your help.

A bit of modification and it works fine. File moves a dream.

But, it does need closure of the PDF file (open in a browser) or else 'permission is denied'.

Can I force this window closed just before I call the function??

Cheers again.
 
Only from client-side code. If your using javascript to do a window.open, then you can assign the result of this call to a javascript variable, basically a handle to the window. Then when you click the submit button you could have an onClick event that uses that handle to close the window with the PDF, thus closing the file.

 
Tarwn,

Thanks, but erm...

The window open code is as follows:

Code:
Response.Write "<script langauge='javascript'>filewin=window.open ('" & (filetoopen) & "','mywindow');</script>"

I then tried to close this window from the submnit button on the form - which passess the form data to another ASP page to populate the database:

Code:
n="right">&nbsp;</td><td colspan="2"><input tabindex="14" type="submit" value="Add details to database" onClick="filewin.close()"></td>

Unfortunately clicking the submit button completes database entry but the window is not closed and hence 'permission is denied' when I try and move the PDF.

Any advice?
 
Sorry to have left you hanging so long, I was gone from the forums for a few days and had pages of new posts to view and missed yours.

I just tried the following ttest code (based on yours) and it appears to be working:
Code:
<html>
<head>
</head>
<body>
<%
Response.Write "<script langauge='javascript'>filewin=window.open ('[URL unfurl="true"]http://www.google.com/','mywindow');</script>"[/URL]
%>
<form method="POST" action="sample2.asp">
<input tabindex="14" type="submit" value="Add details to database" onClick="filewin.close()">
</form>
</body>
</html>

Are you opening and closing the PDF from the same page? I can't think of any reason it would work here and not for you.

Oh, I tested with FF2 and IE6, both worked with the shorter version. I suppose it's possible you have another piece of code on the page interfering with the process, bvut that seems like a stretch.

-T

 
Thanks Tarwn,

Tried to get it to work with no succes - and no explanation other than a possible time issue - I wonder if the open code is processed as the filemove is still in progress so access is denied?

Anway, found a workround whereby the original file is opened, then copied by the submits target form and then the original deleted on return.

Many thanks for your help throughout.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top