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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:05:40+00:00 2026-06-16T20:05:40+00:00

I am unable to send the facebook status with image. Found the code but

  • 0

I am unable to send the facebook status with image. Found the code but it throws the
exception

The Safe handle is closed

kindly let me know if i am missing something.
there was another example where File.OpenRead(filename) was used but it threw the UnAuthorizedAccessException

the code is following :

public static Stream ImageToShare
        {
        set
            {
                try
                {
                    using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        if (myIsolatedStorage.FileExists(ImageToShareKey))
                            myIsolatedStorage.DeleteFile(ImageToShareKey);

                        IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(ImageToShareKey);

                        StreamResourceInfo sri = null;
                        Uri uri = new Uri(ImageToShareKey, UriKind.Relative);
                        sri = Application.GetResourceStream(uri);

                        BitmapImage bitmap = new BitmapImage();
                        bitmap.SetSource(value);
                        //bitmap.SetSource(sri.Stream);
                        WriteableBitmap wb = new WriteableBitmap(bitmap);

                        Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
                        fileStream.Close();
                    }
                }
                catch (Exception ex)
                {
                    AppHelper.ErrorOccured(ex);
                }
            }

private void postFBWithImage()
        {
            try
            {

                using (IsolatedStorageFile myFile = IsolatedStorageFile.GetUserStoreForApplication())
                using (IsolatedStorageFileStream stream = myFile.OpenFile("SharePhoto", FileMode.Open, FileAccess.Read))
                using (var imgFile = new FacebookMediaStream
                {
                    ContentType = "image/jpeg",
                    FileName = Path.GetFileName(imgPath.Text),
                }.SetValue(stream))
                {

                    var fb = new FacebookClient(AppSettings.FacebookPIN);
                    fb.PostCompleted += (o, args) =>
                    {
                        if (args.Error != null)
                        {
                            notPosted(args);
                            return;
                        }

                        Dispatcher.BeginInvoke(() =>
                        {
                            posted();
                        });
                    };

                    fb.PostAsync("me/photos", new { message = ShareComments, imgFile });
                }
            }
            catch (Exception ex)
            {
                AppHelper.ErrorOccured(ex);
                postFBWithoutImage();
            }
        }
  • 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-06-16T20:05:43+00:00Added an answer on June 16, 2026 at 8:05 pm

    sending image with facebook status through media stream is not good as it creates trouble with isolatedStorage streams. best way is to move parameters in Dictionary object rather than anonymous objects. so there are totally 2 changes. one from FacebookMediaStream to FacebookMediaObject and second is the use of Dictionary object instead of using anonymous object

    following is the code to describe the scenario.

     private void postFBWithImage()
        {
            try
            {
                using (IsolatedStorageFile myFile = IsolatedStorageFile.GetUserStoreForApplication())
                using (IsolatedStorageFileStream stream = myFile.OpenFile(AppSettings.ImageToShareKey, FileMode.Open, FileAccess.Read))
                {
                    byte[] byteArr = null;
                    using (var binRdr = new BinaryReader(stream))
                    using (var memStr = new MemoryStream())
                    {
                        const int ReadSize = 8196;
                        int chunkSize = 0;
                        do
                        {
                            byte[] buf = new byte[ReadSize];
                            chunkSize = binRdr.Read(buf, 0, ReadSize);
                            memStr.Write(buf, 0, ReadSize);
                        } while (chunkSize > 0);
    
                        byteArr = new byte[memStr.Length];
                        memStr.Position = 0;
                        memStr.Read(byteArr, 0, (int)memStr.Length);
                    }
    
                    var fb = new FacebookClient(AppSettings.FacebookPIN);
                    fb.PostCompleted += (o, args) =>
                    {
                        if (args.Error != null)
                        {
                            notPosted(args);
                            return;
                        }
    
                        Dispatcher.BeginInvoke(() =>
                        {
                            posted();
                        });
                    };
    
                    var parameters = new Dictionary<string, object>();
                    parameters["message"] = ShareComments;
                    parameters["file"] = new FacebookMediaObject
                        {
                            ContentType = "image/jpeg",
                            FileName = "image.jpeg",
                        }.SetValue(byteArr);
                    fb.PostAsync("me/photos", parameters);
    
                }
            }
            catch (Exception ex)
            {
                AppHelper.ErrorOccured(ex);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My following code is unable to send message text. It is able to send
I'm unable to display the whole Facebook Send Button in IE7. However, It's working
I want to use the cakePHP mailer system, but I am unable to send
I am unable to send a message to a XMPP client on an openfire
I have developed a WCF WebService. On client side they are unable to send
I'm getting an Unable to obtain public key for StrongNameKeyPair. exception using Newtonsoft's JsonConvert.SerializeObject
The 32-bit version of our app is unable to send email using MAPISendMail with
Hi guys for some weird reason I'm unable to send email using zend mail
I am using db mail(sql server 2005) to send bulk email(>2000). The code tat
The following is the program, which I am trying to send e-mail. The code

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.