c# - 无法将 Excel 文件上传到 Azure 存储 Blob

标签 c# .net azure azure-web-app-service azure-blob-storage

我正在尝试将 Excel 文件上传到 Azure 存储容器,但无法执行此操作。它不是上传 Excel 文件,而是上传容器名称本身。下面有一个代码我试过了。请帮忙。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using Azure.Storage.Blobs;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System.IO;

namespace Console_Workstation
{
    public class Azure_Storage_Connection
    {
        public static void Main()
        {
            string connstring = ConfigurationManager.ConnectionStrings["AzureStorageAccount"].ConnectionString;
            string localFolder = ConfigurationManager.AppSettings["sourceFolder"];
            string destContainer = ConfigurationManager.AppSettings["destContainer"];
                            
            // Connect to container
            BlobContainerClient blobContainer = new BlobContainerClient(connstring,destContainer);
            blobContainer.CreateIfNotExists();
    
            // Connect to Blob into the container
            BlobClient blob = blobContainer.GetBlobClient(destContainer);
    
            // Upload Local file
            blob.Upload(@"C:\Users\AbdulHameedM\Desktop\LocalFolder\Mapper.xlsx");
        }
            
    }
}

PFB 显示的是 inputExcel(容器名称)的屏幕截图,而不是 Mapper.xlsx excel 文件

enter image description here

最佳答案

获取BlobClient时,您可以指定blob的名称。你正在做:

BlobClient blob = blobContainer.GetBlobClient(destContainer);

因此 blob 以 destContainer 的值命名。

您可能想要做:

BlobClient blob = blobContainer.GetBlobClient("Mapper.xlsx");

这会将一个名为“Mapper.xlsx”的 blob 放入以 destContainer 的值命名的容器中。

关于c# - 无法将 Excel 文件上传到 Azure 存储 Blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64391321/

相关文章:

C# 甲骨文 : catch all exceptions relative to connectivity?

c# - 如何将winform的自动滚动定位在顶部?

.net - 如何使用堆栈跟踪转储来调试异常?

azure - Visual Studio 中的 "New Virtual Machine Role"选项

powershell - 使用 Powershell 调用同步

c# - VS2012 自动化部署 - 未为项目设置 OutputPath 属性

c# - 将日期字符串转换为另一个具有不同格式的日期字符串

.net - 在 Windows Mobile 上打开/关闭 LED 灯和手电筒

.net - 是否可以在同一进程中加载​​两个版本的 .NET 运行时?

c# - 路由 Microsoft LUIS 请求和机器人框架 - 最好在企业引用应用程序中