Error when i try to upload a file to onedrive windows phone c# RRS feed

  • Question

  • Hi, i'm trying to upload a file to onedrive  but i get  a  "System.NullReferenceException: Object reference not set to an instance of an object."

    Here's my code 

    Firstly  i try to copy  the image file by this method

         public static async Task<String> copyFileAsync(String fileName)
                //New File name
                   string newFileName = "ScouterPrueba" +   Guid.NewGuid().ToString().Substring(0, 4) + ".jpg";
                // get local folder.
                StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
                //get shellContent folder
                var ShellContent = await local.GetFolderAsync(@"Shared\ShellContent");
                //get transfers folder
                var Tranfers=await local.GetFolderAsync( @"Shared\Transfers\");
                //get the file that i will copy
                var file = await ShellContent.GetFileAsync(fileName);
                //now we copy the file
                var fileCopy = await file.CopyAsync(Tranfers,newFileName);
                //now we return the new fileName
                return newFileName;

    secondly in my ViewModel i call the following method 

     public async void actionOneDriveUpload()
                string wellFileName = this.selectedImageUri.OriginalString.Replace("isostore:/Shared/ShellContent/",string.Empty);
                string fileName =await Helpers.ImageHelper.copyFileAsync(wellFileName);
                await skyDriveClient.BackgroundUploadAsync("me/skydrive", new Uri("Shared/Transfers/"+fileName, UriKind.Relative), OverwriteOption.Overwrite);

    The method to copy images files  works perfectly but when I try to send the file to   oneDrive  the following exception occurs

    System.NullReferenceException: Object reference not set to an instance of an object

    Blog Saludos desde México DF

    Saturday, June 7, 2014 10:12 PM

All replies

  • At what line of code does this exception occur?  Is it in the client code or is it returned by the server?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, June 9, 2014 1:26 PM