Saturday, May 16, 2009

how to compress files using asp

how to compress files using asp

most of the time we require to compress file and save it to perticular localtion , or you can
use the for any purpose as u want .

for this we requires Server supporting WScript.Shell - most hosts won't allow this.

here u can get the download link , here u can specify either relative path or absolute path

before that please download this file, click here to download

-zipfile.asp
< % 

'---------------------------------------------------------
'CreateZipFile: function to create zip file at perticular location
'ZipPath - full path for the zip file, including the zip file name.
'arrFilesPath - array of the files to be zipped,
e.g. Array("C:\*.exe", "C:\foldername\*.*")
'NOTE: this code requires ZIP.EXE utility in the same location
' as this file.
'---------------------------------------------------------
Sub CreateZipFile(ZipPath, arrFilesPath)
Const PKZIP_FILE_NAME="zip.exe"
Dim strCommand, objShell, objFSO
Dim x

'first check zip.exe file is exists:
Set objFSO=Server.CreateObject("Scripting.FileSystemObject")
If Not(objFSO.FileExists(Server.MapPath(ZIP_FILE_NAME) )) Then
Set objFSO=Nothing
Err.Raise 20000, "Zip File Creator", "zip utility not found: "&Server.MapPath(ZIP_FILE_NAME)
End If

'delete current file:
If objFSO.FileExists(ZipPath) Then
objFSO.DeleteFile(ZipPath)
End If
Set objFSO=Nothing

'batch command:

strCommand=Server.MapPath(ZIP_FILE_NAME)&" -add "&ZipPath&" "
For x=0 To UBound(arrFilesPath)
strCommand=strCommand&arrFilesPath(x)
If x < UBound(arrFilesPath) Then strCommand=strCommand&" "
Next

'execute:
Set objShell=Server.CreateObject("WScript.Shell")
objShell.Run strCommand, 0, True 'wait!

'done.
Set objShell=Nothing
End Sub
%>

now u can call your CreateZipFile() function
-checkZipFile.asp


< % 

Call checkZipFile()

Sub checkZipFile()
'create zip and give link:
Call CreateZipFile(Server.MapPath("Testzip.zip"), Array(Server.MapPath("images")&"\*.*"))
Response.Write("click here download zip")
End Sub
%>
here u can get the download link , here u can specify either relative path or absoutate path

how to display records from an excel file

hi this is my first blog in this blogspot , hope it may help you ..

i have seen most of the time software people require to display records from an Microsoft Excel in an ASP. We could use SQL command while retreving data from an excel sheet. for the we know how to connect with sql

here is the sql connection string :

strConnection = "DBQ=" & Server.MapPath("nameofexcelfile.xls") & "; DRIVER={Microsoft Excel Driver (*.xls)};"

We will use a specific driver to connect to Excel files.
so for that we can use ODBC

An Example :

strConnection = "DBQ=" & Server.MapPath("nameofexcelfile.xls") & "; DRIVER={Microsoft Excel Driver (*.xls)};"

Set conn = Server.CreateObject("ADODB.Connection")
Set rss = Server.CreateObject("ADODB.Recordset")
cn.open strConnection


sql="select * from tablename;"

rss.Open sql, conn, adOpenStatic, adLockPessimistic


do while not rss.eof
response.write rss("Fieldname")
rss.movenext
loop

rss.close
Set rss = nothing
conn.close
Set conn = nothing


and now u can access you excel content in you are asp coding

thank you.