facebook c# sdk を使用して Windows Phone アプリを開発しています。Facebook ウォールに写真をアップロードする際に問題が発生しています。「var imageStream = File.OpenRead(imagepath);」という行で例外が発生しました。私はここで何を間違えましたか??
void cameraCaptureTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
Uri uri = new Uri(e.OriginalFileName, UriKind.RelativeOrAbsolute);
//Code to display the photo on the page in an image control named myImage.
WriteableBitmap bmp = PictureDecoder.DecodeJpeg(e.ChosenPhoto);
myImage.Source = bmp;
imageSource = this.SaveImageToLocalStorage(bmp,System.IO.Path.GetFileName(e.OriginalFileName));
}
}
private string SaveImageToLocalStorage(WriteableBitmap image, string imageFileName)
{
if (image == null)
{
throw new ArgumentNullException("imageBytes");
}
try
{
var isoFile = IsolatedStorageFile.GetUserStoreForApplication();
if (!isoFile.DirectoryExists("MyPhotos"))
{
isoFile.CreateDirectory("MyPhotos");
}
string filePath = System.IO.Path.Combine("/" + "MyPhotos" + "/", imageFileName);
using (var stream = isoFile.CreateFile(filePath))
{
image.SaveJpeg(stream, image.PixelWidth, image.PixelHeight, 0, 80);
}
return new Uri(filePath, UriKind.Relative).ToString();
}
catch (Exception)
{
throw;
}
}
private void ApplicationBarIconButton_Click(object sender, EventArgs e)
{
postImage(App.AccessToken,titleBox.Text + descriptionBox.Text, imageSource);
}
private void postImage(string p1, string p2, string imagepath)
{
FacebookClient fb = new FacebookClient(p1);
var imageStream = File.OpenRead(imagepath);
dynamic res = fb.PostTaskAsync("/me/photos", new
{
message = p2,
file = new FacebookMediaStream
{
ContentType = "image/jpg",
FileName = Path.GetFileName(imagepath)
}.SetValue(imageStream)
});
}