/// <summary> /// Picks the outlook folder path. /// </summary> /// <param name="oApp">The o app.</param> /// <param name="oItemType">Type of the o item.</param> /// <returns></returns> public static string PickOutlookFolderPath(Outlook._Application oApp, Outlook.OlItemType oItemType) { string retVal = null; bool correctFolderSelected = false; try { while (!correctFolderSelected) { Outlook.NameSpace oNameSpace = oApp.GetNamespace("MAPI"); Outlook.MAPIFolder oMapiFolder = oNameSpace.PickFolder(); if (oMapiFolder.DefaultItemType != oItemType) { DebugAssistant.Log(DebugSeverity.Error | DebugSeverity.MessageBox, Resources.ERR_OUTLOOK_BAD_FOLDER_TYPE, oItemType); continue; } correctFolderSelected = true; retVal = oMapiFolder.Name; while (oMapiFolder.Parent is Outlook.MAPIFolder) { oMapiFolder = (Outlook.MAPIFolder)oMapiFolder.Parent; retVal = string.Format("{0}/", oMapiFolder.Name) + retVal; } retVal = "//" + retVal; } } catch (Exception e) { DebugAssistant.Log(DebugSeverity.Debug, e.Message); DebugAssistant.Log(DebugSeverity.Debug | DebugSeverity.MessageBox, Resources.DBG_OUTLOOK_FOLDER_NOT_SELECTED); } return(retVal); }
private void BtAgregar_Click(object sender, EventArgs e) { { if (CapaEntidad.Boton.Btn) { try { string rpta = ""; if (this.CbNombre.Text == string.Empty || this.DtFecha.Text == string.Empty || this.CbElectrico.Text == string.Empty) { MensajeError("Falta ingresar datos, Los datos con * son Obligatorios"); } else { //System.IO.MemoryStream ms = new System.IO.MemoryStream(); //this.PbFolio.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); //byte[] image = ms.GetBuffer(); FileStream pdf = File.OpenRead(ruta); byte[] contenidoPdf = new byte[pdf.Length]; pdf.Read(contenidoPdf, 0, (int)pdf.Length); pdf.Close(); rpta = NAgInspeccion.Editar(Convert.ToInt32(this.LbID.Text), Convert.ToInt16(this.CbNombre.SelectedValue), Convert.ToInt32(this.CbElectrico.SelectedValue), Convert.ToDateTime(this.DtFecha.Value), contenidoPdf); if (rpta.Equals("OK")) { this.MensajeOk("Se Modificó el registro correctamente"); } else { this.MensajeError(rpta); } } } catch (System.Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace); } } else { try { string rpta = ""; if (this.CbNombre.Text == string.Empty || this.DtFecha.Text == string.Empty || this.CbElectrico.Text == string.Empty) { MensajeError("Falta ingresar datos, Los datos con * son Obligatorios"); } else { //System.IO.MemoryStream ms = new System.IO.MemoryStream(); ////System.IO.MemoryStream ms2 = new System.IO.MemoryStream(); //this.PbFolio.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); FileStream pdf = File.OpenRead(ruta); byte[] contenidoPdf = new byte[pdf.Length]; pdf.Read(contenidoPdf, 0, (int)pdf.Length); pdf.Close(); //byte[] image = ms.GetBuffer(); rpta = NAgInspeccion.Agregar(Convert.ToInt16(this.CbNombre.SelectedValue), Convert.ToInt32(this.CbElectrico.SelectedValue), Convert.ToDateTime(this.DtFecha.Value), contenidoPdf); if (this.CkOutlook.Checked == true) { // usar el objeto de outlook para crear el recordatorio Outlook._Application App = (Outlook._Application) new Outlook.Application(); Outlook._AppointmentItem apt = (Outlook._AppointmentItem) App.CreateItem(Outlook.OlItemType.olAppointmentItem); // algunas propiedades apt.Subject = "Inspeccion obra" + this.CbNombre.Text; apt.Body = "reminderComment"; apt.Start = this.DtFecha.Value; apt.End = this.DtFecha.Value.AddHours(6); apt.ReminderMinutesBeforeStart = 1; apt.BusyStatus = Outlook.OlBusyStatus.olTentative; apt.AllDayEvent = false; apt.Save(); } if (rpta.Equals("OK")) { this.MensajeOk("Se Agregó el registro correctamente"); } else { this.MensajeError(rpta); } } } catch (System.Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace); } } } }
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) { switch (e.Button.Text) { case "Send": Outlook._Application outlookApp = null; Outlook._MailItem newMail = null; Outlook.Recipient recipient = null; Outlook.Recipients recipients = null; Type olType = Type.GetTypeFromProgID("Outlook.Application", false); if (olType != null) { try { outlookApp = Marshal.GetActiveObject("Outlook.Application") as Outlook._Application; } catch { } try { if (outlookApp == null) { outlookApp = Activator.CreateInstance(olType) as Outlook._Application; } } catch { } if (outlookApp != null) { if (tbtnMode.Pushed) { securityManager1.ConnectTo(outlookApp); securityManager1.DisableOOMWarnings = true; } try { newMail = outlookApp.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem; if (newMail != null) { try { recipients = newMail.Recipients; if (recipients != null) { try { if (txbTO.Text != string.Empty) { recipient = recipients.Add(txbTO.Text); if (recipient != null) { try { recipient.Type = (int)Outlook.OlMailRecipientType.olTo; recipient.Resolve(); } finally { Marshal.ReleaseComObject(recipient); } } } if (txbCC.Text != string.Empty) { recipient = recipients.Add(txbCC.Text); if (recipient != null) { try { recipient.Type = (int)Outlook.OlMailRecipientType.olCC; recipient.Resolve(); } finally { Marshal.ReleaseComObject(recipient); } } } if (txbBCC.Text != string.Empty) { recipient = recipients.Add(txbBCC.Text); if (recipient != null) { try { recipient.Type = (int)Outlook.OlMailRecipientType.olBCC; recipient.Resolve(); } finally { Marshal.ReleaseComObject(recipient); } } } newMail.Subject = txbSubject.Text; newMail.Body = txbMail.Text; newMail.Send(); } finally { Marshal.ReleaseComObject(recipients); } } Marshal.ReleaseComObject(newMail); newMail = null; MessageBox.Show("The message has been sent successfully.", "Send Mail", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception err) { if (newMail != null) { Marshal.ReleaseComObject(newMail); } MessageBox.Show(err.Message, err.Source, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } finally { if (tbtnMode.Pushed) { securityManager1.DisableOOMWarnings = false; securityManager1.Disconnect(outlookApp); } if (outlookApp != null) { Marshal.ReleaseComObject(outlookApp); } } } } break; case "Security": if (tbtnMode.Pushed) { tbtnMode.ImageIndex = 2; } else { tbtnMode.ImageIndex = 1; } break; } }