Skip to content

Commit

Permalink
Updated loading document examples
Browse files Browse the repository at this point in the history
  • Loading branch information
muqarrab-aspose committed Mar 12, 2024
1 parent 451df10 commit 36934d3
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 117 deletions.
5 changes: 4 additions & 1 deletion content/english/net/loading-documents/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ url: /net/loading-documents/

## Loading Documents Tutorials
### [Load Documents from Local Disk](./loading-document-local-disk/)
Learn how to seamlessly render documents from your local disk using Groupdocs.Viewer for .NET. Enhance your .NET applications with efficient document.
### [Load Documents from URL](./loading-document-url/)
### [Load Documents from Stream](./loading-document-stream/)
### [Load Documents from FTP (Advanced)](./loading-document-ftp/)
Learn how to seamlessly load documents from streams using GroupDocs.Viewer for .NET. Enhance your .NET applications with powerful document viewing capabilities.
### [Load Documents from FTP (Advanced)](./loading-document-ftp/)
Integrate GroupDocs.Viewer for .NET seamlessly into your applications for efficient document viewing. Render documents from FTP effortlessly.
127 changes: 67 additions & 60 deletions content/english/net/loading-documents/loading-document-ftp/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,83 @@
title: Load Documents from FTP (Advanced)
linktitle: Load Documents from FTP (Advanced)
second_title: GroupDocs.Viewer .NET API
description:
description: Integrate GroupDocs.Viewer for .NET seamlessly into your applications for efficient document viewing. Render documents from FTP effortlessly.
type: docs
weight: 13
url: /net/loading-documents/loading-document-ftp/
---
## Introduction
GroupDocs.Viewer for .NET is a powerful API that enables developers to seamlessly integrate document viewing capabilities into their .NET applications. Whether you're working with PDFs, Microsoft Office documents, or other popular file formats, GroupDocs.Viewer simplifies the process of rendering documents for display, making it easier than ever to provide users with a rich viewing experience.
## Prerequisites
Before you begin working with GroupDocs.Viewer for .NET, ensure that you have the following prerequisites in place:
1. Development Environment: Set up a development environment with Visual Studio and the .NET Framework installed.
2. GroupDocs.Viewer Installation: Download and install GroupDocs.Viewer for .NET from the [website](https://releases.groupdocs.com/viewer/net/).
3. License: Obtain a valid license for GroupDocs.Viewer. You can either purchase a license from the [GroupDocs website](https://purchase.groupdocs.com/buy) or utilize a temporary license for testing purposes ([temporary license](https://purchase.groupdocs.com/temporary-license/)).
4. Basic Understanding of .NET: Familiarize yourself with the basics of .NET development, including C# syntax and working with streams.

## Complete Source Code
## Import Namespaces
To begin using GroupDocs.Viewer for .NET in your application, import the necessary namespaces:
```csharp
using System;
using System.IO;
using System.Net;
using GroupDocs.Viewer.Options;

namespace GroupDocs.Viewer.Examples.CSharp.AdvancedUsage.Loading.LoadingDocumentsFromDifferentSources
```
#Now, let's break down the provided example into multiple steps:
## Step 1: Define Output Directory
```csharp
string outputDirectory = "Your Document Directory";
```
Set the output directory where you want the rendered HTML pages to be saved.
## Step 2: Define Page File Path Format
```csharp
string pageFilePathFormat = Path.Combine(outputDirectory, "page_{0}.html");
```
Specify the format for naming the HTML pages that will be generated.
## Step 3: Set Document File Path
```csharp
string filePath = ""; // e.g. ftp://localhost/sample.doc
```
Provide the path to the document file that you want to load. This could be a local file path or a URL.
## Step 4: Validate File Path
```csharp
if (string.IsNullOrEmpty(filePath))
{
/// <summary>
/// This example demonstrates how to render document downloaded from FTP.
/// </summary>
class LoadDocumentFromFtp
{
public static void Run()
{
string outputDirectory = "Your Document Directory";
string pageFilePathFormat = Path.Combine(outputDirectory, "page_{0}.html");
string filePath = ""; // e.g. ftp://localhost/sample.doc
if (string.IsNullOrEmpty(filePath))
{
Console.WriteLine("\n[LoadDocumentFromFtp] Please make sure to set a proper path to the file.");
return;
}

Stream stream = GetFileFromFtp(filePath);
using (Viewer viewer = new Viewer(stream))
{
HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageFilePathFormat);

viewer.View(options);
}

Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");
}

private static Stream GetFileFromFtp(string filePath)
{
Uri uri = new Uri(filePath);
FtpWebRequest request = CreateRequest(uri);

using (WebResponse response = request.GetResponse())
return GetFileStream(response);
}

private static FtpWebRequest CreateRequest(Uri uri)
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(uri);
request.Method = WebRequestMethods.Ftp.DownloadFile;
return request;
}

private static Stream GetFileStream(WebResponse response)
{
MemoryStream fileStream = new MemoryStream();

using (Stream responseStream = response.GetResponseStream())
responseStream.CopyTo(fileStream);

fileStream.Position = 0;
return fileStream;
}
}
Console.WriteLine("\n[LoadDocumentFromFtp] Please make sure to set a proper path to the file.");
return;
}

```
Ensure that the file path is not empty or null.
## Step 5: Load Document from FTP
```csharp
Stream stream = GetFileFromFtp(filePath);
```
Retrieve the document file from the FTP server.
## Step 6: Render Document
```csharp
using (Viewer viewer = new Viewer(stream))
{
HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageFilePathFormat);
viewer.View(options);
}
```
Create a new Viewer instance and render the document using HTML view options.
## Step 7: Display Success Message
```csharp
Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");
```
Inform the user that the document has been successfully rendered and specify the output directory.

## Conclusion
In conclusion, GroupDocs.Viewer for .NET provides developers with a robust solution for integrating document viewing capabilities into their .NET applications. By following the steps outlined in this tutorial, you can quickly load documents from FTP servers and render them for display, enhancing the user experience of your application.
## FAQ's
### Can I use GroupDocs.Viewer for .NET to render documents from other sources besides FTP?
Yes, GroupDocs.Viewer supports rendering documents from various sources, including local file systems, URLs, and streams.
### Is a license required to use GroupDocs.Viewer for .NET?
Yes, you need a valid license to use GroupDocs.Viewer in production environments. However, you can also obtain a temporary license for testing purposes.
### Can I customize the rendering options for documents?
Absolutely! GroupDocs.Viewer offers a wide range of options for customizing the rendering process, including page rotation, watermarking, and more.
### Does GroupDocs.Viewer support all document formats?
GroupDocs.Viewer supports a vast array of document formats, including PDF, Microsoft Office documents, images, and more.
### Is technical support available for GroupDocs.Viewer for .NET?
Yes, you can access technical support and resources through the [GroupDocs forum](https://forum.groupdocs.com/c/viewer/9) for assistance with any questions or issues you encounter.
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,57 @@
title: Load Documents from Local Disk
linktitle: Load Documents from Local Disk
second_title: GroupDocs.Viewer .NET API
description:
description: Learn how to seamlessly render documents from your local disk using Groupdocs.Viewer for .NET. Enhance your .NET applications with efficient document.
type: docs
weight: 10
url: /net/loading-documents/loading-document-local-disk/
---
## Introduction
In today's digital age, efficient document rendering is essential for various applications. Groupdocs.Viewer for .NET offers a powerful solution for rendering documents directly from your local disk. In this tutorial, we'll guide you through the process of loading documents from your local disk using Groupdocs.Viewer for .NET. Whether you're a seasoned developer or just starting, this step-by-step guide will help you seamlessly integrate document rendering into your .NET applications.
## Prerequisites
Before diving into the tutorial, ensure you have the following prerequisites:
1. Groupdocs.Viewer for .NET: Download and install the latest version from [here](https://releases.groupdocs.com/viewer/net/).
2. .NET Development Environment: Make sure you have a working .NET development environment set up on your system.
3. Local Documents: Have the documents you want to render stored locally on your disk.

## Complete Source Code
## Import Namespaces
Firstly, let's import the necessary namespaces to access the functionalities of Groupdocs.Viewer for .NET.
```csharp
using System;
using System.IO;
using GroupDocs.Viewer.Options;

namespace GroupDocs.Viewer.Examples.CSharp.AdvancedUsage.Loading.LoadingDocumentsFromDifferentSources
```
## Step 1: Load Documents from Local Disk
Begin by setting up the output directory where the rendered HTML pages will be saved.
```csharp
string outputDirectory = "Your Document Directory";
string pageFilePathFormat = Path.Combine(outputDirectory, "page_{0}.html");
```
## Step 2: Initialize Viewer and Render Documents
Initialize the Viewer object with the document's path and render it using HTML view options.
```csharp
using (Viewer viewer = new Viewer("Path_to_Your_Document"))
{
/// <summary>
/// This example demonstrates how to render document from local disk.
/// </summary>
class LoadDocumentFromLocalDisk
{
public static void Run()
{
string outputDirectory = "Your Document Directory";
string pageFilePathFormat = Path.Combine(outputDirectory, "page_{0}.html");

using (Viewer viewer = new Viewer(TestFiles.SAMPLE_DOCX))
{
HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageFilePathFormat);

viewer.View(options);
}

Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");
}
}
HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageFilePathFormat);
viewer.View(options);
}

```
## Step 3: Display Output
Once rendering is complete, display a message indicating the successful rendering of the source document and the location of the output files.
```csharp
Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");
```

## Conclusion
Congratulations! You've successfully learned how to load documents from your local disk using Groupdocs.Viewer for .NET. This powerful tool opens up a world of possibilities for document rendering within your .NET applications.
## FAQ's
### Can I render documents of different formats using Groupdocs.Viewer for .NET?
Yes, Groupdocs.Viewer for .NET supports a wide range of document formats including DOCX, PDF, XLSX, PPTX, and more.
### Is Groupdocs.Viewer for .NET compatible with all .NET frameworks?
Groupdocs.Viewer for .NET is compatible with most .NET frameworks including .NET Core, .NET Framework, and .NET Standard.
### Can I customize the rendering options for my documents?
Absolutely! Groupdocs.Viewer for .NET provides extensive customization options allowing you to tailor the rendering process to your specific requirements.
### Is there a trial version available for Groupdocs.Viewer for .NET?
Yes, you can download a free trial version from [here](https://releases.groupdocs.com/).
### Where can I find support or additional resources for Groupdocs.Viewer for .NET?
For support and additional resources, visit the Groupdocs.Viewer for .NET [forum](https://forum.groupdocs.com/c/viewer/9).
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,69 @@
title: Load Documents from Stream
linktitle: Load Documents from Stream
second_title: GroupDocs.Viewer .NET API
description:
description: Learn how to seamlessly load documents from streams using GroupDocs.Viewer for .NET. Enhance your .NET applications with powerful document viewing capabilities.
type: docs
weight: 12
url: /net/loading-documents/loading-document-stream/
---
## Introduction
In the realm of .NET development, managing and viewing documents efficiently is paramount. With the advent of advanced tools and libraries, tasks that once seemed daunting are now simplified. Among these tools, GroupDocs.Viewer for .NET stands out as a versatile solution for seamlessly handling various document formats. In this comprehensive guide, we delve into the intricacies of using GroupDocs.Viewer for .NET to load documents from a stream. Whether you're a seasoned developer or just starting, this tutorial will equip you with the knowledge to harness the power of GroupDocs.Viewer effectively.
## Prerequisites
Before diving into the tutorial, ensure you have the following prerequisites in place:
1. Basic Understanding of C# and .NET Framework: Familiarity with C# programming language and the .NET framework will aid in comprehending the concepts discussed.

2. Installation of GroupDocs.Viewer for .NET: Download and install GroupDocs.Viewer for .NET from the [website](https://releases.groupdocs.com/viewer/net/).
3. IDE: Have an Integrated Development Environment (IDE) like Visual Studio installed for coding and testing.
4. Document Stream: Prepare a document stream for loading. This could be a file stream or any other compatible stream source.

## Complete Source Code
## Import Namespaces
Before implementing the code to load documents from a stream, make sure to import the necessary namespaces:
```csharp
using System;
using System.IO;
using GroupDocs.Viewer.Options;

namespace GroupDocs.Viewer.Examples.CSharp.AdvancedUsage.Loading.LoadingDocumentsFromDifferentSources
```
## Step 1: Define Output Directory
```csharp
string outputDirectory = "Your Document Directory";
```
Set the directory path where the rendered document will be saved.
## Step 2: Define Page File Path Format
```csharp
string pageFilePathFormat = Path.Combine(outputDirectory, "page_{0}.html");
```
Define the format for the file path of each page. Here, "{0}" will be replaced by the page number.
## Step 3: Get Document Stream
```csharp
Stream stream = GetFileStream();
```
Obtain the document stream from your desired source. This could be a file stream, memory stream, or any other compatible stream.
## Step 4: Load Document Using Viewer
```csharp
using (Viewer viewer = new Viewer(stream))
{
/// <summary>
/// This example demonstrates how to render document from stream.
/// </summary>
class LoadDocumentFromStream
{
public static void Run()
{
string outputDirectory = "Your Document Directory";
string pageFilePathFormat = Path.Combine(outputDirectory, "page_{0}.html");
Stream stream = GetFileStream();

using (Viewer viewer = new Viewer(stream))
{
HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageFilePathFormat);

viewer.View(options);
}

Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");
}

private static Stream GetFileStream()
{
return File.OpenRead(TestFiles.SAMPLE_DOCX);
}
}
HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageFilePathFormat);

viewer.View(options);
}

```
Initialize a new instance of the Viewer class with the document stream. Then, configure the HTML view options and render the document.
## Step 5: Display Output Directory
```csharp
Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");
```
Inform the user about the successful rendering of the document and provide the location where the output is saved.

## Conclusion
In conclusion, GroupDocs.Viewer for .NET offers a robust solution for loading and viewing documents from streams effortlessly. By following the steps outlined in this tutorial, you can seamlessly integrate document viewing capabilities into your .NET applications, enhancing user experience and productivity.
## FAQs
### Can GroupDocs.Viewer for .NET handle different document formats?
Yes, GroupDocs.Viewer supports a wide range of document formats, including PDF, DOCX, XLSX, PPTX, and more.
### Is GroupDocs.Viewer for .NET suitable for both web and desktop applications?
Absolutely! GroupDocs.Viewer can be seamlessly integrated into both web and desktop applications developed using .NET.
### Does GroupDocs.Viewer offer customization options for document rendering?
Yes, you can customize various aspects of document rendering, such as watermarking, page rotation, and zoom level, according to your requirements.
### Can I use GroupDocs.Viewer for .NET in commercial projects?
Yes, GroupDocs.Viewer offers licensing options suitable for commercial projects. You can purchase licenses from the official [website](https://purchase.groupdocs.com/temporary-license/).
### Is technical support available for GroupDocs.Viewer for .NET?
Yes, you can seek technical assistance and guidance from the dedicated support forum provided by [GroupDocs.Viewer](https://forum.groupdocs.com/c/viewer/9).

0 comments on commit 36934d3

Please sign in to comment.