# How to: Share Code through Source Files

\[ **This document was written for WCF Services Version 1 Service Pack 2 and might not be up to date** \
&#x20;Please see [Release Notes](https://github.com/OpenRIAServices/OpenRiaServices/releases) or [Changelog](https://github.com/OpenRIAServices/OpenRiaServices/blob/main/Changelog.md) for a list of changes since WCF RIA Services ]

This topic describes how to share code, and so functionality, between the middle tier and the presentation tier of a Open Ria Services application using source files. When you change the source file in the middle tier and rebuild your application, the updated code is automatically synchronized in the client project. You put code in a shared source file when the code does not belong in a domain service or an entity class, and you do not want the code to go through the client code generation process.

You can share source files by either using a shared naming convention or by file links. This topic describes how to share source files by using both of these approaches. For information about the advantages and disadvantages of both approaches, see the [Shared Code](/openriaservices/ee707348/ee707371.md) topic.

This topic assumes that you have already created a Open Ria Services solution. For a description of the procedures for doing this, see the [Walkthrough: Creating a Open Ria Services Solution](/openriaservices/ee707336/ee707376.md) topic.

## To share a source file by using a shared naming convention

1. In **Solution Explorer** for a middle-tier project, create any directory structure that you want to contain shared code files.

   The directory structure will be re-created in the client project under the Generated\_Code folder.
2. Add a C# or Visual Basic code file to the directory structure.

   The file can exist anywhere in the directory structure of the middle-tier project.
3. Depending on the language of the project, name the class by using the shared naming convention: \*.shared.cs or \*.shared.vb.

   For example, ExampleCode.shared.cs or ExampleCode.shared.vb.
4. Add code to the shared code file.
5. Build (Ctrl+Shjift+B) the solution.
6. In the client project, open the Generated\_Code folder and notice that the code file has been copied.

   At the top of **Solution Explorer**, you might have to click the **Show All Files** option in the client project to see the Generated\_Code folder.

   ![RIA\_SharedCodeFile](/files/-M_An43GdDMO4M_1wafM)
7. Open the code file and notice that no changes have been made to the code during compilation.

## To share a source file by using file links

1. In the middle-tier project, add a new code file.
2. Add code to the code file.
3. In the presentation-tier project, right-click the project, select **Add** and then select **Existing Item**.
4. Select the code file that you added to the middle tier project.
5. On the **Add** button, click the down array and select **Add As Link**.

   When you compile the project, you will see that the file has not been copied to the client project. Instead, a reference was added to the file.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://openriaservices.gitbook.io/openriaservices/ee707348/ee707371/ee707369.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
