แปลง ICS ไปยังรูปแบบอื่น

แปลง ICS เป็น EML

สำหรับการแทนเหตุการณ์ปฏิทินหรือการนัดหมาย, Aspose.Email มี Appointment คลาส ตัวอย่างโค้ดต่อไปนี้แสดงกระบวนการแปลงจาก ICS เป็น EML:

  1. โหลดไฟล์ ICS ที่จะถูกแปลงโดยใช้ Appointment.load เมธอด.
  2. สร้างใหม่ MailMessage อ็อบเจ็กต์เพื่อเก็บข้อมูลปฏิทิน.
  3. เพิ่มการนัดหมายจากไฟล์ ICA ไปยัง EML เป็นมุมมองเพิ่มเติมโดยใช้ requestApointment() เมธอด.
  4. บันทึกไฟล์ EML พร้อมข้อมูลที่แปลงแล้วโดยใช้ บันทึก เมธอดพร้อม EmlSaveOptions ระบุประเภทการบันทึกเป็น EmlFormat.
// Load the ICS file to be converted
Appointment ics = Appointment.load("My File.ics");
// Create an EML
MailMessage eml = new MailMessage();
// Add the appointment to the EML
eml.addAlternateView(ics.requestApointment());
// Save the EML
eml.save("Saved File.eml", new EmlSaveOptions(MailMessageSaveType.getEmlFormat()));

แปลง ICS เป็น EMLX

เพื่อแปลงไฟล์ ICS เป็นรูปแบบ EMLX ให้ทำตามคำแนะนำจาก แปลง ICS เป็น EML ส่วนและบันทึกไฟล์ .emlx ตามบรรทัดโค้ดต่อไปนี้:

Appointment ics = Appointment.load("My File.ics");
MailMessage eml = new MailMessage();
eml.addAlternateView(ics.requestApointment());

// Save as an EMLX
eml.save("Saved File.emlx", new EmlSaveOptions(MailMessageSaveType.getEmlxFormat()));

แปลง ICS เป็น HTML

ตัวอย่างโค้ดต่อไปนี้แสดงกระบวนการแปลง:

  1. โหลดไฟล์ ICS ที่จะถูกแปลงโดยใช้ Appointment.load เมธอด.
  2. สร้างใหม่ MailMessage อ็อบเจ็กต์เพื่อเก็บข้อมูลปฏิทิน.
  3. เพิ่มการนัดหมายจากไฟล์ ICA ไปยัง EML เป็นมุมมองเพิ่มเติมโดยใช้ requestApointment() เมธอด.
  4. บันทึกไฟล์ EML พร้อมข้อมูลที่แปลงแล้วโดยใช้ บันทึก เมธอดพร้อม HtmlSaveOptions เพื่อระบุออพชันการจัดรูปแบบสำหรับไฟล์ HTML ที่บันทึก ในกรณีนี้ HtmlFormatOptions.WriteHeader ใช้เพื่อรวมส่วนหัว HTML ในไฟล์ผลลัพธ์ ขณะเดียวกัน HtmlFormatOptions.RenderCalendarEvent ใช้เพื่อแสดงเหตุการณ์ปฏิทินใด ๆ ที่อยู่ในข้อความ EML ในรูปแบบที่เหมาะสำหรับการแสดงผล.
// Load the ICS file to be converted
Appointment ics = Appointment.load("My File.ics");
// Create an EML
MailMessage eml = new MailMessage();
// Add the appointment to the EML
eml.addAlternateView(ics.requestApointment());

// Save the EML as HTML
HtmlSaveOptions htmlSaveOptions = new HtmlSaveOptions();
htmlSaveOptions.setHtmlFormatOptions(HtmlFormatOptions.WriteHeader | HtmlFormatOptions.RenderCalendarEvent);
eml.save("Saved File.html", htmlSaveOptions);

ใช้ค่าอื่นของ HtmlFormatOptions enumeration และคุณสมบัติของ HtmlSaveOptions คลาสเพื่อกำหนดตัวเลือกรูปแบบตามต้องการ.

แปลง ICS เป็น MBOX

ตัวอย่างโค้ดต่อไปนี้แสดงกระบวนการแปลงจาก ICS ไปเป็น MBOX โดยโหลดไฟล์ ICE, สร้างข้อความ EML, เพิ่มรายละเอียดการนัดหมายจากไฟล์ ICE ไปยังข้อความ EML, และจากนั้นเขียนข้อความ EML ไปยังไฟล์ที่เก็บข้อมูล MBOX.

  1. โหลดไฟล์ ICS ที่จะถูกแปลงโดยใช้ Appointment.load เมธอด.
  2. สร้างใหม่ MailMessage อ็อบเจ็กต์เพื่อเก็บข้อมูลปฏิทิน.
  3. เพิ่มการนัดหมายจากไฟล์ ICA ไปยัง EML เป็นมุมมองเพิ่มเติมโดยใช้ requestApointment() เมธอด.
  4. สร้างใหม่ MboxrdStorageWriter อ็อบเจ็กต์.
  5. เพิ่มข้อความ EML ไปยังที่เก็บโดยเขียนเนื้อหาข้อความในรูปแบบ MBOX ไปยังไฟล์ MBOX ที่ระบุ
