Create OneNote (.ONE) Documents Programmatically in C#

Create OneNote File in C# 2

Aspose.Note for .NET is a feature-rich OneNote document manipulation API that lets you create, read, and convert OneNote documents programmatically using C# or VB.NET. In a previous article, we have covered how to use Aspose.Note for .NET to convert, read, and parse OneNote documents. Today, we’ll check out how to create OneNote documents from scratch using C#.

MS OneNote provides you a way of organizing and managing the information in the form of digital notes (.ONE). The pages in the OneNote documents are used to contain the user-defined content which may consist of text, tables, images, lists and etc. In this article, we’ll cover all the basic aspects of creating pages and their content in OneNote documents.

Create OneNote (.ONE) Document using C#

Let’s start by creating an empty OneNote document with a page title only. The following are the steps to create the OneNote document with an empty page and save it as .one file.

  • Create an instance of the Document class.
  • Create a new page by initializing the Page object with the Document class’s object.
  • Set page’s title using Page.Title property.
  • Call Document.AppendChild() method and pass the Page object.
  • Finally, save the OneNote document using Document.Save() method.

The following code sample shows how to create an empty OneNote document using C#.

Add Pages to OneNote Document using C#

In this section, we’ll go one step ahead and add text to the page in OneNote document. A page in the OneNote document can either be the main page or a subpage. For instance, you are creating an annual report which further contains the subsections for the monthly reports. In such a case, you can put the description of the report on the main page and the monthly reports on the subpages. In the OneNote document, this can be handled using the page levels.

The following are the steps to create pages in OneNote document.

  • Create a new OneNote document using Document class.
  • Create new pages for the document and set their level using Page class.
  • Use Outline and OutlineElement classes to create notes.
  • Add notes to the pages using Page.AppendChildLast() method.
  • Add pages to OneNote document using Document.AppendChildLast() method.
  • Save the document using Document.Save() method.

The following code sample shows how to create and add pages to OneNote documents using C#.

Insert Images to OneNote Document using C#

You can also insert images to the OneNote pages. The following are the steps to create a OneNote document having images.

  • Create an instance of Document class for a new OneNote document.
  • Use Page class to create a new page for the document.
  • Create a new instance of Image class and initialize it with the image’s path.
  • Add image to the page using OutlineElement.AppendChildLast() method.
  • Add page to the document using Document.AppendChildLast() method.
  • Save the OneNote document.

The following code sample shows how to insert images to the OneNote document using C#.

Add Tables to OneNote Document using C#

Tables are a fine way of organizing and summarizing the data in the form of rows and columns. Along with efficient organization, tables let you locate the desired data quickly. OneNote documents also support tables. The following are the steps to add tables in OneNote documents.

  • Create a new OneNote document using Document class.
  • Create a new page using Page class.
  • Add a new table row and table cells using TableRow and TableCell classes respectively.
  • Insert elements to the table cells using TableCell.AppendChildLast method.
  • Add cells to the table row using TableRow.AppendChildLast() method.
  • Create an instance of Table class and add table row to it.
  • Add the table to the page using OutlineElement and Outline classes.
  • Add page to the document and save the document using Document.Save() method.

The following code sample shows how to add a table to the OneNote document using C#.

Insert Tags in OneNote Document using C#

Tags are used to categorize or prioritize the notes in OneNote documents. You can apply tags to text or paragraph to quickly find or filter the related notes. The following are the steps to create and add tags in OneNote documents.

  • Create an instance of Document class.
  • Create a new page using Page class.
  • Initialize Outline and OutlineElement objects.
  • Create a new RichText object and set its text and other properties.
  • Add a tag to the text using RichText.Tags.Add() method.
  • Append text to the page.
  • Add page to the OneNote document and save it.

The following code sample shows how to add tags to text in OneNote documents using C#.

Last but not the least, let’s see how to insert hyperlinks to the OneNote documents using the following steps.

  • Create an instance of the Document class.
  • Create a new page for the document using Page class.
  • Set the text style of the hyperlink and its URL using the TextStyle class.
  • Create an instance of RichText class, add its text and initialize it with previously created text style for the hyperlink.
  • Add text to the page of the OneNote document.
  • Save the document as .one file.

The following code sample shows how to insert a hyperlink to the OneNote document using C#.

Conclusion

In this article, you have learned how to create OneNote (.ONE) documents from scratch using C#. Furthermore, the article also covered how to insert pages, images, tables, tags, and hyperlinks to the OneNote documents programmatically. You can explore the other interesting features of Aspose.Note for .NET using the documentation.

