Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8251339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:12:13+00:00 2026-06-08T00:12:13+00:00

I have a bit of a problem with the client.UploadAsync method of Live SDK

  • 0

I have a bit of a problem with the client.UploadAsync method of Live SDK (SkyDrive SDK). My code for some reason doesn’t work or more specifically it uploads an empty file. It doesn’t throw any error and the serialization to stream works (I know that for sure).

It even seems that the Memory Stream is OK. (since I have no tool to really see the data in it I just guess it is OK by looking at its ‘Length’ property).

The UploadAsync method is fine as well or at least it worked well when I first serialized the data into a .xml file in IsolatedStorage then read it with IsolatedStorageFileStream and then eventualy send that stream. (then it uploaded the data)

Any advice on why this may be happening?

  public void UploadFile<T>(string skyDriveFolderID, T data, string fileNameInSkyDrive)
    {
        this.fileNameInSkyDrive = fileNameInSkyDrive;
        {
            try
            {
                memoryStream =  new MemoryStream();

                XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
                xmlWriterSettings.Indent = true;

                XmlSerializer serializer = new XmlSerializer(typeof(T));
                using (XmlWriter xmlWriter = XmlWriter.Create(memoryStream, xmlWriterSettings))
                {
                    serializer.Serialize(xmlWriter, data);
                }
                client.UploadAsync(skyDriveFolderID, fileNameInSkyDrive, true, memoryStream, null);

            }

            catch (Exception ex)
            {
                if (memoryStream != null) { memoryStream.Dispose(); }
            }
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T00:12:15+00:00Added an answer on June 8, 2026 at 12:12 am

    You have to “rewind” the memorystream to the start before calling the UploadAsync method. Imagine the memorystream being like a tape which you record things on. The “read/write-head” is always floating over some point of the tape, which is the end in your case because you just wrote all serialized data onto it. The uploading method tries to read from it by moving forward on the tape, realizing it is already at its end. Thus you get an empty file uploaded.

    The method you need for rewinding is:

    memoryStream.Seek(0, SeekOrigin.Begin);
    

    Also, it is good practice to use the using directive for IDisposable objects, which the memorystream is. This way you don’t need a try {...} finally { ...Dispose(); } (this is done by the using).

    Your method could then look like:

    public void UploadFile<T>(string skyDriveFolderID, T data, string fileNameInSkyDrive)
    {
        this.fileNameInSkyDrive = fileNameInSkyDrive;
    
        XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
        xmlWriterSettings.Indent = true;
    
        XmlSerializer serializer = new XmlSerializer(typeof(T));
    
        using (var memoryStream = new MemoryStream())
        {
            using (var xmlWriter = XmlWriter.Create(memoryStream, xmlWriterSettings))
            {
                serializer.Serialize(xmlWriter, data);
            }
    
            memoryStream.Seek(0, SeekOrigin.Begin);
    
            client.UploadAsync(skyDriveFolderID, fileNameInSkyDrive, true, memoryStream, null);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

all. I'm having a bit of weird problem with client server program. I have
I have a bit of a problem that I can't seem to code my
I have this bit of code: cerr << client->inventory.getMisc().front()->getName() << endl; vector<itemPtr>::iterator it; it
I have a bit of problem when trying to validate my page as HTML5.
I have a bit of a problem. I am trying to do the following
I have a bit of a problem building my project. I'm getting the bellow
I have a bit of a problem here. I have a third party ActiveX
So, I have a bit of a problem. I'm trying to convert an array
I'm quite new to MediaWiki, and now I have a bit of a problem.
I have a bit of a strange problem. I have a music app that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.