Format string in ICS Fle (Set font for ICS file)

I am creating the ICS file from the # # WPF application and using the following code to generate the ICS file.

StreamWriter writer; writer = new StreamWriter(filePath); writer.WriteLine("BEGIN:VCALENDAR"); writer.WriteLine("VERSION:2.0"); writer.WriteLine("PRODID:MyApp"); writer.WriteLine("CALSCALE:GREGORIAN"); writer.WriteLine("METHOD:PUBLISH"); writer.WriteLine("BEGIN:VEVENT"); string startDateTime = Convert.ToDateTime(appointmentDetails.StartDate).ToString("yyyyMMdd'T'HHmmss"); string endDateTime = Convert.ToDateTime(appointmentDetails.EndDate).ToString("yyyyMMdd'T'HHmmss"); writer.WriteLine("DTSTART:" + startDateTime); writer.WriteLine("DTEND:" + endDateTime); writer.WriteLine(@"DESCRIPTION:" + appointmentDetails.Body); writer.WriteLine("SUMMARY:" + appointmentDetails.Subject); writer.WriteLine("END:VEVENT"); writer.WriteLine("END:VCALENDAR"); writer.Close(); 

But I have some problems while describing the description. I think when I add \ n for a new line, this creates a problem. I need to format my string as follows.

 ------------------ Header1 ----------------- bOdy1 contents --------------- 

I use the following line to create a dashed line.

 result += new String('-', characterLength) + "\\n"; 

But out out shows a single line instead of a dashed line. I think "\ n" is creating a problem. When I add some space after the line escape character, I see that the problem is resolved. Is there a better / alternative solution for this?

Some line in the description displayed in a different font style. How to make it unique?

How can I set the font for this ICs file from C #?

Please offer.

+4
source share
2 answers

First: you should try to find the iCalendar library, and not write it yourself. The format is very complex, and there are probably a lot of small things that you are missing.

Each line should be no more than 75 bytes. If the line does not fit (because it is larger), you can split the line by entering a real new line ( \r\n ) followed by a space or tab.

The iCalendar reader will simply delete any \r\n[space] or \r\n\t .

You have to make sure that you don't split the file in the middle of the UTF-8 multibyte sequence though.

The value for the description should be encoded as such:

  • ; should become \;
  • should become \,
  • Any new line must be literal \n or \n

Does it help? If not, send full output if iCalendar stream so I can tell you where you made a mistake.

0
source

Format Description ...

  str.AppendLine(String.Format("DESCRIPTION:{0}", description)); str.AppendLine(String.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", description)); 
-1
source

Source: https://habr.com/ru/post/1480842/


All Articles