Click to See Complete Forum and Search --> : FSO CopyFile Question...Pls Help


kwilliams
02-16-2004, 03:16 PM
I'm trying to use the FSO CopyFile method, but I'm having a problem. First off, the page was created using ASP & JavaScript. I tried using a VBScript version of this method in a "runat=server" tag, but it wouldn't work well with the page's code. So I found a JS option for the FSO CopyFile method.

But I'm getting a "Path not found" error message. You can see the page at: http://www.douglas-county.com/Local_Govt/agendas_new.asp

I tried to put a "\" slash after the path, but I got a JS error saying "Undetermined String Constant". So I replaced it with "\\", and it worked. Does anyone have any suggestions about what the problem could be? Thanks for any & all help.

KWilliams

Ribeyed
02-16-2004, 03:25 PM
Hi,
sounds like your not using the correct syntax for specifying the correct path. Not sure why you would try using a runat=server tag unless your using ASP.NET but looking at the page you provided your using classic ASP. You also said that you found a JS (javascript) version for doing this but you asked the question in the ASP form, are you expecting an ASP or JavaScript answer????
Are you using virtual or relative paths?

kwilliams
02-16-2004, 03:32 PM
sounds like your not using the correct syntax for specifying the correct path. Not sure why you would try using a runat=server tag unless your using ASP.NET but looking at the page you provided your using classic ASP.
The page is classic ASP, but I put a "<%@LANGUAGE="JAVASCRIPT"%>" at the top of the page. Because of this, any VBScript code needs to be in a "runat=server' tag, or it won't work.

You also said that you found a JS (javascript) version for doing this but you asked the question in the ASP form, are you expecting an ASP or JavaScript answer????
I posted it in the ASP forum because the page is primarily ASP with JS syntax. The problem I'm having relates to the FSO CopyFile method, so I wasn't sure which forum to place this issue in. I will also place a post in the JS forum.

Are you using virtual or relative paths?

They are both relative/physical paths.

Thanks for the quick response. As I stated above, I will also make sure to post this message in the JS forum. But if you have any suggestions, it would be greatly appreciated. Thanks.

Ribeyed
02-16-2004, 03:43 PM
The page is classic ASP, but I put a "<%@LANGUAGE="JAVASCRIPT"%>" at the top of the page. Because of this, any VBScript code needs to be in a "runat=server' tag, or it won't work.


Don't know where you heard that but thats just not the case. Just because you declare which language you are using at the top of your page doesn't mean you need "runat=server" anywhere in your ASP code. Can you show an example of where you have this in your VBScript code???
No problem with you not knowing where to post but you could help us out a bit by specifying which language you would like the answer to be in.
So you have more then one path specified in your code. You should use only virtual paths in your code.
Can you post some of the code?

kwilliams
02-16-2004, 03:50 PM
Hi Ribeyed,

You can see the complete code at http://www.douglas-county.com/Local_Govt/agendas_new.asp.

Concerning the "runat=server", I was told that from several sources, including the Ultradev4 forum, and the DMXZone.com forum. They even use that method to insert VBScript into pages for their Pure ASP Upload extension.

Concerning what language I would like help in, it's JavaScript. Thanks.

kwilliams
02-16-2004, 05:13 PM
Ok, I'm worn out with trying to use the JS FSO CopyFile method, so I went back to what worked...at least somewhat.

This is the VBScript FSOCopyFile method that I came up with:
<%@LANGUAGE="VBSCRIPT"%>
<%
If Session("Packet") <> "" then 'if filename field isn't empty, then...
strFileName = Session("Packet") 'assign var to filename

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
strLocation1 = "c:\inetpub\wwwroot\FOLDER\SUBFOLDER1\SUBFOLDER2\" & strFileName 'internal physical path
strLocation2 = "\\WEBSERVER\FOLDER\" 'external physical path
objFSO.CopyFile strLocation1, strLocation2, true 'copy from internal to external
Set objFSO = nothing
End if
Response.Redirect("agendas_thankyou.asp") 'redirects whether there's a file or not
%>

