Clarification on Relative File Themes

6 posts, 0 answers
  1. Sean McConnell
    Sean McConnell avatar
    38 posts
    Member since:
    Aug 2007

    Posted 04 Mar 2008 Link to this post

    In this post:

    http://www.telerik.com/community/forums/thread/b311D-gdcka.aspx

    This is stated:

    As for loading themes from file, you should have in mind that the file name is generated automatically, and references the full file path on your hard drive. It is quite possible that this path is not valid when deploying the application on another station. For that reason you should use embedded resource OR file name relative to application's executable file. Here is example for relative path:
    • If your application compiles in "C:\Prorects\MyApp\bin\debug" and the theme file is located in "MyApp\Resources" folder, the relative path would be: "..\..\Resources\MyThemeFileName.xml"

    In Q2 2007 this will work in the designer as well.


    However, I do not believe this to be true - because when I change the path name to a relative path, it is using the Visual Studio IDE launch directory as the base directory, not the directory of the application files.

    Can you confirm this?

    I am using Q32007 SP1.

  2. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 05 Mar 2008 Link to this post

    Hello Randall Kohltfarber,

    Thank you for writing.

    You are correct. The relative path is pointing to the executing directory of the application. In debug mode, it is ..MyApp\bin\Debug. However, if you want to deploy the application in conjunction with a theme file you should follow the steps provided below:
    1. Select the theme file in Solution Explorer, right click and select “Properties” from the context menu
    2. Select the “Content” value for the “Build Action” property.
    3. Select the “Copy always” value for the “Copy to Output Directory” setting.
    4. In the Main menu of Visual Studio navigate to: Project/MyProject Properties…
    5. Choose the “Publish” tab at the left side.
    6. Click the “Application Files” button.
    7. In Application Files Form for “Resources\MyThemeFileName.xml” select “Include” for Publish Status field.
    8. Confirm changes by pressing the OK button and you will be able to publish the application. It will be deployed including the theme file.

    I hope this helps. In case, you have further questions, do not hesitate to write me. 

    Best wishes,
    Martin Vasilev
    the Telerik team


    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Sean McConnell
    Sean McConnell avatar
    38 posts
    Member since:
    Aug 2007

    Posted 05 Mar 2008 Link to this post

    Hello Martin, thanks for the response, although I think you may have misunderstood my post.

    I actually noted that this quote:

    In Q2 2007 this will work in the designer as well.

    Is in fact NOT correct,  when using file-based themes in Visual Studio, the relative path is based upon the directory of the devenv.exe not the directory of the application executable.

    I have confirmed this to be the case, simply change the absolute path to a relative path, and the theme file FAILS TO LOAD with an exception stating it cannot find the file.. in that path, you can clearly see the root directory is NOT the application's bin/debug directory but the directory of the visual studio executable.

    It is true this works for a deployed application, however this is of little value to us, as we are unable to use relative paths in design mode.

    My point in making this post is to inform you that the information present in the forums is incorrect, and I wanted to save other users from wasting time trying to get it working based on that information.



  5. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 06 Mar 2008 Link to this post

    Hello Randall Kohltfarber,

    Thank you for contacting me.

    Excuse me for the misunderstanding. I just wanted to specify that when using a relative path, it is pointing to the executable directory for the application (not the root directory of Visual Studio where devenv.exe is located). You can easily check this if you copy the application exe file from bin\Debug to another directory and execute it.

    For example, I have set the relative path to "..\..\Resources\NewTheme.xml" and run the project - in debug mode it can retrieve the theme. After that, I have copied the assembly to c:\ and executed it. It threw an exception with this message: "Error loading theme from resource System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Resources\NewTheme.xml'..." You can see that the path is the application executing directory, which in this case is c:\.

    I'd like to add that you could use the "~" sign to denote the application executable path. For example: "~\Resources\NewTheme.xml". instead of  "..\..\Resources\NewTheme.xml".

    If you need additional information do not hesitate to write me.

    Sincerely yours,
    Martin Vasilev
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Sean McConnell
    Sean McConnell avatar
    38 posts
    Member since:
    Aug 2007

    Posted 06 Mar 2008 Link to this post

    I am referring to the DESIGNER mode, not executing the applicaton in debug mode from the IDE - As in, when you open up the form in the designer, an exception is thrown, and that exception states the relative path from the location of devenv.exe

    If you provide an area for me to upload screenshots, I can quite easily show this to you.

  7. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 07 Mar 2008 Link to this post

    Hello Randall Kohltfarber,

    Thank you for getting back to me.

    I have managed to reproduce this issue and it will be addressed in our next release Q1 2008. For the time being, to avoid this unexpected behavior you could set the theme file at runtime using the codeblock below as a reference:

    Telerik.WinControls.ThemeSource themeSource = new Telerik.WinControls.ThemeSource();  
    themeSource.StorageType = Telerik.WinControls.ThemeStorageType.File;  
    themeSource.ThemeLocation = @"~\MyThemeFile.xml";  
     
    this.radThemeManager1.LoadedThemes.Add(themeSource);  
    this.radMenu1.ThemeName = "MyThemeName"
       
    File attachments are not supported in our forums. If you need to send us a project or a screenshot, you should use our support ticket system. You could find detailed guidelines to using the support forum here: http://www.telerik.com/community/forums/thread/b311D-kecgg.aspx

    Your Telerik points have been updated. If you have any additional questions, please contact me again.

    Greetings,
    Martin Vasilev
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top
UI for WinForms is Visual Studio 2017 Ready