开发者

Application.GetResourceStream throws IOException

I'm working on a Version History dialog box, and I created a sample to test it. It seems, however, that the sample can't find the HTML file:

        var dlg = new VersionHistoryDialog();
        var uri = new Uri(@"pack://application:,,,/VersionHistory.html", UriKind.Absolute);
        var source = Application.GetResourceStream(uri).Stream; // This line throws the error
        dlg.Stream = source;
        var result = dlg.ShowDialog();
        label1.Content = result;

That line in the code above throws this error:

System.IO.IOException was unhandled
  Message=Cannot locate resource 'versionhistory.html'.
  Source=PresentationFramework
  StackTrace:
       at MS.Internal.AppModel.ResourcePart.GetStreamCore(FileMode mode, FileAccess access)
       at System.IO.Packaging.Packa开发者_如何学GogePart.GetStream(FileMode mode, FileAccess access)
       at System.IO.Packaging.PackagePart.GetStream()
       at System.Windows.Application.GetResourceStream(Uri uriResource)
    ....

So.... what do I do? The file is named "VersionHistory.html" and its in the same folder ("Views") as the xaml.cs file asking for it.


You need to include the assembly and path of the resource:

For example:

Application.GetResourceStream(new Uri("/SilverlightApplication;component/EmbeddedInApplicationAssembly.png", UriKind.Relative)))

With the pack and your example, you could specify:

Application.GetResourceStream(new Uri("pack://application:,,,/View/versionhistory.html"))

and the following should also work:

Application.GetResourceStream(new Uri("/XYZ;component/View/versionhistory.html", UriKind.Relative)))

See http://msdn.microsoft.com/en-us/library/ms596994(VS.95).aspx and http://msdn.microsoft.com/en-us/library/aa970069.aspx for more information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