File.StartUpload - uploads empty file

Pavithra Eswara Murthy 25 Reputation points

Trying to test upload file using File.StartUpload but end up uploading empty file.User's image

A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
8,089 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. ChengFeng - MSFT 3,765 Reputation points Microsoft Vendor

    Hi @Pavithra Eswara Murthy

    From your code, I haven't found the key to the problem.

    Could you tell me what effect you want to achieve with this code, and can you provide more information?

    I can only figure out a few things that might be causing the problem from the code you provided

    We analyze the problem from several angles:

    1. The file data is not read correctly: Make sure that when using FileStream to read file data, the data is correctly read into the buffer array. Check that the file path is correct and that the file exists. You could add some debug output to confirm that the data was read correctly.
    2. Memory stream position problem: When using MemoryStream, make sure to reset the position of the stream to the start position before reading or writing, so that you can start reading or writing data from the correct position. Use contentStream.Seek(0, SeekOrigin.Begin) and s.Seek(0, SeekOrigin.Begin) to ensure the stream position is correct.
    3. Problem with the target folder path: Make sure that the folder path specified in uploadFileUrl exists in SharePoint, otherwise it may cause the file to be uploaded to the wrong location or fail to upload.

    In order to locate the problem, you can try the following steps:

    Add debug output in the key code segment, and output the value of key variables, such as file path, buffer length, MemoryStream length, etc.

    Here is a link about startupload for your reference:

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards

    Cheng Feng

    0 comments No comments