Related Articles

Posted in Aspose.Note Product Family | Tagged , , , , , | Leave a comment

Create 7z (7-Zip) Archives Programmatically using C# .NET

Create 7Zip Archive in C#

In the previous post, I have discussed different ways of creating ZIP archives using C#. The article also covered how to create encrypted and password-protected ZIP archives. Besides ZIP format, there are some other commonly used archive formats such as 7z, tar, RAR, etc. Among these, 7z archive format is based on open-source architecture and it is used to compress files and folders with a high compression ratio. It also supports 256-bit AES encryption and allows encrypting the files’ names as well. In this article, I’ll demonstrate how to create 7z (7-Zip) archives programmatically using C#.

This article is divided into the following sections:

All the steps and code samples in this article are based on Aspose.ZIP for .NET. Therefore, make sure you have installed the API using either of the following methods:

Create 7z (7-Zip) Archive using C#

There could be two possible scenarios of compressing files into a 7z archive. Either you have only a single file or there could be a bunch of files to be compressed. You can deal with both of the scenarios explicitly.

Create 7z Archive with Single Entry

The following are the steps to create a 7z archive with a single entry.

The following code sample shows how to create a 7z (7-Zip) archive using C#.

Create 7z Archive with Multiple Entries

In this case, you can put the files in a folder and pass the folder’s path to SevenZipArchive.CreateEntries() method. The following are steps to add multiple file entries to a 7z archive.

The following code sample shows how to create a 7z archive with multiple entries using C#.

Create an AES Encrypted 7z Archive using C#

7z format supports AES encryption to secure the files. In order to encrypt a 7z file, the SevenZipAESEncryptionSettings class is used. The following code sample shows how to create an AES encrypted 7z archive using C#.

Set Different Passwords for 7z Entries using C#

7z format also allows you to specify a different password for every file entry. For instance, if you are going to compress two files in a 7z archive, you can specify a different password for each file. The following are the steps to set different passwords for 7z entries.

The following code sample shows how to set a password for every entry in a 7z archive.

Conclusion

In this article, we have learned how to create 7z archives programmatically using C#. In addition, we have seen how to create AES encrypted 7z files and set a password for every file entry. You can learn more about compression/decompression of files from here.

Related Articles

Posted in Aspose.ZIP Product Family | Tagged , , | Leave a comment

Create MS Project Files Programmatically in C# or VB.NET

Microsoft Project is a popular project management software that makes it easier for project managers to efficiently manage the projects. It lets the managers create tasks and resources, assign tasks to resources, track the project’s progress, manage the budget, and perform other project-related operations. In order to create and manage MS Project files programmatically, Microsoft provides MS Office Automation. However, along with other deficiencies, it requires you to install MS Office. To fill this gap, Aspose jumps in to provide you with an MS Project automation solution for .NET applications as Aspose.Tasks for .NET.

Aspose.Tasks for .NET is a feature-rich API that lets you create MS Project files (.mpp/.xml) programmatically using C# or VB.NET. In addition, it offers various features to work with tasks, resources, and calendars. In this article, I’ll show you how to use Aspose.Tasks for .NET to create MS Project files and work with tasks and resources using C#. The rest of the article is divided into the following sections.

Create MS Project Files using C#

MPP is the proprietary file format of Microsoft which is used for MS Project files. However, you can also keep project data in XML files for sharing it among different applications. Creating a new project from scratch is a simple task and can be done using the following steps:

The following code samples show how to create MS Project files using C#.

Save MS Project Files as MPP

Save MS Project Files as XML

Add Tasks to MS Project Files using C#

The empty MS Project file is useless without tasks and resources. So let’s see how to create and add tasks to a project. A task could be a single task or summary task containing a group of subtasks in it. The following are the steps to add tasks to an MS Project file.

  • Create and initialize the Project object.
  • Add a new summary task to the project’s Tasks collection using Project.RootTask.Children.Add(string) method.
  • Add a subtask to the summary task using Task.Children.Add(string) method.
  • Save the project using Project.Save() method.

The following code sample shows how to create and add tasks to MS Project files using C#.

The following code sample shows how to set different properties of the tasks such as duration, start date/time, etc.

Add Resources to MS Project Files using C#

