Reputation: 15
I'm writing a wp8 app. I have a problem bothers me a few days. I want to uplaod an photo to server. I choose a photo from album and I use FileStream to upload it, but I cannot open it. It said that access to the path is denied.
PhotoChooserTask photoChooserTask = new PhotoChooserTask();
photoChooserTask.Completed += new EventHandler<PhotoResult>(photoChooserTask_Completed);
void photoChooserTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
// show the img
BitmapImage bmp = new BitmapImage();
bmp.SetSource(e.ChosenPhoto);
ShowPhoto.Source = bmp;
// get path of img
string imagePath = e.OriginalFileName;
}
}
upload
if (imagePath != null)
{
FileStream fs = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
StreamContent imageContent = new StreamContent(fs);
}
At the line: FileStream fs = new FileStream(imagePath, FileMode.Open, FileAccess.Read); I encountered an error.
System.UnauthorizedAccessException: Access to the path 'C:\Data\Users\Public\Pictures\Camera Roll\WP_20140331_001.jpg' is denied.
I have chosen the function `D_CAP_MEDIALIB_PHOTO in WMAppMainfest.xml
Upvotes: 0
Views: 1722
Reputation: 456
I saw that u solved ur problem by urself still no solving code here i hope someone will find use for it :)
var imageAsByteArray = File.ReadAllBytes(imagePath);
// I use as example a pictureBox:
pictureBox1.Image = byteArrayToImage(imageAsByteArray);
// Or safe/copy/replace it:
File.WriteAllBytes(picture_Path, imageAsByteArray);
You also can delete the (new) picture instantly ! (if you want)
Upvotes: 0
Reputation: 759
I dont think you can access the Camera Roll like that. You may have to user MediaLibrary class for the same. Also, you have the image in the PhotoChooserTask_Completed event handler. You don't have to get in a File Stream.
Upvotes: 1