This is a migrated thread and some comments may be shown as answers.

Application.GetResourceStream Returns Null

4 Answers 456 Views
Book
This is a migrated thread and some comments may be shown as answers.
Dan Slaby
Top achievements
Rank 1
Dan Slaby asked on 02 Dec 2011, 06:03 AM
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.

4 Answers, 1 is accepted

Sort by
0
Dan Slaby
Top achievements
Rank 1
answered on 03 Dec 2011, 07:28 PM
I found the problem - I needed to set the Build Action in Properties to Resource.
0
Petar Mladenov
Telerik team
answered on 06 Dec 2011, 09:30 AM
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 >>

0
Mohammad
Top achievements
Rank 1
answered on 20 May 2013, 05:14 AM
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
9970848286

0
Tina Stancheva
Telerik team
answered on 22 May 2013, 12:02 PM
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.

Regards,
Tina Stancheva
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Book
Asked by
Dan Slaby
Top achievements
Rank 1
Answers by
Dan Slaby
Top achievements
Rank 1
Petar Mladenov
Telerik team
Mohammad
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or