// Load the ICS file to be converted
Appointment ics = Appointment.load("My File.ics");
// Create an EML
MailMessage eml = new MailMessage();
// Add the appointment to the EML
eml.addAlternateView(ics.requestApointment());

// Create an MBOX storage and add the EML to it
try (MboxrdStorageWriter mboxStorage = new MboxrdStorageWriter("Saved File.mbox", new MboxSaveOptions())) {
    mboxStorage.writeMessage(eml);
}

แปลง ICS เป็น MHTML

ตัวอย่างโค้ดต่อไปนี้แสดงขั้นตอนทั้งหมดของกระบวนการแปลง:

  1. โหลดไฟล์ ICS ที่จะถูกแปลงโดยใช้ Appointment.load เมธอด.
  2. สร้างใหม่ MailMessage อ็อบเจ็กต์เพื่อเก็บข้อมูลที่แปลงแล้ว.
  3. เพิ่มการนัดหมายจากไฟล์ ICA ไปยัง EML เป็นมุมมองเพิ่มเติมโดยใช้ requestApointment() เมธอด.
  4. บันทึกไฟล์ EML พร้อมข้อมูลที่แปลงแล้วโดยใช้ บันทึก เมธอดพร้อม MhtSaveOptions เพื่อระบุออพชันการบันทึกสำหรับไฟล์ MHTML ในกรณีนี้ MhtFormatOptions.WriteHeader ใช้เพื่อรวมส่วนหัวของข้อความอีเมลในไฟล์ผลลัพธ์ ขณะเดียวกัน MhtFormatOptions.RenderCalendarEvent ใช้เพื่อแสดงเหตุการณ์ปฏิทินใด ๆ ที่อยู่ในข้อความ EML ในรูปแบบที่เหมาะสำหรับการแสดงผล.
// Load the ICS file to be converted
Appointment ics = Appointment.load("My File.ics");
// Create an EML
MailMessage eml = new MailMessage();
// Add the appointment to the EML
eml.addAlternateView(ics.requestApointment());

// Save the EML as MHTML
MhtSaveOptions mhtSaveOptions = new MhtSaveOptions();
mhtSaveOptions.setMhtFormatOptions(MhtFormatOptions.WriteHeader | MhtFormatOptions.RenderCalendarEvent);
eml.save("Saved File.mht", mhtSaveOptions);

วิธีการนี้ทำให้มั่นใจว่าไฟล์ MHTML ที่แปลงแล้วจะคงรายละเอียดเหตุการณ์ปฏิทินและรูปแบบไว้ ทำให้การแชร์และการดูบนแพลตฟอร์มและไคลเอนต์อีเมลต่าง ๆ มีประสิทธิภาพ.

ใช้ค่าอื่นของ MhtFormatOptions enumeration และคุณสมบัติของ MhtSaveOptions คลาสเพื่อกำหนดตัวเลือกรูปแบบตามต้องการ.

แปลงไฟล์ ICS เป็น MSG

การแปลงไฟล์ ICS (iCalendar) เป็นรูปแบบ MSG มีความสมเหตุสมผลเพื่อความเข้ากันได้กับ Microsoft Outlook เนื่องจากไฟล์ MSG ใช้เก็บอีเมล, นัดหมายและข้อมูล Outlook อื่น ๆ ตัวอย่างโค้ดต่อไปนี้แสดงวิธีโหลดไฟล์ ICS และบันทึกเป็นไฟล์ MSG โดยไม่สูญเสียข้อมูลหรือการจัดรูปแบบ:

  1. โหลดไฟล์ ICS ด้วย Appointment.load และสร้าง Appointment อ็อบเจ็กต์จากข้อมูลปฏิทินที่เก็บไว้ในไฟล์.
  2. เรียกใช้ save เมธอดบนอ็อบเจ็กต์ Appointment เพื่อแปลงและบันทึกข้อมูลนัดหมายที่โหลดจากไฟล์ ICS ไปยังไฟล์ MSG ที่ตำแหน่งที่ระบุ.
// Load the ICS file to be converted and save it as an MSG
Appointment.load("My File.ics").save("Saved File.msg", AppointmentSaveFormat.Msg);

แปลง ICS เป็น OFT

