# Windows Forms: Loading and Saving Documents from a Server

> A custom URI protocol registered in the Windows registry enables loading and saving documents from a web server through a desktop application. The client receives the document URL as a command-line argument, fetches it with HttpWebRequest, and opens it in TX Text Control for editing.

- **Author:** Bjoern Meyer
- **Published:** 2013-06-17
- **Modified:** 2026-07-17
- **Description:** A custom URI protocol registered in the Windows registry enables loading and saving documents from a web server through a desktop application. The client receives the document URL as a command-line argument, fetches it with HttpWebRequest, and opens it in TX Text Control for editing.
- **4 min read** (737 words)
- **Tags:**
  - Tutorial
- **Web URL:** https://www.textcontrol.com/blog/2013/06/17/windows-forms-loading-and-saving-documents-from-a-server/
- **LLMs URL:** https://www.textcontrol.com/blog/2013/06/17/windows-forms-loading-and-saving-documents-from-a-server/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2013/06/17/windows-forms-loading-and-saving-documents-from-a-server/llms-full.txt
- **GitHub Repository:** https://github.com/TextControl/TextControl.FitToPage-FitToWidth

---

As part of our [Flow Type Layout Reporting Consulting](https://www.textcontrol.com/blog/2013/05/22/flow-type-layout-reporting-free-consulting/llms-full.txt) service, we received an interesting request. With Microsoft SharePoint in combination with Microsoft Word, you can open documents directly from your SharePoint website and load it into the local MS Word installation. After editing, the document can be saved back to the repository.

In order to maintain templates for reporting applications, this approach is perfect in order to give users the full power of thick-client applications in combination with centralized documents and templates.

We have created a very basic demo project that shows this procedure. The solution consists of two parts the Web application and a client application to edit the document. The client application will be registered with a specific protocol. The browser is looking for registered protocols when the user is clicking a link. The protocol is connected to an application through the registry database.

You might have already seen some hyperlink protocols such as *mailto:*, *callto:* or *skype:*. For this purpose, we are creating our own protocol called *ClientApplication*. The following reg file must be created and double-clicked to add the values to the database.

```
REGEDIT4

[HKEY_CLASSES_ROOT\ClientApplication]
@="URL:ClientApplication Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\ClientApplication\shell]

[HKEY_CLASSES_ROOT\ClientApplication\shell\open]

[HKEY_CLASSES_ROOT\ClientApplication\shell\open\command]
@="\"C:\ClientApplication.exe\" \"%1\""
```

You can download the registry file here: [ClientApplication.reg](https://s1-www.textcontrol.com/assets/dist/blog/2013/06/17/a/assets/ClientApplication.reg)

Make sure that the path *C:\\\\ClientApplication.exe\\* matches the path on your machine for the primary output of the *ClientApplication*.

More information about these protocols can be found in this MSDN article:

[Registering an Application to a URI Scheme](http://msdn.microsoft.com/en-us/library/aa767914%28VS.85%29.aspx)

1. After loading the Visual Studio 2012 solution, compile and start the Web application. The website is very simple and basically shows only 3 links to documents that are stored on the server. Pay attention to the status bar when hovering over a link. Our custom protocol *ClientApplication:* is shown.
    
    ![Load and save documents from a server](https://s1-www.textcontrol.com/assets/dist/blog/2013/06/17/a/assets/tx_loadsave_1.webp "Load and save documents from a server")
2. Click on any document. All browsers will show a similar message box asking to confirm that an application on your computer is allowed to open this file type.
    
    ![Load and save documents from a server](https://s1-www.textcontrol.com/assets/dist/blog/2013/06/17/a/assets/tx_loadsave_2.webp "Load and save documents from a server")Confirm with *Allow* in order to load the document.
3. Thanks to the protocol, the browser starts our associated *ClientApplication* which loads the document with a simple HttpWebRequest.
    
    ![Load and save documents from a server](https://s1-www.textcontrol.com/assets/dist/blog/2013/06/17/a/assets/tx_loadsave_3.webp "Load and save documents from a server")
4. Make some changes to the document and click the green *Save back* button.
    
    ![Load and save documents from a server](https://s1-www.textcontrol.com/assets/dist/blog/2013/06/17/a/assets/tx_loadsave_4.webp "Load and save documents from a server")

When you repeat the steps and load the same document again, you will notice that the changes have been saved properly.

The *ClientApplication* receives command line arguments which is basically the name of the document to load. Simple HttpWebRequests are used to get the stream which is converted into a byte array and then loaded into TX Text Control.

```
static void Main(string[] args)
{
    string sFileLocation = args[0].Substring("ClientApplication:".Length);

    // create a new httpp request and load the document into a byte array
    HttpWebRequest myHttpWebRequest =
        (HttpWebRequest)HttpWebRequest.Create("http://" + sFileLocation);
    HttpWebResponse myHttpWebResponse =
        (HttpWebResponse)myHttpWebRequest.GetResponse();

    System.IO.Stream stream = myHttpWebResponse.GetResponseStream();

    byte[] data = null;

    // convert the stream to an array
    var memoryStream = new MemoryStream();
    stream.CopyTo(memoryStream);
    data = memoryStream.ToArray();

    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);

    // open the form and pass byte array and file location
    Application.Run(new Form1(data, sFileLocation));
}
```

```
private byte[] bDocument;
private string sFileLocation;

public Form1(byte[] data, string location)
{
    bDocument = data;
    sFileLocation = location;

    InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
    // load the document from the byte array
    textControl1.Load(bDocument,
        TXTextControl.BinaryStreamType.WordprocessingML);
}
```

**Conclusion:** Creating your own protocol is a very efficient way to load, modify and save documents directly from and to a Website using a thick-client Windows application. TX Text Control provides the required components for client-side and server-side processing.

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [Windows Forms Tutorial: Create Your First Windows Forms C# Application](https://www.textcontrol.com/blog/2024/08/26/windows-forms-tutorial-create-your-first-windows-forms-csharp-application/llms.txt)
- [How to Mail Merge MS Word DOCX Documents in ASP.NET Core C#](https://www.textcontrol.com/blog/2023/10/16/how-to-mail-merge-ms-word-docx-documents-in-aspnet-core-csharp/llms.txt)
- [Creating an Angular Document Editor Application with a Node.js WebSocket Server](https://www.textcontrol.com/blog/2023/08/24/creating-an-angular-document-editor-application-with-a-nodejs-websocket-server/llms.txt)
- [Adding SVG Watermarks to Documents](https://www.textcontrol.com/blog/2022/01/28/adding-svg-watermarks-to-documents/llms.txt)
- [Using MailMerge in ASP.NET Core 6 Web Applications](https://www.textcontrol.com/blog/2022/01/27/using-mailmerge-in-aspnet-core-6-web-applications/llms.txt)
- [DocumentViewer for React Prerelease](https://www.textcontrol.com/blog/2020/10/27/document-viewer-for-react-prerelease/llms.txt)
- [New DocumentViewer Signature Tutorial Sample](https://www.textcontrol.com/blog/2020/08/18/new-documentviewer-signature-tutorial-sample/llms.txt)
- [Creating an ASP.NET MVC DocumentViewer Application With Razor](https://www.textcontrol.com/blog/2020/01/01/creating-an-aspnet-mvc-documentviewer-application-with-razor/llms.txt)
- [Creating Your First Windows Forms Application with C#](https://www.textcontrol.com/blog/2020/01/01/creating-your-first-windows-forms-application-with-csharp/llms.txt)
- [Creating Your First WPF Application](https://www.textcontrol.com/blog/2020/01/01/creating-your-first-wpf-application/llms.txt)
- [Creating a WPF Ribbon Application](https://www.textcontrol.com/blog/2020/01/01/creating-a-wpf-ribbon-application/llms.txt)
- [Integrate Document Editing into any HTML Client using the HTML Widget](https://www.textcontrol.com/blog/2020/01/01/integrate-document-editing/llms.txt)
- [Creating an ASP.NET MVC Application With Razor](https://www.textcontrol.com/blog/2020/01/01/creating-an-aspnet-mvc-application-with-razor/llms.txt)
- [Creating A Windows Forms Ribbon Application](https://www.textcontrol.com/blog/2020/01/01/creating-a-windows-forms-ribbon-application/llms.txt)
- [Creating Your First ASP.NET Reporting Application](https://www.textcontrol.com/blog/2020/01/01/creating-your-first-aspnet-reporting-application/llms.txt)
- [Creating an ASP.NET Web Forms AJAX Application](https://www.textcontrol.com/blog/2020/01/01/creating-an-aspnet-web-forms-ajax-application/llms.txt)
- [Creating a WebSocket Server Project with Node.js](https://www.textcontrol.com/blog/2020/01/01/creating-a-websocket-server-project-with-nodejs/llms.txt)
- [Creating an Angular Document Editor Application](https://www.textcontrol.com/blog/2020/01/01/creating-an-angular-document-editor-application/llms.txt)
- [ReportingCloud .NET Core Quickstart Tutorial](https://www.textcontrol.com/blog/2019/07/24/reportingcloud-dotnet-core-quickstart-tutorial/llms.txt)
- [Document Permissions and Password Encryption](https://www.textcontrol.com/blog/2019/07/05/document-permissions-and-password-encryption/llms.txt)
- [New Online Sample: Build your First Report](https://www.textcontrol.com/blog/2019/07/03/build-your-first-report/llms.txt)
- [Create your First Document with ReportingCloud](https://www.textcontrol.com/blog/2019/02/19/create-your-first-document-with-reportingcloud/llms.txt)
- [MailMerge: Starting Each Merge Block on a New Page](https://www.textcontrol.com/blog/2016/09/09/mailmerge-starting-each-merge-block-on-a-new-page/llms.txt)
- [Windows Forms and WPF: End a List on Return when Line is Empty](https://www.textcontrol.com/blog/2016/08/26/windows-forms-and-wpf-end-a-list-on-return-when-line-is-empty/llms.txt)
- [Using IFormattedText Objects to Access Elements Across All TextParts in a Document](https://www.textcontrol.com/blog/2016/08/25/using-iformattedtext-objects-to-access-elements-across-all-textparts-in-a-document/llms.txt)
