Get current filename

4 posts, 1 answers
  1. Lee
    Lee avatar
    10 posts
    Member since:
    Dec 2014

    Posted 17 Feb 2015 Link to this post

    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.
  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    1414 posts

    Posted 18 Feb 2015 Link to this post

    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.

     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Lee
    Lee avatar
    10 posts
    Member since:
    Dec 2014

    Posted 19 Feb 2015 in reply to Dimitar Link to this post

    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.
  5. Dimitar
    Admin
    Dimitar avatar
    1414 posts

    Posted 19 Feb 2015 Link to this post

    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.

     
Back to Top