473,881 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading/Parsing an iCalendar File (.ics)

8 New Member
Hello,
I'm looking for some C# code that loads a iCalendar file from a wesbite, loops through the .ics file and extracts the event details from each event in the file. I don't want to use aspose.icalenda r or another one of the popular packages.

My ultimate goal is take the iCal data and import into a SQL Server database. I can handle the import to the database but I'm having trouble reading the iCalendar files from external website.

I've been able to load rss files in the past and pull the data within those files into a database. I don't see how loading a structured ical file would be that different.

Is my reasoning off?

Thanks.
Jun 11 '08
17 28156
Plater
7,872 Recognized Expert Expert
You could create a NameValueCollec tion for each pairing you find to. Might make it easier to manipulate data once it's parsed into that object.
Jun 17 '08 #11
csharpusr
8 New Member
Here's another question. As I'm parsing the iCalendar file some of the events have additional ":" in them. For Instance, here's an example of a description in an event:

DESCRIPTION:Reg ular Registration/Postmark Date:\nSeptembe r 19\, 2003\nLa
te Registration Period/Fee + Late Fee: September 20-Oct. 3\, 2003\n\nFo
r info on registering after the late registration period go to: \n<http
://www.act.org/aap/regist/standbytest.htm l>\n\nTo confirm that this test
date is available outside of the 50 US States go to: http://www.act.or
g/aap/regist/outside.html

The script parses out the ":" in the URLs as a new line. I need to grab the entire contents of the data within the description field into a single variable. Any ideas?

Again, thanks so much for your help.
Jun 18 '08 #12
Plater
7,872 Recognized Expert Expert
Perhaps do a first indexOf(":") and then everything after that is the value?
Jun 18 '08 #13
Curtis Rutland
3,256 Recognized Expert Specialist
Here's another question. As I'm parsing the iCalendar file some of the events have additional ":" in them.
Again, thanks so much for your help.
Do the Split to a new String[]. Make another string called temp or something. Then loop through the array, starting with index 1 and ending with Length-1, appending each of them to temp, and if it isn't the last one, append a ":".
something like this: (using my original code. you'll have to fit this into the way you modified yours)
Expand|Select|Wrap|Line Numbers
  1. for (int j = 0; j < 9; j++)
  2. {
  3.     string[] line = lines[i + j + 1].Split(delim);
  4.     string temp = "";
  5.     for(int k=1; k<line.Length; k++)
  6.     {
  7.         if(k<line.Length - 1)
  8.             temp += line[k] + ":";
  9.         else
  10.             temp += line[k];
  11.     }
  12.     eventData[j] = temp;
  13. }
  14.  
Jun 18 '08 #14
csharpusr
8 New Member
Cool that's working great. The only other issue I'm having is that the new lines in the description are being parsed out seperatly. So instaed of gathering all of the data after the description I'm getting the first line. Does that make sense?

Again, I can't thank you guys enough for all of your help.
Jun 18 '08 #15
Curtis Rutland
3,256 Recognized Expert Specialist
Cool that's working great. The only other issue I'm having is that the new lines in the description are being parsed out seperatly. So instaed of gathering all of the data after the description I'm getting the first line. Does that make sense?

Again, I can't thank you guys enough for all of your help.
So there are newline chars in the file aside from separating each pair? Wow, that's tough. Can't think of an easy fix off the top of my head.
Jun 18 '08 #16
csharpusr
8 New Member
Yep, it's a bugger. According to the iCalendar spec data needs to be wrapped to the next line if it is over a certain length. The next line has a open space before the beginning of the text. So here's an example:

DESCRIPTION:Reg ular Registration/Postmark Date:\ La
te Registration Period/Fee + Late Fee: September 20-Oct. 3\, 2003\n<http
://www.act.org/aap/regist/standbytest.htm l>\n\nTo confirm that this test

The sample above should have a space before "te Registration... " and "://www.act.org..."
Jun 18 '08 #17
Curtis Rutland
3,256 Recognized Expert Specialist
Yep, it's a bugger. According to the iCalendar spec data needs to be wrapped to the next line if it is over a certain length. The next line has a open space before the beginning of the text. So here's an example:

DESCRIPTION:Reg ular Registration/Postmark Date:\ La
te Registration Period/Fee + Late Fee: September 20-Oct. 3\, 2003\n<http
://www.act.org/aap/regist/standbytest.htm l>\n\nTo confirm that this test

The sample above should have a space before "te Registration... " and "://www.act.org..."
Well, I guess you can check for a space character at the beginning of each line, and if there is one, append it's data to the last one.

Other than that, good luck!
Jun 18 '08 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

8
1727
by: Darius Fatakia | last post by:
Hello, I have a file that I have opened for reading and this file contains lines with several different types of constraint information. For example, here are a few lines: length(0) = 10 Duration of task 0 is 10. needs(16,1) Operation 16 uses resource 1. before(49,9) Operation 49 must be before operation 9.
5
3418
by: WoodenSword | last post by:
Hi, I am trying to read a huge text file (2GB) using StreamReader. I do this: Read a line (readline()) I process the line a bit (split it with delimeter and change fields a bit) execute (using transaction) a insert query to Ms Sql server
8
3526
by: Andrew Robert | last post by:
Hi Everyone. I tried the following to get input into optionparser from either a file or command line. The code below detects the passed file argument and prints the file contents but the individual swithces do not get passed to option parser.
2
3613
by: Jean-Marie Vaneskahian | last post by:
Reading - Parsing Records From An LDAP LDIF File In .Net? I am in need of a .Net class that will allow for the parsing of a LDAP LDIF file. An LDIF file is the standard format for representing LDAP objects. I need to be able to read the records from an LDIF file into ..Net. There exists a Perl module that will do exactly this called Net::LDAP::LDIF but I am wanting to port my code over to .Net and cannot find anything with similar...
4
7656
by: Lyle Fairfield | last post by:
iCalendar is a standard (RFC 2445) for calendar data exchange. I plan to transfer data from iCalendar files (extension .ics), to a linked Outlook calendar table. While Outlook (2002) has an import strand for this, it does not seem to work with the format I shall be importing. iCalendar files are not comma delimited files. My first inclination is to open the iCalendar file with low level DOS commands, to parse its contents with Regular...
3
3042
by: =?ISO-8859-1?Q?Fabian_L=F3pez?= | last post by:
Hi, I am parsing an XML file that includes chineses characters, like ^ uuࢲDZw.Lﳲǐ or إ... The problem is that I get an error like: UnicodeEncodeerror:'charmap' codec can't encode characters in position.... The thing is that I would like to ignore it and parse all the characters less these ones. So, could anyone help me? I suppose that I can catch an exception that ignores it or maybe use any function that...
5
4933
by: amjadcsu | last post by:
I am a newbie in python I am trying to parse a xml file and write its content in a txt file. The txt contains null elements. Any reason what iam doing wrong here Here is the code that i wrote import sys,os import xml.sax import xml.sax.handler
31
2535
by: broli | last post by:
I need to parse a file which has about 2000 lines and I'm getting told that reading the file in ascii would be a slower way to do it and so i need to resort to binary by reading it in large chunks. Can any one please explain what is all this about ?
2
2847
by: Derik | last post by:
I've got a XML file I read using a file_get_contents and turn into a simpleXML node every time index.php loads. I suspect this is causing a noticeable lag in my page-execution time. (Or the wireless where I'm working could just be ungodly slow-- which it is.) Is reading a file much more resource/processor intensive than, say, including a .php file? What about the act of creating a simpleXML object? What about the act of checking the...
0
9928
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10718
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10816
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10401
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7953
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5977
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4597
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3225
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.