Resources are the entities that are supposed to perform the tasks in a project. Hence, a project would not be possible without the resources to work on it. So let’s check out how to create and add resources to a project. The following are the steps to add resources to an MS Project file.

  • Create a new project using the Project class.
  • Add a new resource to the project’s Resources collection using Project.Resources.Add(string) method.
  • Save the project using Project.Save() method.

The following code sample shows how to add resources to an MS Project file using C#.

The following code sample sets the properties of a resource such as a start date/time, type, etc.

Assign Tasks to Resource in a Project using C#

Once you have completed adding tasks and resources in the project, you can specify which task is to be performed by which resource. Thus, you will assign the task(s) to each resource. The following are the steps to assign tasks to resources in a Project.

  • Create or load a project using Project class.
  • Add new resources to the project and set their properties such as date format, start date, etc.
  • Add new tasks to the project and set their properties such as start date/time, duration, and etc.
  • Perform tasks assignment by adding the task and its respective resource to Project.ResourceAssignments collection.
  • Save the project using Project.Save() method.

The following is the complete code sample of how to create and assign tasks to resources in an MS Project file.

Add Calendar to a Project using C#

The calendars are also one of the main entities of the projects which are used to define the project’s schedule. The calendar makes it possible for the project managers to create a timeline for a project. The following are the steps to add a calendar to a project.

The following code sample shows how to add a calendar to a Project using C#.

Download or Install

You can download Aspose.Tasks for .NET DLL or install it in your project using NuGet.

Try Aspose.Tasks for .NET for Free

Aspose offers a free temporary license to try its products without trial limitations. You can get one from here.

See Also

Posted in Aspose.Tasks Product Family | Tagged , , , , | Leave a comment

Create, Parse and Validate XBRL and iXBRL Financial Reports using C#

aspose.finance

This article provides information about business reporting using the XBRL standard, the purpose of XBRL, and how to automate the process of creating XBRL-based business reports in .NET applications. Furthermore, it contains step by step methods to parse XBRL and iXBRL files and retrieve data programmatically using C#. Last but not the least, it provides some simple ways to validate XBRL and iXBRL files using C#.

eXtensible Business Reporting Language (XBRL)

XBRL is a globally used XML-based standard and file format for business reporting. It makes it easier for various companies and accounting organizations to efficiently and accurately organize, compile, and communicate financial statements or other finance-related information/data. Since XBRL is based on XML (Extensible Markup Language), it uses tags to keep and parse every piece of financial data. iXBRL (inline XBRL) is another variant that makes it possible to keep financial data in a human-readable and machine-readable form at the same time. In contrast with XBRL, iXBRL uses the HTML standard along with some extra tags for figures and statements.

The tags in both, XBRL and iXBRL, are parsed using XBRL-compatible software to retrieve the data. In order to automate XBRL parsing, Aspose offers Aspose.Finance for .NET API. It is a .NET class library that makes it even easier to create XBRL instances programmatically using C# or VB.NET. In addition, it allows you to parse and validate the XBRL or iXBRL files within the .NET applications. Aspose.Finance for .NET provides the following XBRL/iXBRL manipulation features that you will learn in this article.

You can install Aspose.Finance for .NET from NuGet or download its DLL to manually reference it in your project.

Create XBRL Instance from Scratch in C#

Aspose.Finance for .NET makes it simple to create XBRL instances from scratch. You can also add the schema reference, context, units, items, footnote links, role references, and arc role references in the newly created XBRL instance. The following are the steps to create an XBRL instance:

The following code sample shows how to create an XBRL instance in C#.

Once you have created the instance of XBRL, you can insert objects to it which are discussed in the following articles:

Parse XBRL or iXBRL Files in C#

Aspose.Finance for .NET provides an easy way of parsing XBRL files and retrieving their content within a few lines of code. The following sections contain the steps and code samples of how to parse XBRL and iXBRL files.

Parse XBRL Files in C#

The following are the steps to parse an XBRL file using Aspose.Finance for .NET.

The following code sample demonstrates how to parse an XBRL file in C#.

Parse iXBRL Files in C#

Parsing an iXBRL file is comparatively easier and can be done using the following steps.

The following code sample shows how to parse and read an iXBRL file in C#.

Validate XBRL or iXBRL Files in C#

The XBRL and iXBRL files must comply with the validation rules in the XBRL specification and iXBRL specification respectively. Disobeying the specification rules may invalidate the files. Aspose.Finance for .NET also lets you validate XBRL or iXBRL files in order to find out the errors. The following sections demonstrate how to validate XBRL and iXBRL files.

Validate XBRL Files in C#

