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

  • Home
  • SEARCH
  • 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 6703179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:08:26+00:00 2026-05-26T07:08:26+00:00

So I must be doing something wrong here, just not sure what it is

  • 0

So I must be doing something wrong here, just not sure what it is yet. My original PoC worked fine, but wasn’t MVVM, so I have lost something in the translation.

So I browse to a file to choose for an upload, everything starts working fine. It transfers the first chunk up to the server and then my complete event is never called. And that will be sending all of the additional chunks in the array, so the file is incomplete.

Am I just missing a step?

And if it matters, the service is setup on IIS7, but I’m not sure if anything needs to be setup on the service side to make this happen. It just ‘worked’ in the PoC code when I was using the XAML code-behind.

Model Code:

public void uploadChunks(int index, string fileName)
    {
        FileUpload fileUpload = new FileUpload();
        FileUpload.FileName = fileName;
        FileUpload.chunk = fileChunks[index];

        context.UploadFileAsync(fileUpload);
    }

FileUploadServiceSoapClient context = new FileUploadServiceSoapClient("BasicHttpBinding_FileUploadServiceSoap");

    int chunkSize = 15306;
    public List<byte[]> fileChunks;
    public double TotalChunks { get; set; }

    /// <summary>
    /// Convert file to an array of file chunks to stream to the upload location
    /// </summary>
    /// <param name="imageFile"></param>
    public void convertToChunks(byte[] imageFile)
    {
        TotalChunks = Math.Ceiling((double)imageFile.Length / (double)chunkSize);
        fileChunks = new List<byte[]>();

        for (int i = 0; i < TotalChunks; i++)
        {
            byte[] chunk;

            int startIndex = i * chunkSize;
            if (startIndex + chunkSize > imageFile.Length)
                chunk = new byte[imageFile.Length - startIndex];
            else
                chunk = new byte[chunkSize];

            Array.Copy(imageFile, startIndex, chunk, 0, chunk.Length);

            fileChunks.Add(chunk);
        }
    }

ViewModel Code

public UploadViewModel()
    {
        uploadModel = new UploadModel(); // important – must initialize model
        OpenFileCommand = new RelayCommand(OpenDialog);

        StatusText = "Please select a file to upload";

        context.UploadFileCompleted += new EventHandler<AsyncCompletedEventArgs>(context_UploadFileCompleted);
    }

 private void OpenDialog()
    {
        OpenFileDialog ofd = new OpenFileDialog();
        if ((bool)ofd.ShowDialog())
        {
            _fileName = ofd.File.Name;
            FileStream fs = ofd.File.OpenRead();
            fileSize = (double)fs.Length;
            index = 0;
            sendData = 0;

            byte[] file = new byte[fs.Length];
            fs.Read(file, 0, file.Length);

            // call our model and convert file into chunks
            uploadModel.convertToChunks(file);

            // start upload process, this only sends the first chunk all subsquent chunks
            // are sent on the context_UploadFileToCrmCompleted function
            uploadModel.uploadChunks(index, _fileName);
        }
    }

void context_UploadFileCompleted(object sender, AsyncCompletedEventArgs e)
    {
        if (e.Error == null)
        {
            sendData += uploadModel.fileChunks[index].Length;
            TotalFileSize = byteTranslation(sendData) + "/" + byteTranslation(fileSize);

            if ((index + 1) < uploadModel.fileChunks.Count)
            {
                this.CurrentProgress = index / uploadModel.fileChunks.Count;

                index += 1;
                uploadModel.uploadChunks(index, _fileName);
            }
            else
            {
                StatusText = "Successfully uploaded. Submitting to the file repository...";

                // Submit the upload to SharePoint
            }
        }
    }
  • 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-05-26T07:08:27+00:00Added an answer on May 26, 2026 at 7:08 am

    I hope I am not missing anything… do you have two FileUploadServiceSoapClients?

    One in the ViewModel and one in the model. You are calling the service in the model but the completed handler is assigned to the context of the ViewModel.

    So you have to write

    uploadModel.context.UploadFileCompleted += new EventHandler<AsyncCompletedEventArgs>(context_UploadFileCompleted); 
    

    instead of

    context.UploadFileCompleted += new EventHandler<AsyncCompletedEventArgs>(context_UploadFileCompleted);
    

    Probably you should better not use the ServiceClient directly in the viewModel but pass a callback or let the model raise an own event.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm sure I must be doing something wrong. But can't for the life of
There must be something obvious that I'm doing wrong, but I'm not seeing it.
I must be doing something obviously wrong here. But what is it, and how
I must be doing something wrong here but I can't find an easy way
I must be doing something wrong here (because really, what are the chances of
I find this very strange, must be something I'm doing wrong, but still... I'm
I must be doing something wrong here, any ideas? >>> (datetime.datetime(2008,11,7,10,5,14)-datetime.datetime(2008,11,6,9,30,16)).seconds 2098 It should
I think I must be doing something wrong here because my code only sent
I might be doing something completely wrong here but for some reason the values
I must be doing something wrong. I can't seem to execute my CustomValidator's ServerValidate

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.