• Sales: 1-800-961-2888
  • Support: 1-800-961-4454

Sample CSharp Application for Cloud Files


Note: This code example does not work at this time, and is preserved here for archival purposes. We apologize for the inconvenience.

We are collaborating with the OpenStack project on a newer .NET SDK that would work with Cloud Files.  You can track its progress on its github project page.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.mosso.cloudfiles;
using com.mosso.cloudfiles.domain;
namespace ConsoleApplication1
{
 class Program
  {
   static void Main(string[] args)
    {
     UserCredentials userCreds = new UserCredentials("UserNameGoesHere", "ApiKeyGoesHere");
     Connection connection = new com.mosso.cloudfiles.Connection(userCreds);
     connection.CreateContainer("ContainerNameGoesHere");
     connection.PutStorageItem("ContainerNameGoesHere", "PathToFileYouWantToUpload");
    }
  }
}


© 2011-2013 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License


See license specifics and DISCLAIMER

16 Comments

This code seems outdated, I had to use the namespace Rackspace.Cloud and CF_* objects.

That sounds likely. Thanks for bringing this to our attention - we'll get the code samples reviewed.

Is this code already updated or not? thnks

I'll check with the devs again, sorry about the uncertainty for now.

How about putting up a powershell sample

Is VB.net for Cloud Files available?

I think there are only language bindings for c# right now, I'd imagine you could use raw HTTP requests to interact with the API instead. You might check our github to see if there are any vb.net projects there too:

https://github.com/rackspace/

Any news on getting the code updated? I am trying to write a file but I keep getting a null reference exception.

What I'm hearing back is that we don't have internal C# expertise at this time, so we can't get a working example in place yet. I'll make a note on the article for now, and we'll work on remedying the situation as soon as possible.

Please note that my C# is very rusty, however, downloading the DLLs from https://github.com/rackspace/csharp-cloudfiles/downloads and following the code samples at https://github.com/rackspace/csharp-cloudfiles/wiki/Code-Examples netted me the following which lists out the files stored in a container:

using System;
using Rackspace.Cloudfiles;

namespace cloudfiles
{
class Program
{
private const string ContainerName = "testing";
public static void Main(string[] args)
{
var creds = new UserCredentials("USERNAME","APIKEY");
var client = new CF_Client();
Connection conn = new CF_Connection(creds, client);
Console.WriteLine("Authenticating...");
conn.Authenticate();
Console.WriteLine("Authenticated");

var container = new CF_Container(conn, client, ContainerName);
var list = container.GetObjectList(true);
Console.WriteLine("There are {0} items in the {1} container", list.Count, ContainerName);
Console.WriteLine("Listing all objects in {0} container", ContainerName);
foreach(var item in list) {
Console.WriteLine(item["name"]);
Console.WriteLine("--------------------");
}
Console.WriteLine("Listed all objects in {0} container", ContainerName);
Console.ReadLine();
}
}
}

Note that you need to add references to both the Rackspace.Cloudfiles and OpenStack.Swift dlls.

Please advice how to use with Proxy server:
UserCredentials userCredentials = new UserCredentials(new System.Uri(auth_endpoint), username, api_access_key, null, null);

On live landscape it works fine.

Please advice how to use with Proxy server:
UserCredentials userCredentials = new UserCredentials(new System.Uri(auth_endpoint), username, api_access_key, null, null);

On live landscape where there is no need for proxy it works fine.

Unfortunately, we don't have in-house C# expertise right now (that I could find) who could answer your question. We are, however, working with the OpenStack project on a new SDK for .NET that would work with Cloud Files and our other services:

https://github.com/rackspace/openstack.net/

Does anyone know where the Sample for Objective-C went? It was on GitHub earlier this year, but now it seems to be removed from the site.

The github projects that aren't directly supported by Rackspace have been moved to a new github repository:

https://github.com/rackerlabs

You should be able to find the iOS Cloudfiles bindings here:

https://github.com/rackerlabs/ios-cloudfiles

I realize it's been a while since Gary asked about VB.NET, but I put my own library together since OpenStack.NET still doesn't support Cloud Files at all. It's a "use at your own risk" type of deal and does nothing with CDN or "large files" but in my own testing, it seems to do the basics well.

I'm still writing documentation but it should be pretty easy to use...

https://github.com/LukeBaum/CloudFilesHelper

Add new comment