Facebook.Facebook.UploadToFacebook C# (CSharp) Method

UploadToFacebook() public method

public UploadToFacebook ( MemoryStream ms ) : string
ms MemoryStream
return string
        public string UploadToFacebook(MemoryStream ms)
        {
            // TODO: Make progressbar functional for C# Facebook SDK.
            //       Limitation in current C# Facebook SDK makes us unable to track progress of photo uploads.
            this.ProgressBar.Start("Facebook", ms.Length);

            string url = "";
            try {
                ms.Seek(0, SeekOrigin.Begin);

                FacebookMediaStream img = new FacebookMediaStream();
                img.ContentType = "image/png";
                img.FileName = this.RandomFilename(5) + ".png";
                img.SetValue(ms);

                Dictionary<string, object> photoParams = new Dictionary<string, object>();
                // TODO: Some way to attach a message to an image
                //photoParams["message"] = message;
                photoParams["image"] = img;
                dynamic ret = this.facebookClient.Post("/me/photos", photoParams);

                string photoID = ret.id;
                url = "https://" + "www.facebook.com/photo.php?fbid=" + photoID;

                this.AddLog(url, (ms.Length / 1000) + " kB");
            } catch (Exception ex) {
                this.Debug("UploadToFacebook threw " + ex.GetType().FullName + ": '" + ex.Message + "'");
            }

            this.ProgressBar.Done();

            return url;
        }