获取c#应用程序中的文件夹路径

时间:2015-02-24 09:19:32

标签: c# visual-studio-2012 directory

我正在尝试检索我的应用程序中的文件夹标记,如printcreen中所示,我该怎么做

enter image description here

我尝试了下面的代码但是对我来说不起作用,因为它给了我c:\ location而我的项目是在驱动器中

   private void Countryflag_SelectionChanged(object sender, RibbonControlEventArgs e)
    {
        PowerPoint.Application ppApp = Globals.ThisAddIn.Application;
        PowerPoint.SlideRange ppslr = ppApp.ActiveWindow.Selection.SlideRange;
        string id = Countryflag.SelectedItem.Label;
        int countlargest = ppslr.Shapes.Count;
        PowerPoint.Shape shapepic = ppslr.Shapes[countlargest];


        String programfilesPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
           // Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
        //String msOfficePath = "Microsoft Office\\Document Themes 14";
        String msOfficePath = "~\\NepaAddintool\\Flag\\allflags\\";
        String fullPath = Path.Combine(programfilesPath, msOfficePath);
        string imagename = id + ".gif";

        String themePresentationPath = fullPath + "\\" + imagename;

       // ppslr.Shapes.AddPicture(themePresentationPath, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, shapepic.Left, shapepic.Top, shapepic.Width, shapepic.Height);
      ppslr.Shapes.AddPicture(themePresentationPath, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, 803, 35, 86, 56);
    }

1 个答案:

答案 0 :(得分:0)

尝试在config中添加图像旧路径,

 <add key="CommonImageFolder" value="D:/NepaAddintool/Flag/allflags" />

然后在你的应用中访问它,例如

 ConfigurationManager.AppSettings["CommonImageFolder"];

而不是msOfficePath。