The following are the steps to validate an XBRL file:

The following code sample shows how to validate an XBRL file in C#.

Validate iXBRL Files in C#

The below steps are used to validate an Inline XBRL file.

The following code sample shows how to validate an iXBRL file in C#.

Learn more about the validation error codes and error messages from here.

Explore the API

You can learn more about how to create, parse, and validate XBRL and iXBRL files from the following resource:

Try Aspose.Finance for .NET for Free

Aspose offers a temporary license to evaluate its APIs free of cost. You may also post your request and get a temporary license.

See Also

Posted in Aspose.Finance Product Family | Tagged , , , , | Leave a comment

Encrypt and Decrypt PDF Files using C#

Excrypt and Decrypt PDF in C#

PDF encryption is used to secure the PDF document from unauthorized access. If a PDF document is encrypted, you have to decrypt it to access its content, otherwise, it will remain unreadable. Most often, the PDF documents are encrypted with a password that is required to open the document. On the other hand, you can also limit the access permissions to various operations such as printing, editing, copying, etc. Aspose’ PDF library, Aspose.PDF for .NET, provides some simple ways to encrypt and decrypt PDF files using C# and VB.NET. In this article, I’ll show you how to perform PDF encryption and decryption operations using C#.

C# PDF Encryption and Decryption API – Installation

Aspose.PDF for .NET is hosted on NuGet and can easily be installed using the NuGet Package Manager. Alternatively, you can download the API’s DLL from the Downloads section.

Encrypt a PDF Files in C#

In order to encrypt a PDF file, you need to set a password that will be required to open and view the document. In addition, you have to specify the desired cryptographic algorithm as the encryption method. Aspose.PDF for .NET supports the following encryption methods:

  • RC4 with a 40-bit key.
  • RC4 with a 128-bit key.
  • AES with a 128-bit key.
  • AES with a 256-bit key.

Steps to Encrypt a PDF File

The following are the simple steps to encrypt a PDF document using C#.

  • Load the PDF document using Document class.
  • Encrypt the PDF document with a password and cryptographic algorithm using Document.Encrypt method.
  • Save the encrypted PDF document using Document.Save method.

The following code sample shows how to encrypt a PDF document using C#.

When you will open this encrypted PDF document in Adobe Reader, it will popup the following dialogue.

encrypted PDF document

Decrypt a PDF File using C#

In order to decrypt a PDF document, you must have the user or owner password of the document. The following are the simple steps to decrypt a PDF document:

  • Load PDF document using Document class by specifying the user’s or owner’s password.
  • Call Document.Decrypt() method.
  • Save the decrypted PDF document.

The following code sample shows how to decrypt a PDF document using C#.

Change Security Permissions of a PDF File in C#

You can enhance the security of a PDF document by limiting the user’s permission. In such a case, you can specify the operations which are allowed for the users. The following is the list of the permissions that you can set to allow for a user.

  • Print Document – Allows printing the document.
  • Modify Content – Allows modifying the contents of the document.
  • Extract Content – Allows copying the content from the document.
  • Modify Text Annotations – Allows adding or modifying text annotations.
  • Fill Form – Allows filling in the interactive form fields.
  • Extract Content with Disabilities – Allows extracting text and graphics (for users with disabilities).
  • Assemble Document – Allows to insert, rotate, or delete pages and create bookmarks or thumbnail images.
  • Printing Quality – Allows printing documents with high resolution.

Steps to Change Security Permissions of a PDF File

The following are the steps to change the security permissions of a PDF document.

  • Load the PDF document.
  • Set security permissions using Document.Encrypt method.
  • Save the encrypted PDF document.

The following code sample shows how to change permissions of a PDF document using C#.

Another way to set or modify the privileges of PDF documents is by using DocumentPrivilege class. The DocumentPrivilege class lets you define the permissions or privileges for the users. The following code sample shows how to set the security permissions of a PDF document using DocumentPrivilege class in C#.

The following are the security details of the PDF document we have encrypted in this section.

changed security permissions of PDF

Conclusion

In this article, you have gone through the steps of how to encrypt and decrypt PDF documents using C#. Furthermore, you have also learned how to set or modify the security permissions of a PDF document in C#. These security features let you protect the sensitive PDF documents using the password and cryptographic algorithms as well as limit the user’s access to the document related operations. You may consult the documentation to learn more about our .NET PDF Library.

See Also

Posted in Aspose.PDF Product Family | Tagged , , | Leave a comment