This script works great, but unfortunately it has a "Permission Denied" error for a couple of minutes until it clears the firewall on the external webserver. Then the script is successful.

So is there a way to:
1) Refresh the VBScript script until it's successful
2) Redirect the user ONLY after the script is successful.

Thanks for any help.

Ribeyed
02-16-2004, 06:55 PM
Hi,
to refresh the page:


<%
Response.AddHeader "Refresh", "10"
%>


this will refresh every 10 seconds.

To redirect but only if sucessful depends on which part is not sucessful.

PeOfEo
02-16-2004, 07:02 PM
Originally posted by [SWR]Ribeyed
Hi,
to refresh the page:


<%
Response.AddHeader "Refresh", "10"
%>


this will refresh every 10 seconds.

To redirect but only if sucessful depends on which part is not sucessful. would that just output a meta refresh?

Ribeyed
02-16-2004, 07:04 PM
no it will refresh the page

PeOfEo
02-16-2004, 07:59 PM
Originally posted by [SWR]Ribeyed
no it will refresh the page oh it does it server side?

buntine
02-16-2004, 11:14 PM
Add this under your copyfile code..


if objFSO.fileExists(strLocation2 & strFileName) then
response.redirect("yourNextPage.asp")
else
response.redirect(request.serverVariables("SCRIPT_NAME"))
end if


This will determine if the file has been copied to the new location. If it has, the page will be reloaded. If not, the page will be refreshed.

Dont forget to place the following line at the top of the page.


response.buffer = true


This will set the page buffer and allow server-side redirects.

Regards,
Andrew Buntine.

kwilliams
02-17-2004, 05:42 PM
I'll give your suggestion a try buntine. Thanks.

kwilliams
02-18-2004, 10:50 AM
Hi buntine,

I just got through testing our your solution on my page, but it's still not working. First off, I'm going to include my revised code, which includes a different method:
<%@LANGUAGE="VBSCRIPT"%>
<%
Response.Buffer = true 'Sets the page buffer and allows server-side redirects.
if Session("Packet") <> "" then 'if filename field isn't empty, then...
strFileName = Session("Packet") 'assign var to filename
'strFileName = "Agenda1-12-04.pdf" 'STATIC TEST

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
strLocation1 = "c:\inetpub\wwwroot\FOLDER\SUBFOLDER1\SUBFOLDER2\" & strFileName 'internal physical path
strLocation2 = "\\WEBSERVER\FOLDER\" 'external physical path
objFSO.CopyFile strLocation1, strLocation2, true 'copy from internal to external <<--LINE 12
'This will determine if the file has been copied to the new location.
'If it has, the page will be reloaded. If not, the page will be refreshed.
if objFSO.fileExists(strLocation2 & strFileName) then
Response.Write("<script language='JavaScript'>window.close()</script>")
else
Response.Redirect(Request.ServerVariables("<script language='JavaScript'>window.location.reload(true);</script>"))
End if
Set objFSO = nothing
else
Response.Write("<script language='JavaScript'>window.close()</script>") 'redirects whether there's a file or not
End if
%>
What basically happens is that the INSERT/UPDATE pages redirect the user to a thank you page, which loads the VBScript FSO CopyFile page as a separate smaller window. This way the user doesn't get tied up in a "Permissions Denied" page.

The problem is that the FSO page gets stuck on Line 12 (marked in above code), which is the actual FileCopy code. It doesn't get a chance to get down to the if statement that asks if the file exists because of this. If I manually refresh the page with the refrenced code, the window does close properly when the job is successful. But it's not refreshing on its own.

In place of:
Response.Redirect(Request.ServerVariables("<script language='JavaScript'>window.location.reload(true);</script>"))

I tried a few more options to refresh the page on failure, including:
1) JS Method: Response.Write("<script language='JavaScript'>window.location.reload( false );</script>")
2) VBScript Method: objFSO.Refresh

...but neither of these worked, because it still gets stuck on Line 12. I guess it's one of those "Did the chicken come before the egg" problems. Any suggestions??

