Options

Documents.Open method: Problem with optional parameters

code_eatercode_eater Member Posts: 5
Hi
I want to open a word document, using .NET variables. Documentation for the command is here:
https://msdn.microsoft.com/de-de/library/microsoft.office.interop.word.documents.open(v=office.11).aspx
Document Open(
	[In] ref object FileName, 
	[In, Optional] ref object ConfirmConversions, 
	[In, Optional] ref object ReadOnly, 
	[In, Optional] ref object AddToRecentFiles, 
	[In, Optional] ref object PasswordDocument, 
	[In, Optional] ref object PasswordTemplate, 
	[In, Optional] ref object Revert, 
	[In, Optional] ref object WritePasswordDocument, 
	[In, Optional] ref object WritePasswordTemplate, 
	[In, Optional] ref object Format, 
	[In, Optional] ref object Encoding, 
	[In, Optional] ref object Visible, 
	[In, Optional] ref object OpenAndRepair, 
	[In, Optional] ref object DocumentDirection, 
	[In, Optional] ref object NoEncodingDialog, 
	[In, Optional] ref object XMLTransform
);

As you can see there, the command has a lot of optional parameters. The parameters are all of type "Object".
Has somebody an idea how to use such a function from C/AL without using all parameters or how to use placeholders?

Thx in advance
Thomas


Comments

  • cwhmycwhmy Member Posts: 24
    Old thread but no answer, any idea, anybody? TQ
  • vaprogvaprog Member Posts: 1,156
    edited 2016-08-18
    I did not look any closer at the description of the function, but can you pass null values for those parameters you're not interested in?

    See #8 at Vjeko's blog post Top 10 things I miss in .NET Interoperability in NAV 2013
  • cwhmycwhmy Member Posts: 24
    Hi vaprog, with variable leaving nothing assigned in or something assigned doesn't make it work.
  • ShakoofterShakoofter Member Posts: 1
    For any poor souls that find this and were stuck like I was, if you're using Powershell, you can't use $null like you might think. Instead you have to use:

    $missing = [System.Reflection.Missing]::Value

    And substitute $missing where you would normally put $null.
Sign In or Register to comment.