How to open Outlook 2016 with vs2017 - vb.net

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

Related

PowerShell remote call. Access is denied from webserver

i write a code for remote access for exchange powershell from asp.net application to enable remote mail using vb.net and exchange 2016
the command run successfully from my visual studio debug
but when i put in iis web server it's giving me
Connecting to remote server "" failed with the following error
message : Access is denied
this is is the code
Function enableRemoteEmail(ByVal samaccount As String, ByVal email As String) As String
Dim ServerUri As String = "http://{mailserver}/powershell"
Dim SchemaUri As String = "http://schemas.microsoft.com/powershell/Microsoft.Exchange"
Dim userName As String = AccountOperatorLogon
Dim password As New System.Security.SecureString
For Each x As Char In AccountOperatorPassword
password.AppendChar(x)
Next
Dim PSCredential As New PSCredential(userName, password)
Dim ConnectionInfo As WSManConnectionInfo = New WSManConnectionInfo(New Uri(ServerUri), SchemaUri, PSCredential)
ConnectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic
Dim RemoteRunspace As Runspace = RunspaceFactory.CreateRunspace(ConnectionInfo)
Dim RemotePowerShell As PowerShell = PowerShell.Create
RemotePowerShell.AddCommand("Enable-RemoteMailbox")
RemotePowerShell.AddParameter("Identity", samaccount)
RemotePowerShell.AddParameter("RemoteRoutingAddress",email )
RemotePowerShell.AddParameter("Credential", PSCredential)
' Open the remote runspace on the server.
RemoteRunspace.Open()
' Associate the runspace with the Exchange Management Shell.
RemotePowerShell.Runspace = RemoteRunspace
Dim TheResult As Collection(Of PSObject)
Dim TheResultString As String = ""
TheResult = RemotePowerShell.Invoke
For Each RSLT As PSObject In TheResult
TheResultString += RSLT.ToString() + "<br/>"
Next
RemoteRunspace.Close()
' Invoke the Exchange Management Shell to run the command.
Return TheResultString
End Function
i found the solution for anyone have the same problem
create user as a member of (Recipient Management group)
IIS change (for exchange server) navigate to IIS Manager | Default Website | PowerShell Change the physical path from: C:\Program Files\Microsoft\Exchange Server\V15\FrontEnd\HttpProxy\PowerShell to: C:\Program Files\Microsoft\Exchange Server\V15\ClientAccess\PowerShell
3.After the change: IISRESET
and it will work fine

Need help getting Registry.GetValue to work correctly

I have a simple setup project that is no longer working and it seems like a windows update is the cause. I am using Visual Studio 2010 on Windows 7. The project is 64bit. It still works on some computers but it does not work on any computers that have had updates recently.
Here is the original code:
Dim appPath As String = Registry.GetValue("HKEY_CURRENT_USER\SOFTWARE\Our Company Inc.\SoftwareName.exe", "Path", "Not Found")
appPath &= "Colorbar.col"
Dim sid : sid = "S-1-1-0"
Dim objWMI : objWMI = GetObject("winmgmts://./root\cimv2")
Dim objSID : objSID = objWMI.Get("Win32_SID='" & sid & "'")
Dim userAccount As String = objSID.AccountName
Dim fileInfo As IO.FileInfo = New IO.FileInfo(appPath)
Dim fileAcl As New FileSecurity
fileAcl.AddAccessRule(New FileSystemAccessRule(userAccount, FileSystemRights.FullControl, AccessControlType.Allow))
fileInfo.SetAccessControl(fileAcl)
I have put the key value pair of "Path" and "[TARGETDIR]" in the registry editor and have the output from this installer class (the code above) in the Install and Commit custom actions.
This code that used to work now returns "Exception has been thrown by the target of an invocation -> C:\Windows\SYSWOW64\Colorbar.col"
I have checked the registry when this message appears and the path is correct so I don't know where SYSWOW64 is coming from.
I have tried to change getting the appPath using this code:
Dim regKey As RegistryKey = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64)
regKey = regKey.OpenSubKey("SOFTWARE\Our Company Inc.\SoftwareName.exe")
Dim appPath As String = regKey.GetValue("Path").ToString
This returns an "Object reference not set to an instance of an object" error.
I have made a test Windows Form application and put both versions of code in a button event. Everything works as expected. Any ideas why the code does not work in a setup project anymore and what I can do to get it working again?
Thanks in advance.
Finally have it working again. I got around using the registry by using the custom action's CustomActionData and setting it to:
/name="[TARGETDIR]\"
I was then able to access it in my installer class by using this line of code:
Dim appPath As String = Context.Parameters.Item("name")
Once the path was set, everything else worked as expected. The final code looks like this:
Public Overrides Sub Commit(ByVal stateSaver As System.Collections.IDictionary)
MyBase.Commit(stateSaver)
Dim appPath As String = Context.Parameters.Item("name")
appPath = appPath.Remove(appPath.Length - 1)
appPath &= "Colorbar.col"
Dim sid : sid = "S-1-1-0"
Dim objWMI : objWMI = GetObject("winmgmts://./root\cimv2")
Dim objSID : objSID = objWMI.Get("Win32_SID='" & sid & "'")
Dim userAccount As String = objSID.AccountName
Dim fileInfo As IO.FileInfo = New IO.FileInfo(appPath)
Dim fileAcl As New FileSecurity
fileAcl.AddAccessRule(New FileSystemAccessRule(userAccount, FileSystemRights.FullControl, AccessControlType.Allow))
fileInfo.SetAccessControl(fileAcl)
End Sub

How to save changes to app.config file from runtime for a Visual Studio Add-In

