System.IO.File 不包含 ReadAllBytes C# [英] System.IO.File does not contain ReadAllBytes C#
本文介绍了System.IO.File 不包含 ReadAllBytes C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 C# 中,我正在为 WP7 创建简单的 Facebook 应用程序,但遇到了一个问题.
In C# I am creating simple facebook application for WP7 and I came across a problem.
我正在尝试让您可以在相册或提要中上传图片.
I'm trying to do the part where you can upload a picture in the album or feed.
代码:
FacebookMediaObject facebookUploader = new FacebookMediaObject { FileName = "SplashScreenImage.jpg", ContentType = "image/jpg" };
var bytes = System.IO.File.ReadAllBytes(Server.MapPath("~") + facebookUploader.FileName);
facebookUploader.SetValue(bytes);
错误:
- System.IO.File 不包含 ReadAllBytes 的定义
推荐答案
我找到了解决方案.
代码:
string imageName = boxPostImage.Text;
StreamResourceInfo sri = null;
Uri jpegUri = new Uri(imageName, UriKind.Relative);
sri = Application.GetResourceStream(jpegUri);
try
{
byte[] imageData = new byte[sri.Stream.Length];
sri.Stream.Read(imageData, 0, System.Convert.ToInt32(sri.Stream.Length));
FacebookMediaObject fbUpload = new FacebookMediaObject
{
FileName = imageName,
ContentType = "image/jpg"
};
fbUpload.SetValue(imageData);
IDictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("access_token", _AccessToken);
parameters.Add("source", fbUpload);
//_fbClient.PostAsync("/"+MainPage._albumId+"/photos", parameters);
_fbClient.PostAsync("/me/photos", parameters);
MessageBox.Show("Image has been posted successfully..");
}
catch (Exception error)
{
MessageBox.Show("Sorry, there's an error occured, please try again.");
}
这篇关于System.IO.File 不包含 ReadAllBytes C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文