Spire.Cloud.Storage 创建、移动、复制、删除文件夹

Spire.Cloud.Storage .NET SDK 给开发人员提供了 FolderApi 接口,支持新建、移动、复制、及删除文件夹。本文将介绍如何调用该接口来实现以上文件夹操作。

首先:通过 NuGet 安装 Spire.Cloud.Sdk 包及依赖,详细步骤可参考这篇文章

其次:通过冰蓝云官网(https://cloud.e-iceblue.cn/)注册账号并登陆,在“我的应用”下点击“创建应用”,获得 App ID 及 App Key。

Spire.Cloud.Storage 创建、移动、复制、删除文件夹

最后:编辑如下 C# 后端代码来实现创建、移动、复制、删除文件夹。

  • C#
using Spire.Cloud.Storage.Sdk.Api;
using Spire.Cloud.Storage.Sdk.Client;

namespace CloudStorage
{
    class FolderApiDemo
    {
        static string appId = "Your App ID";
        static string appKey = "Your App Key";
        static string baseUrl = "https://api.e-iceblue.cn";
        //配置App ID和App Key
        static Configuration configuration = new Configuration(appId, appKey, baseUrl);
        //创建FolderApi实例
        static FolderApi folderApi = new FolderApi(configuration);

        //创建文件夹
        public static void CreateFolder()
        {
            string path = "CreateFolderTest";
            string storageName = null;
            folderApi.CreateFolder(path, storageName);
        }

        //移动文件夹
        public static void MoveFolder()
        {
            string srcPath = "input";
            string destPath = "output/clone";
            string srcStorageName = null;
            string destStorageName = null;
            folderApi.MoveFolder(srcPath, destPath, srcStorageName, destStorageName);
        }

        //复制文件夹
        public static void CopyFolder()
        {
            string srcPath = "input";
            string destPath = "output/CopyFolderTest";
            string srcStorageName = null;
            string destStorageName = null;
            folderApi.CopyFolder(srcPath, destPath, srcStorageName, destStorageName);
        }

        //删除文件夹
        public static void DeleteFolder()
        {
            string path = "output/test";
            string storageName = null;
            bool? recursive = true;
            folderApi.DeleteFolder(path, storageName, recursive);
        }
    }
}

下面是创建的文件夹效果,可在“文档管理”下查看:

Spire.Cloud.Storage 创建、移动、复制、删除文件夹