aRo` automating your e-commerce

This blog has been neglected due to the success of Solidshops.com
31Aug/07

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:
  1. &lt;%
  2. Response.ContentType = "application/vnd.ms-excel"
  3. strfilename = "Filename_" &amp; Day(Date) &amp; Month(Date) &amp; Year(Date) &amp; ".xls"
  4. Response.AddHeader "Content-Disposition","filename=" &amp; strfilename
  5. response.expires = -1
  6. %&gt;
  7. strContent =”fill this variable(strContent) the same way as an html table”
  8.  
  9. &lt;able border="1" cellpadding="4" cellspacing="1" width="100%" %&gt;
  10. &lt;% response.write strContent %&gt;
  11. &lt;/table%&gt;

Popularity: 5% [?]

Filed under: asp No Comments
8Aug/07

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.

ASP:
  1. &lt;%
  2. Set myMail=CreateObject("CDO.Message")
  3.  
  4. myMail.Subject="test"
  5. myMail.From="name@domain.com"
  6. myMail.To="name@domain.com"
  7. myMail.TextBody="test"
  8.  
  9. myMail.Configuration.Fields.Item _
  10. ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
  11. 'Name or IP of remote SMTP server
  12. myMail.Configuration.Fields.Item _
  13. ("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
  14. ="relay1.smtp.local"
  15. 'Server port
  16. myMail.Configuration.Fields.Item _
  17. ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _
  18. =25
  19. myMail.Configuration.Fields.Update
  20.  
  21. myMail.Send
  22.  
  23. set myMail=nothing
  24. response.write "mail send succesfully"

Popularity: 3% [?]

Filed under: asp No Comments
16Jul/06

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% [?]

Filed under: asp, asp.net, php No Comments
6Feb/06

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% [?]

Filed under: asp No Comments