Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > Book > Application.GetResourceStream Returns Null

Not answered Application.GetResourceStream Returns Null

Feed from this thread
  • Dan Slaby avatar

    Posted on Dec 2, 2011 (permalink)

    Here are my code (copy to NotePad then paste looks better):

        public partial class MainPage : UserControl
        {
            private const string DocumentPath = "CageManagementFeatures.docx";
            private RadDocumentBindingSource bindingSource = new RadDocumentBindingSource();
            private DocumentViewManager viewManager;

            public MainPage()
            {
                InitializeComponent();
                this.viewManager = (DocumentViewManager)this.Resources["viewManager"];
            }

            private void LoadDocument(Stream stream, string extension)
            {
                RadDocument doc;

                IDocumentFormatProvider provider = DocumentFormatProvidersManager.GetProviderByExtension(extension);
                if (provider != null)
                {
                    doc = provider.Import(stream);
                }
                else
                {
                    MessageBox.Show("Unknown format.");
                    return;
                }

                doc.Measure(RadDocument.MAX_DOCUMENT_SIZE);
                doc.Arrange(new RectangleF(PointF.Empty, doc.DesiredSize));

                doc.LayoutMode = DocumentLayoutMode.Paged;

                doc.DefaultPageLayoutSettings.Width = 320 / 0.7F;
                doc.DefaultPageLayoutSettings.Height = 390 / 0.7F;
                doc.SectionDefaultPageMargin = new Padding(55);
                doc.Sections.First.PageMargin = new Padding(55);

                doc.UpdateLayout();

                this.book.RightPageIndex = 0;
                this.viewManager.Document = doc;
                bindingSource.Document = doc;
            }

            private void UserControl_Loaded(object sender, RoutedEventArgs e)
            {
                <!-- NULL ERROR OCCURS IN THIS LINE-->
                using (Stream stream = Application.GetResourceStream(this.GetResourceUri(DocumentPath)).Stream)
                {
                    this.LoadDocument(stream, ".docx");
                }
                this.book.ItemsSource = bindingSource;
            }

            private Uri GetResourceUri(string resource)
            {
                AssemblyName assemblyName = new AssemblyName(this.GetType().Assembly.FullName);
                string resourcePath = "/" + assemblyName.Name + ";component/" + resource;
                Uri resourceUri = new Uri(resourcePath, UriKind.Relative);

                return resourceUri;
            }

            private void Simulation_Click(object sender, RoutedEventArgs e)
            {
                book.Visibility = Visibility.Collapsed;
                radMediaPlayer1.Visibility = Visibility.Visible;
                radMediaPlayer1.Play();
            }
        }
    }


    1. Why am I getting a Null Value when stepping through the code shows a
    value in the GetResourceUri return value?
    2. I have the document in a folder "Documents/Cage Management Features.docx"
    which didn't work and so I placed it in the root folder and removed spaces,
    but that didn't work either.
    3. The mainpage.xaml is copied from the sample.
    Any suggestions would be appreciated. Thank you.

    Reply

  • Dan Slaby avatar

    Posted on Dec 3, 2011 (permalink)

    I found the problem - I needed to set the Build Action in Properties to Resource.

    Reply

  • Petar Mladenov Petar Mladenov admin's avatar

    Posted on Dec 6, 2011 (permalink)

    Hi Dan Slaby,

     We are glad to hear that you have resolved your issue. Please do not hesitate to contact us if you need further assistance.

    Greetings,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > Book > Application.GetResourceStream Returns Null