Solved

Output from asp to file

Posted on 2003-12-09
5
259 Views
Last Modified: 2012-08-14
Hi , i want to output some Calendar data from asp ( would be coming from access db in backend) to a txt file in the format..

Name: Test
Address: Forest Lane
Country: Ireland

Any ideas?

Im trying to output in VCS extension and so use with Outlook...

thanks

Stephen
0
Comment
Question by:sgriffin
  • 2
  • 2
5 Comments
 
LVL 19

Expert Comment

by:Dexstar
ID: 9906193
@sgriffin:

> Hi , i want to output some Calendar data from asp ( would be coming from access
> db in backend) to a txt file in the format..

You should use the "Scripting.FileSystemObject".  A small sample of its use would look like this:
   Dim fso
   Dim ts
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set ts = fso.CreateTextFile("SOMEPATH\Event.VCS", True)
   ts.WriteLine "Name: " & RS("Name")
   ts.WriteLine "Address: " & RS("Address")
   ts.WriteLine "Country: " & RS("Country")

Then you can just add a link to the .VCS file.


Hope That Helps,
Dex*
0
 
LVL 2

Author Comment

by:sgriffin
ID: 9906200
will try , thanks!
0
 
LVL 2

Author Comment

by:sgriffin
ID: 9906205
would it be possible to delete the vcs after?
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9906223
Sure the "Scripting.FileSystemObject" has facilities for deleting files as well.  All of the methods and properties are documented here:
      http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/jsobjFileSystem.asp

Enjoy!

D*
0
 
LVL 4

Accepted Solution

by:
Iguanasan earned 50 total points
ID: 9907450
Here you go.  All you need to do is adjust this to get the data from the database instead of the URL.  Also, if you fix the DateToUTC I'd appreciate it if you could flip it back to me either through this forum or via email, Iguanasan*AT*hotmail*DOT*com.

<% Option Explicit ' Ensure Variable Usage is Unique %>
<!--#include file="functions.asp" -->
<%

'
' Define Variables and constants.
'
'---- CursorTypeEnum Values ----
Const adOpenForwardOnly = 0
Const adOpenKeyset = 1
Const adOpenDynamic = 2
Const adOpenStatic = 3
'---- LockTypeEnum Values ----
Const adLockReadOnly = 1
Const adLockPessimistic = 2
Const adLockOptimistic = 3
Const adLockBatchOptimistic = 4
'---- CommandTypeEnum Values ----
Const adCmdUnknown = &H0008
Const adCmdText = &H0001
Const adCmdTable = &H0002
Const adCmdStoredProc = &H0004
Const adCmdFile = &H0100
Const adCmdTableDirect = &H0200

Dim dtDate, dtTime, FileName
Dim CRLF ' Carriage Return Line Feed
Dim QQ   ' Double Quote
CRLF = Chr(13) & Chr(10)
QQ = Chr(34)

FileName = Request.QueryString("Event")
If Len(FileName) > 0 Then
    FileName = Replace(FileName," ","_")
Else
    FileName = "untitled"
End If
FileName = FileName & ".ics"

Response.Expires = 0
Response.Buffer = True
Response.Clear
Response.ContentType = "text/calendar"
Response.AddHeader "content-disposition", "attachment; filename=""" & FileName & """"
Response.Write "BEGIN:VCALENDAR" & CRLF
Response.Write "VERSION:0.1" & CRLF
Response.Write "PRODID:-//immediaC/webcal//NONSGML v1.0//EN" & CRLF
Response.Write "BEGIN:VEVENT" & CRLF
dtDate = Request.QueryString("start")
dtTime = TimeValue(dtDate)
dtDate = DateValue(dtDate)
Response.Write "DTSTART:" & dateToUTC(dtDate,dtTime) & CRLF ' 19970714T170000Z
dtDate = Request.QueryString("end")
dtTime = TimeValue(dtDate)
dtDate = DateValue(dtDate)
Response.Write "DTEND:" & dateToUTC(dtDate,dtTime) & CRLF ' 19970715T035959Z
Response.Write "SUMMARY:" & Request.QueryString("Event") & CRLF 'Bastille Day Party
If Len(Request.QueryString("Location")) > 0 Then
    Response.Write "LOCATION:" & Request.QueryString("Location") & CRLF
End If
Response.Write "DESCRIPTION:" & Fold(Request.QueryString("Details")) & CRLF
Response.Write "END:VEVENT" & CRLF
Response.Write "END:VCALENDAR" & CRLF
Response.End

Function Fold(byRef sString)
      if Len(sString) > 0 then
            Fold = Replace(sString,CRLF,CRLF & " ")
      end if
End Function

Function dateToUTC (sDate, sTime)
' returns a UTC-formatted string describing the date and time
' The UTC format is YYYYMMDDTHHMMSS plus Z for Greenwich Mean Time

'
' this thing doesn't take into consideration Daylight Saving Time.  I'm going to have to adjust for that.
' For now I'm switching to a 3 hour offset.
' According to this site: http://webexhibits.org/daylightsaving/b.html
' North America: United States, Canada, Mexico, St. Johns, Bahamas, Turks And Caicos
' Start: First Sunday In April
' End: Last Sunday In October
' See http://webexhibits.org/daylightsaving/g.html for more details.
'
'
Dim iHour, iMin, iYear, iMonth, iDay, tDate, tTime
tDate = DateValue(sDate)
tTime = TimeValue(sTime)
iHour = Hour(DateAdd("h", 3, tTime)) 'correction for US Eastern time
iMin = Minute(tTime)
iYear = Year(tDate)
iMonth = Month(tDate)
iDay = Day(tDate)
If iHour < 3 Then
    iDay = iDay + 1
End If
      
Dim s : s = iYear
If iMonth < 10 Then s = s & "0"
s = s & iMonth
If iDay < 10 Then s = s & "0"
s = s & iDay & "T"
If iHour < 10 Then s = s & "0"
s = s & iHour
If iMin < 10 Then s = s & "0"
s = s & iMin & "00Z"
dateToUTC = s

End Function
%>
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now