示例#1
0
        public override UploadResult Upload(Stream stream, string fileName)
        {
            if (!CheckAuthorization())
            {
                return(null);
            }

            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("access_token", AuthInfo.Token.access_token);
            args.Add("overwrite", "true");
            args.Add("downsize_photo_uploads", "false");

            string folderPath;

            if (!string.IsNullOrEmpty(FolderID))
            {
                folderPath = URLHelpers.CombineURL(FolderID, "files");
            }
            else
            {
                folderPath = "me/skydrive/files";
            }

            string url = CreateQuery(URLHelpers.CombineURL("https://apis.live.net/v5.0", folderPath), args);

            UploadResult result = UploadData(stream, url, fileName);

            if (result.IsSuccess)
            {
                OneDriveFileInfo uploadInfo = JsonConvert.DeserializeObject <OneDriveFileInfo>(result.Response);

                if (AutoCreateShareableLink)
                {
                    result.URL = CreateShareableLink(uploadInfo.id);
                }
                else
                {
                    result.URL = uploadInfo.source;
                }
            }

            return(result);
        }
        private void OneDriveAddFolder(OneDriveFileInfo folder, TreeNode tnParent)
        {
            TreeNode tn = new TreeNode(folder.name);
            tn.Tag = folder;
            tn.Nodes.Add(new TreeNode(Resources.UploadersConfigForm_OneDriveAddFolder_Querying_folders___));

            if (tnParent != null)
            {
                tnParent.Nodes.Add(tn);
            }
            else
            {
                tvOneDrive.Nodes.Add(tn);
            }
        }
 public void OneDriveListFolders(OneDriveFileInfo fileEntry, TreeNode tnParent)
 {
     Application.DoEvents();
     OneDrive oneDrive = new OneDrive(Config.OneDriveOAuth2Info);
     OneDrivePathInfo oneDrivePathInfo = oneDrive.GetPathInfo(fileEntry.id);
     tnParent.Nodes.Clear();
     foreach (OneDriveFileInfo folder in oneDrivePathInfo.data.Where(x => x.id.StartsWith("folder.")))
     {
         OneDriveAddFolder(folder, tnParent);
     }
 }