简体   繁体   English

Rackspace云文件c#,添加文件到目录

[英]Rackspace cloud file c#, adding files to directory

Adding files to a specific directory using rackspace cloud files, c# bindings api more specifically reference: https://github.com/rackspace/csharp-cloudfiles使用机架空间云文件将文件添加到特定目录,c# 绑定 api 更具体参考: https://github.com/rackspace/csharp-cloudfiles

For some strange reason doing something like:出于某种奇怪的原因,执行以下操作:

    public static void UploadFile(CSImageDTO file)
    {
        var connection = new Connection(UserCredentials);
        var containerItemList = connection.GetContainerItemList(ContainerName);

        if (!containerItemList.Contains(file.Filename))
            connection.PutStorageItem(ContainerName, file.File, Path.Combine(MyPath, Path.GetFileName(file.Filename)));
        else
            throw new NotSupportedException("we dont know what to do now...");
    }

Presuming MyPath = "Funky";假设 MyPath = "Funky";

This adds files like so:这会添加如下文件:

  • Funky/Image1.jpg时髦/Image1.jpg
  • Funky/Image5.png时髦/Image5.png
  • ... ...

I could get the file path using Path.GetFileName(filepath) and return that to the view, but I want to know my files are not stored under the directory "Funky", instead the actual file name is called "Funky/Image1.png" ?我可以使用Path.GetFileName(filepath)获取文件路径并将其返回到视图,但我想知道我的文件没有存储在“Funky”目录下,而是实际文件名称为"Funky/Image1.png" or so it appears using my code:或者它使用我的代码出现:

 public static IEnumerable<string> GetFiles()
        {
            var connection = new Connection(UserCredentials);

            var parameters = new Dictionary<GetItemListParameters, string>();
            //parameters.Add(GetItemListParameters.Path, MyPath);

            var containerItemList = connection.GetContainerItemList(ContainerName, parameters)
                .Where(x => Path.HasExtension(x));
            //.Select(x => Path.GetFileName(x));

            return containerItemList;
        }

Also note: I have to use this filter to make sure I dont get the file folder back...另请注意:我必须使用此过滤器来确保我不会找回文件夹...

.Where(x => Path.HasExtension(x));

Because it is a Flat file system...因为它是一个平面文件系统...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM