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

Initial directory

2 Answers 132 Views
PdfViewer and PdfViewerNavigator
This is a migrated thread and some comments may be shown as answers.
Frédéric
Top achievements
Rank 1
Frédéric asked on 08 Nov 2017, 01:46 PM

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 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 09 Nov 2017, 02:03 PM
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.
0
Frédéric
Top achievements
Rank 1
answered on 10 Nov 2017, 07:01 AM

Hi Hristo,

Thanks for your answer, it works perfectly.

Regards

Tags
PdfViewer and PdfViewerNavigator
Asked by
Frédéric
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Frédéric
Top achievements
Rank 1
Share this question
or