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

Get current filename

3 Answers 35 Views
RichTextEditor
This is a migrated thread and some comments may be shown as answers.
Lee
Top achievements
Rank 1
Lee asked on 17 Feb 2015, 01:00 PM
Hi,

Is there a way to get the filename of the currently opened document when the Open dialog is used from the ApplicationMenu button group? I want to display current filename in the form caption.

Also, is there anyway to force RichTextEditor to ONLY use docx files (ideally looking to remove the other buttons from the Application menu).

Regards,

Lee.

3 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 18 Feb 2015, 03:07 PM
Hello Lee,

Thank you for contacting us.

1. You can hide the buttons with the following code:
BackstageViewPage savaAsPage = richTextEditorRibbonBar1.BackstageControl.Controls[0] as BackstageViewPage;
for (int i  = 1; i  <savaAsPage.Item.Page.Controls[0].Controls.Count; i ++)
{
    savaAsPage.Item.Page.Controls[0].Controls[i].Visible = false;
}

2. You can use the CommandExecuting event and show custom OpenFileDialog. This way you can open only docx files and you can get the file name:
void radRichTextEditor1_CommandExecuting(object sender, CommandExecutingEventArgs e)
{
    if (e.Command is OpenDocumentCommand)
    {
        e.Cancel = true;
        this.radRichTextEditor1.Document = ImportDocx();
    }
}
public RadDocument ImportDocx()
{
    RadDocument document = null;
    IDocumentFormatProvider provider = new DocxFormatProvider();
    OpenFileDialog openDialog = new OpenFileDialog();
    openDialog.Filter = "Documents|*.docx";
    openDialog.Multiselect = false;
    DialogResult dialogResult = openDialog.ShowDialog();
    if (dialogResult == System.Windows.Forms.DialogResult.OK)
    {
        this.Text = openDialog.FileName;
        using (Stream stream = openDialog.OpenFile())
        {
            document = provider.Import(stream);
        }
    }
    
    return document;
}

Please let me know if there is something else I can help you with. 
 
Regards,
Dimitar
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Lee
Top achievements
Rank 1
answered on 19 Feb 2015, 10:21 AM
Hi Dimitar,

Thats' perfect thank you. Also answers another forum post I have where I can now hardcode the folder that the user is able to open files from.

Thanks for the code sample - not sure I'd ever have been able to find that in the documentation though...

Regards,

Lee.
0
Dimitar
Telerik team
answered on 19 Feb 2015, 11:23 AM
I am glad I could be of help. Let us know if you have any other questions.

Regards,
Dimitar
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
RichTextEditor
Asked by
Lee
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Lee
Top achievements
Rank 1
Share this question
or