• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 280
  • Last Modified:

Output from asp to file

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
sgriffin
Asked:
sgriffin
  • 2
  • 2
1 Solution
 
DexstarCommented:
@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
 
sgriffinAuthor Commented:
will try , thanks!
0
 
sgriffinAuthor Commented:
would it be possible to delete the vcs after?
0
 
DexstarCommented:
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
 
IguanasanCommented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now