how to create an excel file from an ASP page
The code below gives a brief example on how to create an .xls file from an asp webpage. I use this to often to export my customers data(database) to an offline version wich they can use for archiving/reporting.
To to so you have to change the contenttype of the asp file to "application/vnd.ms-excel". This code has to be at the top of you page.
From then on you can use the response.write() function to write data to the .xls file. The data must be structured in table rows("<TR>") .
You can define the fields in the .xls with TH and TD.
code snippet:
ASP:
<% Response.ContentType = "application/vnd.ms-excel" strfilename = "Filename_" & Day(Date) & Month(Date) & Year(Date) & ".xls" Response.AddHeader "Content-Disposition","filename=" & strfilename response.expires = -1 %> strContent =”fill this variable(strContent) the same way as an html table” <able border="1" cellpadding="4" cellspacing="1" width="100%" %> <% response.write strContent %> </table%>
Popularity: 5% [?]
sending a mail with asp on win2k3
While migrating an application from an old IIS4(NT) server to a new win2003 machine there were some errors with emails.
It's always better to use a default component over a 3th party tool. That's why you should use CDO.
CDO (Collaboration Data Objects) is a Microsoft technology that is designed to simplify the creation of messaging applications.
However there are 2 versions of CDO: CDOSYS and CDONT.
Microsoft doesn't support CDONTs anymore on win2k/XP and 2k3.
So the only thing i had to change to make it work, was to change te version.
The code below works on windows 2003.
-
<%
-
Set myMail=CreateObject("CDO.Message")
-
-
myMail.Subject="test"
-
myMail.From="name@domain.com"
-
myMail.To="name@domain.com"
-
myMail.TextBody="test"
-
-
myMail.Configuration.Fields.Item _
-
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
-
'Name or IP of remote SMTP server
-
myMail.Configuration.Fields.Item _
-
("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
-
="relay1.smtp.local"
-
'Server port
-
myMail.Configuration.Fields.Item _
-
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _
-
=25
-
myMail.Configuration.Fields.Update
-
-
myMail.Send
-
-
set myMail=nothing
-
response.write "mail send succesfully"
Popularity: 3% [?]
An overview of all HTTP status codes
These HTTP Status codes are returned by the server to the client software to determine the outcome of a request.
The first digit of the status code specifies one of five classes of response.
- 1xx Informational
- 2xx Success
- 3xx Redirection
- 4xx Client Error
- 5xx Server Error
Each Status-Code is described below.
- 200: request completed (OK)
- 201: object created, reason = new URI
- 202: async completion (TBS)
- 203: partial completion
- 204: no info to return
- 205: request completed, but clear form
- 206: partial GET furfilled
- 300: server couldn't decide what to return
- 301: object permanently moved
- 302: object temporarily moved
- 303: redirection w/ new access method
- 304: if-modified-since was not modified
- 305: redirection to proxy, location header specifies proxy to use
- 307: HTTP/1.1: keep same verb
- 400: invalid syntax
- 401: access denied
- 402: payment required
- 403: request forbidden
- 404: object not found
- 405: method is not allowed
- 406: no response acceptable to client found
- 407: proxy authentication required
- 408: server timed out waiting for request
- 409: user should resubmit with more info
- 410: the resource is no longer available
- 411: the server refused to accept request w/o a length
- 412: precondition given in request failed
- 413: request entity was too large
- 414: request URI too long
- 415: unsupported media type
- 500: internal server error
- 501: required not supported
- 502: error response received from gateway
- 503: temporarily overloaded
- 504: timed out waiting for gateway
- 505: HTTP version not supported
Popularity: 4% [?]
Connection to access or MS SQL database in ASP
The best way of connecting to a database is including a separated file with the database info. Afterwards u can always check if the database connection state is open.
MS SQL
set cnn = Server.CreateObject("ADODB.Connection")
cnn.ConnectionString = "Provider=SQLOLEDB.1;User ID=User;Passwd=;Initial Catalog=ASPDB;Data Source=server"
cnn.Open
Microsoft Access
set cnn = Server.CreateObject("ADODB.Connection")
cnn.Provider = "Microsoft.Jet.OLEDB.4.0"
cnn.ConnectionString = Server.MapPath ("/mywwwfolder") & "\database.mdb"
cnn.Open
check connection state
if cnn.State = 0 then
cnn.Open
end if
Popularity: 3% [?]


