Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

How to serialize an image

$
0
0

Hi Xamarin Forum

I was able to pull data and image from my database but now I want to serialize my data that I have pulled, Im having an error that says

Error getting value from 'ReadTimeout' on 'System.IO.MemoryStream'

anyways here is my code for pulling and serializing into Json

string SystemPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            string filename = "pulled_data.json";
            string filePath = Path.Combine(SystemPath, "pulled_data.json");

            if (!File.Exists(filePath))
            {
                File.Create(Path.Combine(SystemPath, filename)).Dispose();

                DataSet ds = new DataSet();
                Pipeline databaseConnect = new Pipeline();

                SqlCommand selectPost = new SqlCommand("SELECT * FROM t_Post ORDER BY Id DESC", databaseConnect.connectDB());
                SqlDataReader reader = selectPost.ExecuteReader();
                postslist = new List<Post>();
                while (reader.Read())
                {
                    string postContent = (string)reader["Post_Content"];
                    string uploader = (string)reader["Uploader"];
                    var stream = reader["Photo"];
                    string imageUrl = Convert.ToBase64String((byte[])reader["Photo"]);
                    var postWall = new Post
                    {
                        PhotoSource = imageUrl,
                        PostContent = postContent,
                        Uploader = uploader
                    };
                    postslist.Add(postWall);
                    json = JsonConvert.SerializeObject(postslist);
                }
                listViewPost.ItemsSource = postslist;

                using (var file = File.Open(filePath, FileMode.Create, FileAccess.Write))
                {
                    using (var strms = new StreamWriter(file))
                    {
                        strms.Write(json);
                        strms.Close();
                    }
                    file.Close();
                }
            }
            else
            {
                DisplayAlert("Alert", "Exist", "OK");
            }

Am I missing something? :)


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>