0
将文件添加到一个特定的目录更具体参考:https://github.com/rackspace/csharp-cloudfilesRackspace的云文件C#,使用Rackspace公司云文件,C#绑定API将文件添加到目录
出于某种奇怪的原因,做这样的事情:
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...");
}
假定MyPath =“Funky”;
这增加了文件,像这样:
- 质朴/ Image1.jpg
- 质朴/ Image5.png
- ...
我能得到使用的文件路径和返回到视图,但我想知道我的文件不存储在“Funky”目录下,而是实际文件名称为"Funky/Image1.png"
?或因此才出现用我的代码:
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;
}
另外请注意:我不得不使用此过滤器,以确保我没有得到的文件夹回...
.Where(x => Path.HasExtension(x));