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:
- 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.
- 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.
- 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:
https://github.com/kstrauss/SharepointUpload
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