How to hide and show outlook calendars on another computer - properties

On my computer with office 2016 64bit I am able to use http://schemas.microsoft.com/mapi/proptag/0x10F4000B to hide an outlook calendar. But when the app runs from my test computer (office 2013 23 bit) the code just breaks and it stops execution without raising an error
Maybe the proptags are office version dependent? Do you know how to handle this problem?
the actual code is:
`
outlookApp = Globals.ThisAddIn.Application;
primaryCalendar = (Outlook.MAPIFolder)
Globals.ThisAddIn.Application.ActiveExplorer().Session.GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderCalendar);
Outlook.MAPIFolder setcalendar = primaryCalendar.Folders["mycal"];
Outlook.PropertyAccessor propertyaccesor = (Outlook.PropertyAccessor)setcalendar.PropertyAccessor;
string stringprop = "http://schemas.microsoft.com/mapi/proptag/0x10F4000B";
bool bHidden = propertyaccesor.GetProperty(stringprop);
propertyaccesor.SetProperty(stringprop, false);`

Related

Excplicit conversion from object to Outlook.AppointmentItem or Outlook.MailItem (VB.NET)

I need to send an Outlook appointment using UiPath studio. I've got a VB code creating appointment, but UiPath is not a great IDE unfortunatelly.
My code looks like this:
Dim app As Microsoft.Office.Interop.Outlook.Application = New
Microsoft.Office.Interop.Outlook.Application
Dim tmpapp As Microsoft.Office.Interop.Outlook.AppointmentItem =
app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem)
tmpapp.Subject = "Testing Appointment"
tmpapp.Body = "Siema siema"
tmpapp.Location = "tutej"
tmpapp.Start = Convert.ToDateTime("10.06.2019 23:33:12")
tmpapp.End = Convert.ToDateTime("10.06.2019 23:35:13")
tmpapp.ReminderSet = True
tmpapp.ReminderMinutesBeforeStart = 10
But i receive a compiling error:
Option Strict On disallows implicit conversions from ‘Object’ to ‘Microsoft.Office.Interop.Outlook.AppointmentItem’.
At line 3
As much as I would like to, I cannot set Option Strict Off. It is just not possible.
Do you know how can I convert it explicitly?
Thank you in advance!

How to open Outlook 2016 with vs2017

I've on my computer Office 2013 32bits. I develop an Intranet but on server and windows session of my customer : it's an Office 2016 32bits...
On my vs2017 I install with nugget package microsoft.office.interop 15.0.4797.1003 But it's for Office 2013.
I create mail with
dim outl as new outlook.application
dim Mai las outl.mailitem=outl.createItem(Micrososft.office.Interop.outlook.olitemtype.olmailItem)
Mail.To=...
...
Mail.attachment.add(MyFile)
Mail.display()
I try to put my code on the customer server, and like I thougth ... 80070005 Access denied...
I don't find how to open an Outlook 2016
Thanks for your help
UPDATE
On Property of my project, I've "Any CPU" option activate
Finally...
A friend says me, my method can be ok only If I open session on server. outlook.display run on server not on clientside on other computer.
Then I change my mind and build a emml file, store and push with ashx file
For Each _file As String In IO.Directory.GetFiles(IO.Path.GetDirectoryName(Path), "*.eml")
IO.File.Delete(_file)
Next
Dim MailMdp As New Net.Mail.MailMessage
MailMdp.Subject = Vers.Devi.Libelle
MailMdp.From = New Net.Mail.MailAddress(ConnectedUser.Mail)
MailMdp.To.Add(AnAdress)
MailMdp.Body = "Bonjour,"
Dim att As New Net.Mail.Attachment(Path)
MailMdp.Attachments.Add(att)
MailMdp.IsBodyHtml = True
Dim Client As Net.Mail.SmtpClient = New Net.Mail.SmtpClient()
Client.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.SpecifiedPickupDirectory
Client.PickupDirectoryLocation = IO.Path.GetDirectoryName(Path)
Client.Send(MailMdp)
Dim MonEml = IO.Directory.GetFiles(IO.Path.GetDirectoryName(Path), "*.eml", IO.SearchOption.TopDirectoryOnly).First
Dim fso As New System.IO.FileInfo(MonEml)
Dim NomFichier As String = fso.Name
context.Response.Clear()
context.Response.ClearContent()
context.Response.ClearHeaders()
context.Response.ContentType = "message/rfc822"
context.Response.AppendHeader("Content-Disposition", "attachment; filename=" & NomFichier)
context.Response.TransmitFile(MonEml)
context.Response.End()
I hope that can be helpfull

