Application.GetResourceStream Returns Null

5 posts, 0 answers
  1. Dan Slaby
    Dan Slaby avatar
    4 posts
    Member since:
    Jul 2003

    Posted 02 Dec 2011 Link to this post

    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()
                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);
                    MessageBox.Show("Unknown format.");

                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);


       = 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");
       = 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;

    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.

  2. Dan Slaby
    Dan Slaby avatar
    4 posts
    Member since:
    Jul 2003

    Posted 03 Dec 2011 Link to this post

    I found the problem - I needed to set the Build Action in Properties to Resource.
  3. DevCraft banner
  4. Petar Mladenov
    Petar Mladenov avatar
    2882 posts

    Posted 06 Dec 2011 Link to this post

    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.

    Petar Mladenov
    the Telerik team

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

  5. Mohammad
    Mohammad avatar
    2 posts
    Member since:
    May 2013

    Posted 20 May 2013 Link to this post

    Hi All, 
    I am also getting same issue. Getting null exception when trying to load .pdf from the path.
    my code is as below. i have also set the Build Action property = resources of .xap file. kindly help me how to resolve this issue.

     this.documentStream = App.GetResourceStream(new Uri("PDF-Veiwer;component/SampleData/Book.pdf"UriKind.Relative)).Stream;

    my solution name is = PDF-Veiwer
    Folder name = SampleData
    File Name = Book.pdf

    Thanks in Advance
    Mohammad Sharique

  6. Tina Stancheva
    Tina Stancheva avatar
    3298 posts

    Posted 22 May 2013 Link to this post

    Hi Mohammad,

    You actually need to set the Book.pdf BuildAction to Resource. If this doesn't help, can you please send over a sample project demonstrating your approach so that we can further investigate it locally? Thank you in advance.

    Tina Stancheva

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
DevCraft banner