buntine
02-18-2004, 11:02 AM
Ok, i havent finished reading your post just yet, though the following line will output an error.


Response.Redirect(Request.ServerVariables("<script language='JavaScript'>window.location.reload(true);</script>"))


The request.serverVariables() method is used to invoke a set of pre-defined server constants such as; SERVER_NAME, SCRIPT_NAME, LOGON_USER, etc. The way which it has been used in your program will confuse the server.

The correct code to refrech the page is as follows:


Response.redirect(request.serverVariables("SCRIPT_NAME"))

buntine
02-18-2004, 11:37 AM
If you get a permissions error, why dont you just set file permissions for each loaction? Also, why does it work if you refresh the page?

kwilliams
02-25-2004, 11:43 AM
Hello all,

I used your feedback to get the VBScript version working on the intranet server. This is what I came up with:
<%@LANGUAGE="VBSCRIPT"%>
<%
Response.Buffer = true 'Sets the page buffer and allows server-side redirects.
Response.Write("<font face='arial'><b>" & "Uploading Agenda Packet..." & "</b></font>") 'displays when page loads
Response.AddHeader "Refresh", "5" 'refreshes page every 5 seconds
if Session("Packet") <> "" then 'if filename field isn't empty, then...
strFileName = Session("Packet") 'assign var to filename
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
strLocation1 = "c:\inetpub\wwwroot\FOLDER\SUBFOLDER1\SUBFOLDER2\" & strFileName 'internal physical path
strLocation2 = "\\DGIISSRV1\SUBFOLDER\" 'external physical path
objFSO.CopyFile strLocation1, strLocation2, true 'copy from internal to external
'This will determine if the file has been copied to the new location.
'If it has, the page will be reloaded. If not, the page will be refreshed.
if objFSO.fileExists(strLocation2 & strFileName) then
Response.Write("<script language='JavaScript'>window.close()</script>") 'close window if upload is successful
End if
Set objFSO = nothing
else
Response.Write("<script language='JavaScript'>window.close()</script>") 'closes window if there's no file to upload
End if
%>

But I still ran into the same problem of how long it takes to get a file through the webserver's firewall into the external folder. So someone suggested that I do the CopyFile method from the external webserver, so that there wouldn't be any issues with the firewall. And since my whole site is written with ASP & JavaScript, I needed to come up with a JS version that could be placed in a looped record. After reviewing this article: http://www.webreference.com/js/column71/3.html, I came up with this:
<%
var packet = (rsAgendasB.Fields.Item("Packet").Value); //assigns var to filename
if (packet != null) { //if filename field isn't empty, then...
Response.Write("<a target='_blank' href='http://www.douglas-county.com/Local_Govt/Agenda_Packets/" + packet + "'>" + packet + "</a>");

var fso = new ActiveXObject("Scripting.FileSystemObject");
var strLocation1 = "\\DGINTRASRV1\\Agenda_Packets\\" + packet;
var strLocation2 = "e:\\inetpub\\wwwroot\\dgcowww\\Local_Govt\\Agenda_Packets\\";
Response.Write("<br>" + "Packet Paths:" + "<br>" + "Path 1: " + strLocation1);
Response.Write("<br>" + "Path 2: " + strLocation2);
fso.CopyFile(strLocation1, strLocation2, true); 'CopyFile Line
}
else
{
Response.Write("NONE");}
%>
I also tried changing the CopyFile line to say:
fso.CopyFile("\\DGINTRASRV1\\Agenda_Packets\\" + packet, "e:\\inetpub\\wwwroot\\dgcowww\\Local_Govt\\Agenda_Packets\\", true);
Everything works great except for the CopyFile method itself. On that line, I get a "Path not found" error message. But I did a check next to the filename link, which can be seen at http://www.douglas-county.com/Local_Govt/agendas_new.asp, and both paths are being pulled correctly.

So I think that the problem lies in the syntax I have for the JS CopyFile method itself. Can anyone see something that may be wrong with that line? Thanks for any & all help.