กระบวนการนี้รวมถึงการโหลดไฟล์ ICS และบันทึกเป็นไฟล์ MSG พร้อมการแปลงต่อเป็นรูปแบบ OFT:

  1. สร้างอ็อบเจ็กต์สตรีมใหม่เพื่อจัดเก็บข้อมูลนัดหมายในหน่วยความจำ.
  2. โหลดข้อมูลนัดหมายจากไฟล์ ICS บันทึกข้อมูลนัดหมายไปยังอ็อบเจกต์สตรีมในรูปแบบ MSG โดยใช้ save() เมธอด.
  3. โหลดข้อมูลนัดหมายจากสตรีมโดยสร้างอ็อบเจ็กต์ MapiMessage ใหม่โดยใช้ MapiMessage.load() เมธอด.
  4. บันทึกข้อมูล MapiMessage ที่โหลดเป็นไฟล์เทมเพลต Outlook โดยใช้ save() เมธอดพร้อมกับ SaveOptions.getDefaultOft() ตัวเลือกรูปแบบ
// Load the ICS file to be converted and save it as an MSG into a stream
ByteArrayOutputStream msgStream = new ByteArrayOutputStream();
Appointment.load("My File.ics").save(msgStream, AppointmentSaveFormat.Msg);

// Save the MSG as an OFT
MapiMessage.load(new ByteArrayInputStream(msgStream.toByteArray()))
        .save("Saved File.oft", SaveOptions.getDefaultOft());

แปลง ICS เป็น OST

Aspose.Email มีฟังก์ชันการโหลดไฟล์ ICS, บันทึกเป็นไฟล์ MSG, จากนั้นเปิดไฟล์ OST, เข้าถึงโฟลเดอร์ปฏิทินภายในไฟล์ และง่ายต่อการเพิ่มไฟล์ MSG ไปยังโฟลเดอร์ปฏิทิน:

  1. สร้างสตรีมเพื่อจัดเก็บข้อมูลนัดหมาย
  2. โหลดข้อมูลนัดหมายจากไฟล์ ICS โดยใช้ Appointment.load() เมธอดและบันทึกลงสตรีมในรูปแบบ MSG พร้อม save เมธอด.
  3. โหลดไฟล์ personal storage ด้วย fromFile เมธอดของ PersonalStorage คลาส ส่งค่า true เป็นอาร์กิวเมนต์ที่สองเพื่อเปิดที่เก็บสำหรับเขียน
  4. ดึงโฟลเดอร์ปฏิทินจากไฟล์ personal storage ด้วย getPredefinedFolder เมธอด.
  5. ใช้ addMessage เมธอดเพื่อเพิ่มข้อความนัดหมายไปยังโฟลเดอร์ปฏิทินในไฟล์ OST
// Load the ICS file to be converted and save it as an MSG into a stream
ByteArrayOutputStream msgStream = new ByteArrayOutputStream();
Appointment.load("My File.ics").save(msgStream, AppointmentSaveFormat.Msg);

// Open an OST file
try (PersonalStorage pst = PersonalStorage.fromFile("Saved File.ost", true)) {
    // Get the calendar folder
    FolderInfo calendarFolder = pst.getPredefinedFolder(StandardIpmFolder.Appointments);
    // Add the MSG to the calendar folder
    calendarFolder.addMessage(MapiMessage.load(new ByteArrayInputStream(msgStream.toByteArray())));
}

แปลง ICS เป็น PST

ตัวอย่างโค้ดต่อไปนี้แสดงกระบวนการแปลง:

  1. สร้างสตรีมเพื่อเก็บข้อมูลนัดหมาย
  2. โหลดข้อมูลนัดหมายจากไฟล์ ICS โดยใช้ Appointment.load() เมธอดและบันทึกลงสตรีมในรูปแบบ MSG พร้อม save เมธอด.
  3. สร้างไฟล์ PST ใหม่พร้อมชื่อไฟล์โดยใช้ PersonalStorage.create เมธอด.
  4. สร้างโฟลเดอร์ปฏิทินภายในไฟล์ PST เพื่อเก็บนัดหมายโดยใช้ createPredefinedFolder เมธอด.
  5. เพิ่มข้อความนัดหมายไปยังโฟลเดอร์ปฏิทินภายในไฟล์ PST โดยใช้ addMessage เมธอด.
// Load the ICS file to be converted and save it as an MSG into a stream
ByteArrayOutputStream msgStream = new ByteArrayOutputStream();
Appointment.load("My File.ics").save(msgStream, AppointmentSaveFormat.Msg);

// Create a PST file
try (PersonalStorage pst = PersonalStorage.create("Saved File.pst", FileFormatVersion.Unicode)) {
    // Create a calendar folder
    FolderInfo calendarFolder = pst.createPredefinedFolder("Calendar", StandardIpmFolder.Appointments);
    // Add the MSG to the calendar folder
    calendarFolder.addMessage(MapiMessage.load(new ByteArrayInputStream(msgStream.toByteArray())));
}