我正在使用 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)
});
}