Initial directory

3 posts, 0 answers
  1. Frédéric
    Frédéric avatar
    8 posts
    Member since:
    Oct 2017

    Posted 08 Nov 2017 Link to this post

    Hi,

    I'd like to change the initial directory used by Open and Save buttons. An InitialDirectory property like in OpenFileDialog would be perfect.

    Thanks for your help

     

     

  2. Hristo
    Admin
    Hristo avatar
    1393 posts

    Posted 09 Nov 2017 Link to this post

    Hi Frédéric,

    Thank you for writing.

    We have not received other request for similar properties so far. In case there is a demand for them, of course, we will consider adding such options. For the time being, you can accomplish your task by handling the MouseDown events of the open and save buttons in the RadPdfViewerNavigator. Please check my code snippet below: 
    public class Form1
    {
     
     
        public Form1()
        {
            InitializeComponent();
     
            this.RadPdfViewer1.LoadDocument("..\\..\\sample.pdf");
     
            this.RadPdfViewerNavigator1.OpenButton.MouseDown += OpenButton_MouseDown;
            this.RadPdfViewerNavigator1.SaveButton.MouseDown += SaveButton_MouseDown;
        }
     
        private void OpenButton_MouseDown(object sender, MouseEventArgs e)
        {
            if (this.RadPdfViewer1.PdfViewerElement == null) {
                return;
            }
     
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = "C:\\Users\\Administrator\\Desktop";
            openFileDialog.Filter = "PDF Files|*.pdf";
            openFileDialog.Title = "Select a PDF File";
            if (openFileDialog.ShowDialog() == DialogResult.OK) {
                this.RadPdfViewer1.PdfViewerElement.LoadDocument(openFileDialog.FileName);
                this.RadPdfViewerNavigator1.UpdatePageCount();
            }
        }
     
        private void SaveButton_MouseDown(object sender, MouseEventArgs e)
        {
            string fileName = (string)typeof(RadPdfViewerElement).GetField("fileName", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this.RadPdfViewer1.PdfViewerElement);
            SaveFileDialog savefile = new SaveFileDialog();
            savefile.InitialDirectory = "C:\\Users\\Administrator\\Desktop";
            savefile.FileName = fileName;
            savefile.Filter = "PDF files (*.pdf)|*.pdf|All files (*.*)|*.*";
     
            if (savefile.ShowDialog() == DialogResult.OK) {
                this.RadPdfViewer1.PdfViewerElement.SaveDocument(savefile.FileName);
            }
        }
    }

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Frédéric
    Frédéric avatar
    8 posts
    Member since:
    Oct 2017

    Posted 10 Nov 2017 in reply to Hristo Link to this post

    Hi Hristo,

    Thanks for your answer, it works perfectly.

    Regards

Back to Top