Previous Excel instance not getting through IIS

I am using VB.NET to open the Excel files but dont want to create excel object every time.
My code is working perfectly in debug mode, but after publish, it never gets the existing instances and always create new instances which we can see from Task Manager. Here is my code which always returns false in published mode.
My OS is Windows Server 2008. Please guide how to solve this.
Function IsExcelRunning() As Boolean
Dim xlApp As Excel.Application
On Error Resume Next
xlApp = GetObject(, "Excel.Application")
IsExcelRunning = (Err.Number = 0)
MyHelper.writeLog("Excel Instance found=" & IsExcelRunning)
xlApp = Nothing
Err.Clear()
End Function
Here is how I call.
If IsExcelRunning() Then
excelApp = GetObject(, "Excel.Application")
Else
excelApp = Server.CreateObject("Excel.Application")
End If
We used to use Excel Interop and I remember it always being difficult to work with (clunky.) Due to the Interop opening an Excel process and not closing it every time you use it, makes it difficult to work with.
The Interop opens Excel automatically, so all we needed to do was close it. This is what we used to use to kill the Process. Replace YourProcessName with Excel.exe.
Dim proc As System.Diagnostics.Process
Dim info As ManagementObject
Dim search As New ManagementObjectSearcher("SELECT ProcessId FROM Win32_process WHERE caption = 'YourProcessName'")
For Each info In search.Get()
Dim TheString As String = info.GetText(TextFormat.Mof).ToString
proc = System.Diagnostics.Process.GetProcessById(Mid$(TheString, _
(Len(TheString) - 8), 4))
proc.CloseMainWindow()
proc.Refresh()
If proc.HasExited Then GoTo NoKill
proc.Kill()
NoKill:
Next
You'll need to import
Imports System.Management
You'll also need to add the reference 'System.Management' to your project.
See: http://msdn.microsoft.com/en-us/library/vstudio/wkze6zky.aspx for adding a reference to a project.
If you can rather work with CSV, I would suggest you try to. If you are creating the Excel file yourself, try to find a report creator that let's you create / export to Excel. You'll save yourself a lot of time in the long run.

Silverlight application using vb.net. Issue creating new email in lotus notes

Im writing a silverlight application in vb.net and need to send an email via lotus notes. I wish to do this by opening the lotus notes client app, open a new email window and substitute all the necessary details (to, subject etc.) in the new email window. I am using the below code but it only OPENS the lotus notes application on the machine, it does not do anything past this. Its seems that everything after the initial CreateObject call is simply ignored, although it doesnt throw any errors. I have attempt to reference interops.domino.dll but being silverlight project visual studio states the dll is not compiled for the silverlight runtime. Any assistance with this would be greatly appreciated.
Dim outlook = AutomationFactory.CreateObject("Notes.NotesSession")
Dim notesdb = outlook.GetDatabase("", "")
notesdb.OpenMail()
Dim doc = notesdb.CreateDocument()
Dim msg = "Hey whats up"
doc.ReplaceItemValue("SendTo", "person#temp.com")
doc.ReplaceItemValue("Subject", "Hello")
Dim rtitem = doc.CreateRichTextItem("Body")
rtitem.AppendText(msg)
All you do in the moment is to create a new document in the backend and fill it with values.
It is like creating a word document without opening it...
You need some more code to actually SHOW the document you created.
In addition you need to assign a Form, otherwise Notes will not know, how to display this document:
Dim session = AutomationFactory.CreateObject("Notes.NotesSession")
Dim notesdb = outlook.GetDatabase("", "")
Dim ws = AutomationFactory.CreateObject("Notes.NotesUIWorkspace")
notesdb.OpenMail()
Dim doc = notesdb.CreateDocument()
Dim msg = "Hey whats up"
doc.ReplaceItemValue("Form", "Memo")
doc.ReplaceItemValue("SendTo", "person#temp.com")
doc.ReplaceItemValue("Subject", "Hello")
Dim rtitem = doc.CreateRichTextItem("Body")
rtitem.AppendText(msg)
ws.EditDocument( True, doc )
As I do not use silverlight I unfortunately could not test the code, but It should point into the right direction.
You can not do UI manipulations via COM in Notes, as the UI-Classes (NotesUIDocument, NotesUIWorkspace, ...) are not supported via COM.
You can only use the backend-classes likes NotesDocument, ...
This still leaves you a lot of possibilites, as you can eiter use NotesRichTextItem or MIMEEntity classes to compose e-mails.

