Click here to Skip to main content
15,435,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Overview: I would like to take a screenshot, turn it into a byte array and then upload it to a server. I'm using Xamarin.Forms for Visual Studio Mac.

The target device is an Android Emulator Tablet.

Tried a lot but I'm not that good in C#.

The piece of code I want to implement:

byte[] buffer = System.IO.File.ReadAllBytes("");//provide the path of the .PNG in the ("please help me find the path")

The code I want to implement it in:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NativeMedia;
using Xamarin.Essentials;
using Xamarin.Forms;

namespace UploadingFiles
    public partial class MainPage : ContentPage
        public MainPage()

        private async void DoPDFThings(object sender, EventArgs e)
            var screenshot = await Screenshot.CaptureAsync(); 

            await MediaGallery.SaveAsync(MediaFileType.Image, await screenshot.OpenReadAsync(), "myScreenshot.png");


What I have tried:

I have tried to paste it under my code but then I got multiple red underlines.
Updated 3-Jun-22 0:09am
Richard MacCutchan 3-Jun-22 7:36am    
You have probably pasted it in the wrong place, or inadvertently deleted some control character. Try again and examine the result carefully.

1 solution

Did you try Google Search? Here is what I tried: Xamarin C# how to send an image to a server[^]

Found many solutions. This YouTube video looks good: Upload File from Xamarin app to ASP.NET server - YouTube[^]
Share this answer
CharbelMansour 3-Jun-22 8:41am    
I have all I need I just need help with implementation but thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900