views:

20

answers:

1

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.PackagePart.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.

+1  A: 

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.

Pieter
So the /SilverlightApplication; part would be the name of the project? Say I had the file in Project 'XYZ' under the folder 'Views'. How would I enter that?
TheAdamGaskins