SaveAs2 method still prompts! Why?

Context:
Vb.net program
Visual studio 2010 ultimate
MS Word 2010 automation
Microsoft.Office.Interop.Word library
I'm using the saveAs2 method to save a new document I'm creating but the application is still prompting me when I call the method. Why?
The application is not visible.
The application.displayAlerts is false
Any ideas guys?
Also, when I do complete the SaveUI prompt by hand, the saveAs2 method throws an exception.
Here's my code for people who asked for it :
Public Sub generateModel() Implements ModelGenerator.generateModel
wordApp.Visible = True
wordApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone
wordDoc = wordApp.Documents.Add
wordDoc.PageSetup.TopMargin = wordApp.InchesToPoints(0.25)
wordDoc.PageSetup.BottomMargin = wordApp.InchesToPoints(0.25)
wordDoc.PageSetup.LeftMargin = wordApp.InchesToPoints(0.25)
wordDoc.PageSetup.RightMargin = wordApp.InchesToPoints(0.25)
With wordDoc.Content.Paragraphs.Add(wordDoc.Bookmarks.Item("\endofdoc").Range)
.Range.Text = _text
.Format.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
.Format.LineUnitBefore = 1
.Range.Font.SmallCaps = True
.Range.Font.Size = 12
End With
Dim logo = wordDoc.Shapes.AddPicture(logoLoc)
logo.Height = wordApp.InchesToPoints(0.5)
logo.Width = wordApp.InchesToPoints(1.18)
Me.mainTable = wordDoc.Tables.Add(wordDoc.Bookmarks.Item("\endofdoc").Range, 3, 2)
mainTable.Rows.HeightRule = Word.WdRowHeightRule.wdRowHeightExactly
mainTable.Columns.Width = wordApp.InchesToPoints(4)
mainTable.Rows.Height = wordApp.InchesToPoints(3.25)
mainTable.Select()
wordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
With wordDoc.Content.Paragraphs.Add(wordDoc.Bookmarks.Item("\endofdoc").Range)
.Range.Text = "Rapport journalier de production - page 2"
.Range.Font.Size = 10
.Format.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
.Format.LineUnitBefore = 0
.Format.SpaceBeforeAuto = False
.Format.SpaceBefore = 0
End With
wordDoc.SaveAs2("C:\Doc1.docx")
wordDoc.Close(False)
wordApp.Application.Quit()
End Sub
**Update:
I tested the code on an other machine and it works. So I tried this code on mine:
Dim app As New Microsoft.Office.Interop.Word.Application
Dim doc = app.Documents.Add
doc.SaveAs2("C:\Users\simon\Documents\Doc3.docx")
And it still makes the saveUI pop up. I'm so confused...
Finally found the problem's source.
My Acer computer was installing an Add-in everytime I installed Word. Once I removed the Add-in from Word everything went back to normal.
The Add-in was the AcerCloud Add-in.
I just tried to create a sample implementation in C#, Word Interop API v.15 (Office 2013):
var wordApplication = new Application() { Visible = true };
var doc = wordApplication.Documents.Add();
doc.SaveAs2(#"C:\my.docx");
... and when you save to a location that requires admin permission (like on the root of the C:\ drive), Word Interop throws a System.Runtime.InteropServices.COMException saying that: "Word cannot save or create this file. Make sure that the disk you want to save the file on is not full, write-protected, or damaged."
Instead, you should save at a location where your application has the necessary write permissions, e.g., to your own user directory - then it should work as expected.