Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Output from asp to file

Posted on 2003-12-09
5
262 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 Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
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/…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 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