Skip to content

Files

Latest commit

f8c118d · May 9, 2025

History

History

FileShares

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Apr 10, 2025
Apr 10, 2025
May 9, 2025

Network File Sharing Sample App

ASP.NET Core sample app showing how to use Steeltoe to manage credentialed connections with Windows file shares.

General pre-requisites

  1. Windows machine with the .NET 8 SDK installed
  2. Pre-existing Windows file share or local adminstrator rights
  3. Optional: Tanzu Platform for Cloud Foundry with Windows support

Running locally

Before running the app, you need to create the fileshare or update appsettings.Development.json with the values for a pre-existing fileshare.

Create a file share

Caution

The script add-user-and-share.ps1 must be run as administrator, in Windows. As with any script found on the internet, review the contents before running it.

  1. Open a PowerShell window as an administrator
  2. cd to the scripts directory
  3. Run add-user-and-share.ps1, optionally using parameters to override the default values:
    • -ShareName steeltoe_network_share - the name of the share
    • -SharePath c:\steeltoe_network_share - the path to the share
    • -UserName shareWriteUser - the name of the user
    • -Password thisIs1Pass! - the password for the user

Using an existing file share

  1. Open the appsettings.Development.json file
  2. Update the location, username, and password values with the appropriate values for your file share
  3. Save the file

Run the app

  1. Open a terminal window
  2. cd to the src\FileSharesWeb directory
  3. Run the app with the following command:
    dotnet run --launch-profile https

Once the app is running, you should be able to upload files and list files in the file share. Multiple files can be uploaded at once using the form provided, but you should be aware that files are renamed when they are saved in order to prevent issues with improper characters. You can also delete files by clicking the "Delete file" button in the same row as the file name on the list files page.

Tip

The sample uses credentials different from those of your Windows user account. If you've opened the file share in Windows Explorer before running the sample, it fails because a file share can't be accessed by one user using multiple credentials. To recover, run klist purge to make Windows forget the connection from Windows Explorer.

Removing the local user account and file share

Caution

The script remove-user-and-share.ps1 must be run as administrator, in Windows. As with any script found on the internet, review the contents before running it.

When you are done working with the sample, you can remove the user account, the file share, and its target directory, with the following steps:

  1. Open a PowerShell window as an administrator
  2. cd to the scripts directory
  3. Run remove-user-and-share.ps1, optionally using parameters to override the default values:
    • -ShareName steeltoe_network_share - the name of the share
    • -SharePath c:\steeltoe_network_share - the path to the share
    • -UserName shareWriteUser - the name of the user

Running on Tanzu Platform for Cloud Foundry

Before deploying the app, you must create an entry in CredHub to contain the credentials.

Store credentials in CredHub

  1. Run cf-create-service.ps1 to create a service instance in CredHub, using parameters to set the required values:
    • -NetworkAddress \\\\<hostname>\\<sharename> - escaped UNC path of the fileshare
    • -UserName <username> - the username for accessing the fileshare
    • -Password <password> - the password for accessing the fileshare

Deploy the app

  1. This sample will only run on Windows, so binaries must be built locally before push. Use the following commands to publish and push the app:
    dotnet publish -r win-x64 --self-contained
    cf push -f manifest-windows.yml -p bin/Release/net8.0/win-x64/publish
  2. Copy the value of routes in the output and open in your browser

See the Official Steeltoe Windows Network File Shares Documentation for more detailed information.