Web API Edition | ComponentOne
Web API / Working with Web API / Configuring Web API / Configuring Storage
In This Topic
    Configuring Storage
    In This Topic

    Once you have created the Web API service application, you can optionally configure Storage in it. Storage serves as a repository for data, on the server side or remote location. It provides data from database or data files to the client applications. The client applications use this data and consume the Rest API service through GET request, to generate, convert, and merge excel files in desired format. For more information, see Excel Services.

    Client application fetches data/file from the configured storage once user makes a GET request. Your storage can be a remote or local storage. Remote storage could reside on cloud or on a different server than your configured host service. Whereas, local storage resides on the same server where host service is deployed. This section demonstrates how to create and configure a local storage folder within your service app. While, the following sections discuss configuring server side connection string and .NET collections to configure local storage. 

    Complete the following steps to configure local storage in Web API service created in Configuring Web API topic.

    1. Create a folder named Files, in your service application.
    2. Add the desired data files to this folder.
    3. To configure this storage in your service, call the GetFullRoot() method and pass its value to a local variable folder in Configuration (IAppBuilder app) method within Startup.cs file of your Web API service project, as shown below.
      C#
      Copy Code
      var folder = GetFullRoot("Files");
      
    4. Define the GetFullRoot() method within Startup class, as shown below.
      C#
      Copy Code
      private static string GetFullRoot(string root)
      {
              var applicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
              var fullRoot = Path.GetFullPath(Path.Combine(applicationBase, root));
              if (!fullRoot.EndsWith(Path.DirectorySeparatorChar.ToString(), 
              StringComparison.Ordinal))
          {
          // When we do matches in GetFullPath, we want to only match full directory names.
          fullRoot += Path.DirectorySeparatorChar;
          }
      return fullRoot;
      }
      
    5. Add disk storage to the StorageProviderManager of your service app through AddDiskStorage() method in Configuration method within Startup.cs, as shown below.  
      C#
      Copy Code
       app.UseStorageProviders()
      .AddDiskStorage("fullRoot", GetFullRoot("Files"));
      

      This method takes root name and full path of the storage. Give a desired name to your storage folder, for example "root" in this case. 

    See Also