Upload file to skydrive through SkyDrive API

后端 未结 3 1632
说谎
说谎 2020-12-17 06:17

I try to upload a text file to my skydrive or at least create new text file in SD and edit it\'s content, through SkyDrive API in my Windows 8 application. How can I do that

相关标签:
3条回答
  • 2020-12-17 06:32

    Here's another way to upload a file from a console application using a SkyDriveApiClient downloaded from http://skydriveapiclient.codeplex.com/releases/view/103081

        static void Main(string[] args)
        {
            var client = new SkyDriveServiceClient();
    
            client.LogOn("YourEmail@hotmail.com", "password");
            WebFolderInfo wfInfo = new WebFolderInfo();
    
            WebFolderInfo[] wfInfoArray = client.ListRootWebFolders();
    
            wfInfo = wfInfoArray[0];
            client.Timeout = 1000000000;
    
            string fn = @"test.txt";
            if (File.Exists(fn))
            {
                client.UploadWebFile(fn, wfInfo);
            }
    
        }
    
    0 讨论(0)
  • 2020-12-17 06:38

    You should use the Upload method on LiveConnectionClient. For example, see the Uploading Files example in the Live SDK. Something like ...

    LiveOperationResult fileOperationResult =
         await client.Upload("me/skydrive", /*file name here*/, /*file stream here*/);
    
    0 讨论(0)
  • 2020-12-17 06:47

    Close but as I wrote: I can't use client.upload method because LiveConnectClient class doesn't contain it. That's why I asked about site content update.

    Anyway - I've got an answer:

    //create a StorageFile (here is one way to do that if it is stored in your ApplicationData)
    StorageFile file = awaitApplicationData.Current.LocalFolder.GetFileAsync("yourfilename.txt");
    
    try {
       client = new LiveConnectClient(session);
       LiveOperationResult operationResult = await client.BackgroundUploadAsync("me/skydrive", file.Name, file, OverwriteOption.Overwrite);
    }
    catch (LiveConnectException exception) {
      //handle exception                
    }
    
    0 讨论(0)
提交回复
热议问题