什么是System.UnauthorizedAccessException?

时间:2014-02-09 12:38:13

标签: c# windows-phone-7 windows-phone-8

我有这个代码,允许我的Windows手机的屏幕截图:

private void TakeScreenShot()
{

     // Take a screenshot 
     var screenshot = new WriteableBitmap(this, null);
     var screenshotname = String.Format("Screenshooter_{0}", DateTime.Now.Ticks);
     using (var ms = new MemoryStream())
     {
           screenshot.SaveJpeg(ms, 480, 800, 0, 85);
           ms.Seek(0, SeekOrigin.Begin);

           var library = new MediaLibrary();
           var pic = library.SavePicture(screenshotname, ms);
     }    
     MessageBox.Show(string.Concat("Screenshot saved as ", screenshotname));
}

但是我有一个exeption(System.UnauthorizedAccessException)这条指令:

var pic = library.SavePicture(screenshotname, ms);

如何抛出异常?提前谢谢。

2 个答案:

答案 0 :(得分:0)

如错误所述 - 您无权写信至MediaLibrary

您需要从功能标签中添加权限。

答案 1 :(得分:0)

操作系统因I / O错误或特定类型的安全错误而拒绝访问时引发的异常。资料来源:msdn 您似乎无法访问媒体库