We recommend using Visual Studio 2017

FormTemplate.OpenFileFromPackage Method (Microsoft.Office.InfoPath)

Opens a file contained within the form template (.xsn) file.

Namespace: Microsoft.Office.InfoPath
Assembly: Microsoft.Office.InfoPath (in microsoft.office.infopath.dll)

public abstract Stream OpenFileFromPackage (
	string filename



The name of the file to open.

Return Value

The specified file as a Stream object.

Exception typeCondition


An I/O error, such as file not found.


The parameter passed to this method is null.


The parameter passed to this method isnot valid. For example, it is of the wrong type or format.

This member can be accessed only by forms running in the same domain as the currently open form, or by forms that have been granted cross-domain permissions.

This type or member can be accessed from code running in forms opened in Microsoft Office InfoPath 2007 or in a Web browser.