Thanks to Is there a config type file for Visual Studio Add-In? I was able to create an app.config file for the Visual Studio add-in I am developing with the ability to read/write to it.
Now I am having trouble saving the changes made to it at runtime. I have been running the following test code, but when I look the app.config file after running in debug, nothing has changed.
Dim pluginAssemblyPath As String = Assembly.GetExecutingAssembly().Location
Dim configuration As Configuration = ConfigurationManager.OpenExeConfiguration(pluginAssemblyPath)
Dim test1 As String = configuration.AppSettings.Settings.Item("Key1").Value
configuration.AppSettings.Settings.Item("Key1").Value = "Is this thing on?"
Dim test3 As String = configuration.AppSettings.Settings.Item("Key1").Value
configuration.AppSettings.SectionInformation.ForceSave = True
configuration.Save(ConfigurationSaveMode.Modified)
Dim pluginAssemblyPath As String = Assembly.GetExecutingAssembly().Location
'Dim configuration As Configuration = ConfigurationManager.OpenExeConfiguration(pluginAssemblyPath)
Dim test1 As String = configuration.AppSettings.Settings.Item("Key1").Value
configuration.AppSettings.Settings.Item("Key1").Value = "Is this thing on?"
Dim test3 As String = configuration.AppSettings.Settings.Item("Key1").Value
configuration.AppSettings.SectionInformation.ForceSave = True
configuration.Save(ConfigurationSaveMode.Modified)
ConfigurationManager.RefreshSection("appSettings")
The actual app.config will not change, but the config file inside of the bin folder does.

VB.net express System.UnauthorizedAccessException

I am trying to write a file listing custom class in VB.net 2010 express on a Win7 64 bit machine. I installed VB.net express using an account that has administrator rights on both the machine and the network it belongs to. I should be able to access any file on the machine and from Windows Explorer, I can. I have been stopped cold by a “System.UnauthorizedAccessException”.
I have tried changing the manifest file. Although that should not be needed since the account already has full permissions. It has not worked. Below is a fragment of the offending code.
I am beginning to wonder if it is possible read the files on a drive using managed code. I can revert to the VBA class that in capsules ancient Win32 API calls that I wrote years ago but that violates the purpose of this exercise. Any suggestions would be appreciated.
Private Sub sLoadCatalog(ByVal strPath As String, ByVal intParentID As Integer)
'Get the file list
Dim strsearchPattern As String = "*"
Dim fp As New FileIOPermission(FileIOPermissionAccess.PathDiscovery _
Or FileIOPermissionAccess.Read, strPath)
Try
'fp.Demand()
fp.Assert()
Dim dirInfo As DirectoryInfo = New DirectoryInfo(strPath)
Dim FileList() As FileInfo = dirInfo.GetFiles()
If FileList.Length > 0 Then
… Loop through the file list and do something exciting
End If
Dim dirFolder() As DirectoryInfo = dirInfo.GetDirectories
If dirFolder.Length > 0 Then
… Loop through the folder list and do something exciting
sLoadCatalog(strfolder, intLastID)
Else
Exit Sub
End If
Catch e As SecurityException
MessageBox.Show("Security Cannot access folder " & strPath)
Catch k As UnauthorizedAccessException
MessageBox.Show("Unauthorized Cannot access folder " & strPath)
End Try

How to do Mailmerge in Openoffice using Vb.net

Its 5th Question and apart of one I didn't get response from the experts....
Hope this time I will get the helping hand.
I want to do mailmerge in openoffice using Vb.net and I am totally new with openoffice.
I searched on net for some help to understand how to use openoffice with vb.net but all I get is half info.....So can you please help me and give me code for mailmerge in vb.net for openoffice.
Well i have list of workers in DB and there is this facility that if they want to mail to all or some of the workers then they can do it.I have completed this task using Microsoft Office now as a Add in we are providing the facility to perform the same task using Open Office.
What they have to do is just select the List of workers and click on a button and it will automate the mailmerge using the field of those workers data from DB. The Code of mine is as shown below
Public Sub OpenOfficeMail(ByVal StrFilter As String)
Dim oSM ''Root object for accessing OpenOffice from VB
Dim oDesk, oDoc As Object ''First objects from the API
Dim arg(-1) ''Ignore it for the moment !
''Instanciate OOo : this line is mandatory with VB for OOo API
oSM = CreateObject("com.sun.star.ServiceManager")
''Create the first and most important service
oDesk = oSM.createInstance("com.sun.star.frame.Desktop")
''Create a new doc
oDoc = oDesk.loadComponentFromURL("private:factory/swriter", "_blank", 0, arg)
''Close the doc
oDoc.Close(True)
oDoc = Nothing
''Open an existing doc (pay attention to the syntax for first argument)
oDoc = oDesk.loadComponentFromURL("file:///C:\Users\Savan\Documents\1.odt", "_blank", 0, arg)
Dim t_OOo As Type
t_OOo = Type.GetTypeFromProgID("com.sun.star.ServiceManager")
Dim objServiceManager As New Object
objServiceManager = System.Activator.CreateInstance(t_OOo)
Dim oMailMerge As New Object
oMailMerge = t_OOo.InvokeMember("createInstance", Reflection.BindingFlags.InvokeMethod, Nothing, _
objServiceManager, New [Object]() {"com.sun.star.text.MailMerge"}) 'com.sun.star.text.MailMerge"})
oMailMerge.DocumentURL = "file:///C:\Users\Savan\Documents\1.odt"
oMailMerge.DataSourceName = CreateSource(StrFilter)''Function that will return the datasource name which will be a text file's path
oMailMerge.CommandType = 0
oMailMerge.Command = "file:///C:\Mail.txt"
oMailMerge.OutputType = 2
oMailMerge.execute(New [Object]() {})**---->I am getting Error here**
End Sub