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.
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:
You've got a couple of problems there. First off, Server.MapPath isn't going to give you the file location (since you're not in a web application). But once you do know the file path you're looking for (in IsolatedStorage), you can do something like this to read in the file as a byte array:
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With