---
title: "How do I programmatically close an InfoPath form in C#?"  
description: "How do I programmatically close an InfoPath form in C#?"  
author: "Anonymous User"  
published: 2013-11-14  
updated: 2013-11-14  
canonical: https://www.mindstick.com/forum/1736/how-do-i-programmatically-close-an-infopath-form-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# How do I programmatically close an InfoPath form in C#?

Is it possible to [close](https://yourviews.mindstick.com/story/1687/rubbing-hands-close-up-benefits) an InfoPath [form](https://www.mindstick.com/forum/6/multi-form-mfc-application) programmatically? I know that it can be configured as a form [rule](https://www.mindstick.com/interview/1715/describe-the-rules-in-style-sheets) [action](https://www.mindstick.com/forum/155752/what-is-action-result-with-its-types) but I want to close the form via [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii)

## Replies

### Reply by Anonymous User

Hi Goti,

Use the ApplicationClass.XDocuments.Close method and pass it your document object:

```
using System;using Microsoft.Office.Interop.InfoPath;namespace ConsoleApplication1{    class Program    {        static void Main(string[] args)        {            var app = new ApplicationClass();            var uri = @".\form1.xml";            var doc = app.XDocuments.Open(uri, 0);           
app.XDocuments.Close(doc);        }    }}
```


---

Original Source: https://www.mindstick.com/forum/1736/how-do-i-programmatically-close-an-infopath-form-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
