private CalendarItem Map(Microsoft.Office.Interop.Outlook.AppointmentItem item) { var calItem = new CalendarItem() { End = item.End, Id = item.GlobalAppointmentID, ItemId = item.GlobalAppointmentID, Start = item.Start, Summary = item.Subject, Location = item.Location, Organizer = item.Organizer, Created = item.CreationTime, Description = item.Body, Attendees = item.Recipients.OfType<Microsoft.Office.Interop.Outlook.Recipient>().Select(x => new Attendee() { DisplayName = x.Name, Email = GetEmailOfRecipient(x), Optional = x.Type == 2 }).ToList(), Locked = true, Status = item.BusyStatus.ToString(), Reminders = new List<Reminder> { new Reminder { Method = "popup", Minutes = item.ReminderMinutesBeforeStart } }, //Recurrence = GetRecurrence(item), IsRecurring = item.IsRecurring, CalendarId = item.GlobalAppointmentID }; item.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olDiscard); return calItem; }
/// <summary> /// 释放内存 /// </summary> public void Dispose(Microsoft.Office.Interop.Excel._Worksheet CurSheet, Microsoft.Office.Interop.Excel._Workbook CurBook, Microsoft.Office.Interop.Excel._Application CurExcel) { try { System.Runtime.InteropServices.Marshal.ReleaseComObject(CurSheet); CurSheet = null; CurBook.Close(false, mValue, mValue); System.Runtime.InteropServices.Marshal.ReleaseComObject(CurBook); CurBook = null; CurExcel.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(CurExcel); CurExcel = null; GC.Collect(); GC.WaitForPendingFinalizers(); } catch (System.Exception ex) { // HttpContext.Current.Response.Write("在释放Excel内存空间时发生了一个错误:" + ex); } finally { foreach (System.Diagnostics.Process pro in System.Diagnostics.Process.GetProcessesByName("Excel")) //if (pro.StartTime < DateTime.Now) pro.Kill(); } System.GC.SuppressFinalize(this); }
private static void CloseThreadHandle(Microsoft.Win32.SafeHandles.SafeThreadHandle handle) { if (handle != null) { handle.Close(); } }
private void ReleaseObjects(Microsoft.Office.Interop.PowerPoint.Presentation _objPresentation, Application _objApplication) { GC.Collect(); GC.WaitForPendingFinalizers(); if (_objPresentation != null) { _objPresentation.Close(); //Marshal.FinalReleaseComObject(_objPresentation); } if (_objApplication != null) { _objApplication.Quit(); //Marshal.FinalReleaseComObject(_objApplication); } System.Diagnostics.Process[] pros = System.Diagnostics.Process.GetProcessesByName("POWERPNT"); for (int i = 0; i < pros.Length; i++) { pros[i].Kill(); } }
void CloseWorkBook(Microsoft.Office.Interop.Excel.Workbook ExcelWb, String TargetDirectory, String SaveName) { String ExcelFileName = Path.Combine(TargetDirectory, SaveName); if (File.Exists(ExcelFileName)) File.Delete(ExcelFileName); ExcelWb.SaveAs(ExcelFileName, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); ExcelWb.Close(Missing.Value, Missing.Value, Missing.Value); ExcelApplication.Quit(); ExcelWb = null; ExcelApplication = null; }
public void CloseReadWorkbook(Microsoft.Office.Interop.Excel.Workbook ExcelWb) { ExcelWb.Close(Missing.Value, Missing.Value, Missing.Value); ExcelApplication.Quit(); ExcelWb = null; ExcelApplication = null; }
private void ReleaseProcessHandle(Microsoft.Win32.SafeHandles.SafeProcessHandle handle) { if ((handle != null) && (!this.haveProcessHandle || (handle != this.m_processHandle))) { handle.Close(); } }
private void SaveDocument(Microsoft.Office.Interop.Word.Document wordDocument, Microsoft.Office.Interop.Word.ApplicationClass wordApp, string filePath) { object Visible = false; object missing = System.Reflection.Missing.Value; Object Nothing = System.Reflection.Missing.Value; object Save_FileName = filePath; //保存模板文件 wordDocument.SaveAs(ref Save_FileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref Visible, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); //关闭wordDoc文档对象 wordDocument.Close(ref Nothing, ref Nothing, ref Nothing); wordDocument = null; //关闭wordApp组件对象 wordApp.Quit(ref Nothing, ref Nothing, ref Nothing); }