Big George
2009-12-04 23:41:02 UTC
Hello,
How asp.net can deal with client-side files is a question that has
intrigued me for a long time ago. We need to transfer client-side
files via asp.net to a web server.
The first thing to do is to compress those files and then transfer
them.
To compress the files, the asp.net application has to zip them on a
folder of the client PC. How to do that? I'm aware that due security
restrictions, asp.net application has to use Activex dll or some plugs
to manipulate files on client side and end-users have to download and
let be installed.
I found some vbscript that zip files on a PC folder, using 7-zip
software. I post it .
How could I use this vbs in my asp.net code in order to compress the
clienst-side files?
If I click on my button and call Zip function, then it got these
errors:
- Microsoft VBScript runtime error: Object required: 'WScript'
- Microsoft VBScript runtime error: Type mismatch: 'Ubound'
- Microsoft VBScript runtime error: Object required: 'oFSO'
Do I have to compile the vbscript code in some dll and then use it in
my asp.net application?
Any guide to solve this thing will be very appreciated. Thank you.
==========================
HTML Code and VBS code:
==========================
<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="Default.aspx.vb" Inherits="Transfer._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<LINK href="Styles.css" type="text/css" rel="stylesheet" />
<script language="vbscript" type="text/vbscript">
Function Zip (sFileReducir, sArchiveZip, sFolderZip, sFolderDBF)
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set oShell = WScript.CreateObject("Wscript.Shell")
'--------Find Working Directory--------
aScriptFilename = Split(Wscript.ScriptFullName, "\")
sScriptFilename = aScriptFileName(Ubound(aScriptFilename))
sWorkingDirectory = Replace(Wscript.ScriptFullName,
sScriptFilename, "")
'--------------------------------------
'-------Ensure we can find 7za.exe------
If oFSO.FileExists(sWorkingDirectory & "\" & "7zG.exe") Then
s7zLocation = ""
ElseIf oFSO.FileExists("C:\Program Files\7-Zip\7zG.exe") Then
s7zLocation = "C:\Program Files\7-Zip\"
ElseIf oFSO.FileExists("C:\Archivos de programa\7-Zip\7zG.exe")
Then
s7zLocation = "C:\Archivos de programa\7-Zip\"
Else
Zip = "Error: Couldn't find 7zG.exe"
Exit Function
End If
'--------------------------------------
oShell.Run """" & s7zLocation & "7zG.exe"" a -tzip -y """ &
sFolderZip & sArchiveZip & """ " & sFolderDBF & sFileReducir, 0,
True
If oFSO.FileExists(sArchiveZip) Then
Zip = 1
Else
Zip = "Error: Archive Creation Failed."
End If
Call ShowMessage("Everything OK!")
End Function
Function ShowMessage (sMessage, x)
Wscript.echo "Here's a message: " & sMessage
End Function
</script>
</head>
<body>
<form id="form1" runat="server">
<div >
Files Compression
</div>
<div>
<input id="Button1" type="button" language="VBScript"
onclick="vbscript:Zip 'Reducir.dbf','Reducido.zip','C:\x\','C:\x\'"
value="compress Files to .zip on client" />
</div>
How asp.net can deal with client-side files is a question that has
intrigued me for a long time ago. We need to transfer client-side
files via asp.net to a web server.
The first thing to do is to compress those files and then transfer
them.
To compress the files, the asp.net application has to zip them on a
folder of the client PC. How to do that? I'm aware that due security
restrictions, asp.net application has to use Activex dll or some plugs
to manipulate files on client side and end-users have to download and
let be installed.
I found some vbscript that zip files on a PC folder, using 7-zip
software. I post it .
How could I use this vbs in my asp.net code in order to compress the
clienst-side files?
If I click on my button and call Zip function, then it got these
errors:
- Microsoft VBScript runtime error: Object required: 'WScript'
- Microsoft VBScript runtime error: Type mismatch: 'Ubound'
- Microsoft VBScript runtime error: Object required: 'oFSO'
Do I have to compile the vbscript code in some dll and then use it in
my asp.net application?
Any guide to solve this thing will be very appreciated. Thank you.
==========================
HTML Code and VBS code:
==========================
<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="Default.aspx.vb" Inherits="Transfer._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<LINK href="Styles.css" type="text/css" rel="stylesheet" />
<script language="vbscript" type="text/vbscript">
Function Zip (sFileReducir, sArchiveZip, sFolderZip, sFolderDBF)
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set oShell = WScript.CreateObject("Wscript.Shell")
'--------Find Working Directory--------
aScriptFilename = Split(Wscript.ScriptFullName, "\")
sScriptFilename = aScriptFileName(Ubound(aScriptFilename))
sWorkingDirectory = Replace(Wscript.ScriptFullName,
sScriptFilename, "")
'--------------------------------------
'-------Ensure we can find 7za.exe------
If oFSO.FileExists(sWorkingDirectory & "\" & "7zG.exe") Then
s7zLocation = ""
ElseIf oFSO.FileExists("C:\Program Files\7-Zip\7zG.exe") Then
s7zLocation = "C:\Program Files\7-Zip\"
ElseIf oFSO.FileExists("C:\Archivos de programa\7-Zip\7zG.exe")
Then
s7zLocation = "C:\Archivos de programa\7-Zip\"
Else
Zip = "Error: Couldn't find 7zG.exe"
Exit Function
End If
'--------------------------------------
oShell.Run """" & s7zLocation & "7zG.exe"" a -tzip -y """ &
sFolderZip & sArchiveZip & """ " & sFolderDBF & sFileReducir, 0,
True
If oFSO.FileExists(sArchiveZip) Then
Zip = 1
Else
Zip = "Error: Archive Creation Failed."
End If
Call ShowMessage("Everything OK!")
End Function
Function ShowMessage (sMessage, x)
Wscript.echo "Here's a message: " & sMessage
End Function
</script>
</head>
<body>
<form id="form1" runat="server">
<div >
Files Compression
</div>
<div>
<input id="Button1" type="button" language="VBScript"
onclick="vbscript:Zip 'Reducir.dbf','Reducido.zip','C:\x\','C:\x\'"
value="compress Files to .zip on client" />
</div>