Articles in this section
Category / Section

How to open generated Word using installed apps in Xamarin.iOS?

7 mins read

Syncfusion Essential DocIO is a Xamarin Word library used to create, read, and edit Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can create a Word document in Xamarin.iOS.

Steps to open generated Word using installed apps in Xamarin.iOS:

  1. Create a new C# Xamarin iOS application project.

Create Xamarin.iOS application in Visual Studio

  1. Select a project template, minimum iOS version, and device support for the application.

Select Xamarin.iOS project template and iOS version

  1. Install the Syncfusion.Xamarin.DocIO NuGet package as reference to your .NET Framework applications from NuGet.org.

Add DocIO NuGet package reference to the project

  1. In the project, add new UIViewController class.

Add new UIViewController class to the project

  1. In AppDelegate.cs, add the following code on FinishedLaunching() to load the UIViewController1 at top of the window.

C#

//Load the UIViewController for UI Window
Window.RootViewController = new UIViewController1();
  1. In UIViewController1.cs, add the following code in the ViewDidLoad() method to add the button in the UIView.

C#

var btn = UIButton.FromType(UIButtonType.System);
btn.Frame = new CoreGraphics.CGRect(20, 200, 280, 44);
btn.SetTitle("Generate Word Document", UIControlState.Normal);
btn.TouchUpInside += OnButtonClicked;
View.AddSubview(btn);
  1. Include the following namespace in the UIViewController1.cs file.

C#

using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using System.IO;
  1. In the click event method (OnButtonClicked), add the following code to open generated Word document using installed apps in Xamarin.iOS.

C#

// Create a new Word document
WordDocument document = new WordDocument();
//Add a section & a paragraph in the empty document
document.EnsureMinimal();
//Append text to the last paragraph of the document
document.LastParagraph.AppendText("Hello World");
 
string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string filePath = Path.Combine(path, "Sample.docx");
//Create a file and write the stream into it.
FileStream fileStream = File.Open(filePath, FileMode.Create);
//Saves the Word document
document.Save(fileStream, Syncfusion.DocIO.FormatType.Docx);
//Close the document
document.Close();
fileStream.Flush();
fileStream.Close();
 
UIDocumentInteractionController previewController = UIDocumentInteractionController.FromUrl(NSUrl.FromFilename(filePath));
previewController.Delegate = new InteractionDelegate(this);
previewController.PresentOptionsMenu(View.Frame, View, true);
  1. Add the InteractionDelegate class that inherits from UIDocumentInteractionControllerDelegate to enable previewing of file.

C#

public class InteractionDelegate : UIDocumentInteractionControllerDelegate
{
UIViewController parent;
 
public InteractionDelegate(UIViewController controller)
{
parent = controller;
}
public override UIViewController ViewControllerForPreview(UIDocumentInteractionController controller)
{
return parent;
}
}
  1. Compile and execute the application. Now, this application creates a simple Word document and shows a menu with apps installed in Xamarin.iOS to open the Word document.

A complete working sample can be downloaded from create and open Word file.zip

Take a moment to peruse the documentation, where you can find basic Word document processing options along with features like mail merge, merge and split documents, find and replace text in the Word document, and most importantly PDF conversions with code examples.

Explore more about the rich set of Syncfusion Word Framework features.

See Also:

Create Word document in Xamarin.iOS

Create Word document in Xamarin.Android

Create Word document in Xamarin

Create Word document in Windows Forms

Create Word document in WPF

Create Word document in ASP.NET Core

Create Word document in ASP.NET MVC

Note:

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied