Write to CSV

  • Thread starter Thread starter ^MisterJingo^
  • Start date Start date
M

^MisterJingo^

Hi all,

I need some help on how to generate and write a CSV file in my ASP app
(i'm using c#). Ideally I'd like to generate the CSV file from the DB
and then offer it for download to the user, but i'm unsure where I
should start.

Any help would be appreciated.
 
You could open a file to a predefined location with a random name,
write the db contents there and submit a link to the user.

To write to a file you can use a snippet similar to :

StreamWriter writer = new StreamWriter(File.Create('tempFileName'));
while (rdr.read()) {
writer.WriteLine('data');
}
writer.close();

and then send a link pointing to the file you 've created.

An alternative would be to create a HttpModule that could respond to a
specfic URL and output text/csv content, or a file with as an
attachment.

Regards,
Tasos
 
Hi all, I got it working but when I try and import the vcs file into
outlook I get the following error:

"This error can appear if you have attempted to save a recurring
Lunar appointment in iCalendar format.
To avoid this error, set the appointment option to Gregorian instead of
Lunar."

An example vcs file I generate can be seen below:

BEGIN:VCALENDAR
PRODID:-//IntraMed//NONSGML v1.0//EN
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
DTSTART:20060619T090000Z
DTEND:20060619T170000Z
SUMMARY: CPD Course Course 1
DESCRIPTION:test test test
CLASS:PUBLIC
END:VEVENT
BEGIN:VEVENT
DTSTART:20060614T090000Z
DTEND:20060614T170000Z
SUMMARY: CPD Course test 3
DESCRIPTION:test test test
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR

If I change the version to 1.0 I can import, but it only imports the
first vevent of the file and ignores the rest. Any ideas what I'm
doing wrong or how I can correct this error?

Thanks.


PS The title is wrong, it should read writing to a vcs file!
 
^MisterJingo^ said:
Hi all, I got it working but when I try and import the vcs file into
outlook I get the following error:

"This error can appear if you have attempted to save a recurring
Lunar appointment in iCalendar format.
To avoid this error, set the appointment option to Gregorian instead of
Lunar."

An example vcs file I generate can be seen below:

BEGIN:VCALENDAR
PRODID:-//IntraMed//NONSGML v1.0//EN
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
DTSTART:20060619T090000Z
DTEND:20060619T170000Z
SUMMARY: CPD Course Course 1
DESCRIPTION:test test test
CLASS:PUBLIC
END:VEVENT
BEGIN:VEVENT
DTSTART:20060614T090000Z
DTEND:20060614T170000Z
SUMMARY: CPD Course test 3
DESCRIPTION:test test test
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR

If I change the version to 1.0 I can import, but it only imports the
first vevent of the file and ignores the rest. Any ideas what I'm
doing wrong or how I can correct this error?

Thanks.


PS The title is wrong, it should read writing to a vcs file!

I've sorted this out, but i'll post what I've found here for anyone
else might come across this problem. It seems that to import multiple
vevents you have to use the import feature of outlook, just opening the
file imports the last event only. Also, outlook seems to need a unique
field called: UID:<unique hex num> to import the file correctly (add
this field removed the above error).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top