在 C# 中,我正在为 WP7 创建简单的 facebook 应用程序,但遇到了一个问题。
我正在尝试做可以在相册或提要中上传图片的部分。
Code:
FacebookMediaObject facebookUploader = new FacebookMediaObject { FileName = "SplashScreenImage.jpg", ContentType = "image/jpg" };
var bytes = System.IO.File.ReadAllBytes(Server.MapPath("~") + facebookUploader.FileName);
facebookUploader.SetValue(bytes);
Error:
- System.IO.File 不包含 ReadAllBytes 的定义
你那里有几个问题。首先,Server.MapPath 不会为您提供文件位置(因为您不在 Web 应用程序中)。但是,一旦您知道要查找的文件路径(在isolatedStorage中),您就可以执行类似的操作以字节数组的形式读入文件:
public byte[] ReadFile(String fileName)
{
byte[] bytes;
using (IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream file = appStorage.OpenFile(fileName, FileMode.Open, FileAccess.Read))
{
bytes = new byte[file.Length];
var count = 1024;
var read = file.Read(bytes, 0, count);
var blocks = 1;
while(read > 0)
{
read = file.Read(bytes, blocks * count, count);
blocks += 1;
}
}
}
return bytes;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)