public List <string> GetBucketList()
        {
            List <string> output = new List <string>();

            S3Request request = new S3Request(this);

            request.Method   = S3Request.RequestMethod.rmGet;
            request.Resource = "/";

            S3Response response = null;

            response = request.Perform();

            XmlDocument doc = new XmlDocument();

            doc.Load(response.GetResponseStream());
            response.Close();

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);

            nsmgr.AddNamespace("s3", doc.LastChild.NamespaceURI); //"http://s3.amazonaws.com/doc/2006-03-01/");

            XmlNodeList xmlBuckets = doc.SelectNodes("/s3:ListAllMyBucketsResult/s3:Buckets/s3:Bucket/s3:Name", nsmgr);

            foreach (XmlNode xmlBucketName in xmlBuckets)
            {
                output.Add(xmlBucketName.InnerText);
            }
            return(output);
        }
        public void CreateBucket(string bucketName)
        {
            S3Request request = new S3Request(this);

            request.Resource = "/" + bucketName;
            request.Method   = S3Request.RequestMethod.rmPut;

            S3Response response = null;

            try
            {
                response = request.Perform(null);
            }
            catch (S3Exception ex)
            {
                // Check for "BucketAlreadyOwnedByYou" server code, which is okay.
                if (ex.Code != "BucketAlreadyOwnedByYou")
                {
                    throw ex;
                }
            }

            if (response != null)
            {
                response.Close();
            }
        }
        public void DeleteObject(string path)
        {
            S3Request request = new S3Request(this);

            request.Resource = GetPathForObject(path);
            request.Method   = S3Request.RequestMethod.rmDelete;
            S3Response response = request.Perform(null);

            response.Close();
        }
        // Important: Caller must close the returned Stream!
        public Stream GetObject(string path)
        {
            S3Request request = new S3Request(this);

            request.Resource = GetPathForObject(path);
            request.Method   = S3Request.RequestMethod.rmGet;
            S3Response response = request.Perform();

            return(response.GetResponseStream());
        }
        public void PutObject(string path, Stream stream, string encryptionKey)
        {
            S3Request request = new S3Request(this);

            request.Resource      = GetPathForObject(path);
            request.Method        = S3Request.RequestMethod.rmPut;
            request.EncryptionKey = encryptionKey;
            S3Response response = request.Perform(stream);

            response.Close();
        }
        public List <string> GetObjectList(string prefix, ref string marker, int maxEntries, string delimiter, ReceiveContentsDelegate contentsDelegate, ReceivePrefixDelegate prefixDelegate)
        {
            bool          cancelled = false; // True if we have been asked to stop (not presently used).
            bool          truncated = false; // True if there were too many entries to list in one go.
            string        lastKey   = marker;
            List <string> output    = new List <string>();

            do
            {
                string signPath = "/";
                if (IsUS)
                {
                    signPath += bucket;
                }
                string path         = signPath + "?prefix=" + HttpUtility.UrlEncode(pathPrefix + prefix);
                int    prefixLength = (pathPrefix + prefix).Length;

                if (marker.Length > 0)
                {
                    path += "&marker=" + HttpUtility.UrlEncode(marker);
                }
                if (delimiter != null && delimiter.Length > 0)
                {
                    path += "&delimiter=" + HttpUtility.UrlEncode(delimiter);
                }

                S3Request request = new S3Request(this);
                request.Resource = path;
                request.Method   = S3Request.RequestMethod.rmGet;
                S3Response response = request.Perform();

                XmlDocument doc = new XmlDocument();
                doc.Load(response.GetResponseStream());
                response.Close();
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
                nsmgr.AddNamespace("s3", doc.LastChild.NamespaceURI); //"http://s3.amazonaws.com/doc/2006-03-01/");

                XmlNode truncatedNode = doc.SelectSingleNode("//s3:IsTruncated", nsmgr);
                truncated = truncatedNode.InnerText.ToUpper().StartsWith("T");

                XmlNodeList contentNodes = doc.SelectNodes("//s3:Contents", nsmgr);
                foreach (XmlNode contentNode in contentNodes)
                {
                    string key = contentNode.SelectSingleNode("./s3:Key", nsmgr).InnerText;
                    if (contentsDelegate != null)
                    {
                        contentsDelegate(key.Remove(0, prefixLength));
                    }
                    lastKey = key;
                }
                XmlNodeList prefixNodes = doc.SelectNodes("//s3:CommonPrefixes/s3:Prefix", nsmgr);
                if (prefixDelegate != null)
                {
                    foreach (XmlNode prefixNode in prefixNodes)
                    {
                        prefixDelegate(prefixNode.InnerText.Remove(0, prefixLength));
                    }
                }
            } while (truncated && (maxEntries == 0 || output.Count < maxEntries) && !cancelled);

            marker = truncated ? lastKey : "";
            return(output);
        }