2010-03-17 7 views
0

응용 프로그램 1과 응용 프로그램 2가 있습니다. App2는 App1이 설치되어 있는지 확인하고 App1 설정에서 속성에 액세스해야하는지 확인해야합니다.다른 응용 프로그램의 설정에 액세스

이 문제를 해결하는 가장 좋은 방법은 무엇입니까?

UPDATE 첫째, 내 사과는 결코이에 대한 답변을 수용하지, 난 지금 오래된 년 이상 알고,하지만 난이 요청 직후 탈선있어 다음 프로젝트가 어쩌구 저쩌구, 변경되었습니다. Mea culpa ...

저는이 문제를 해결할 필요가 있지만 지금은 ClickOnce를 통해 응용 프로그램을 배포하므로 위치가 실제로 알려지지 않았습니다. 모든 제안을 부탁드립니다. 이번에는 대답을 선택하겠습니다.

+0

더 많은 정보가 필요합니다. 설정이 포함 된 파일 위치가 이미 알려져 있습니까? – galford13x

+1

응용 프로그램 범위 또는 사용자 범위 설정? –

답변

1

ConfigurationManager.OpenExeConfiguration의 문서에는 다른 exe의 .config 파일을 읽고 AppSettings에 액세스하는 예제가 있습니다. 여기있다 :

// Get the application path. 
string exePath = System.IO.Path.Combine(
    Environment.CurrentDirectory, "ConfigurationManager.exe"); 

// Get the configuration file. 
System.Configuration.Configuration config = 
    ConfigurationManager.OpenExeConfiguration(exePath); 

// Get the AppSetins section. 
AppSettingsSection appSettingSection = config.AppSettings; 

지금까지 앱 1이 설치되어 있는지 확인, 당신은 설치시 레지스트리에 값을 쓸 수와 앱 2에서 그것을 확인 (및 제거하는 동안 값을 제거).

0

이것은 고통이며, 그 정도는 말할 수 있습니다. 가장 좋은 방법은 Settingsclass를 직렬화하고 XML (아래 코드)을 사용한다는 것입니다. 그러나 먼저이 페이지를보십시오 : http://cf-bill.blogspot.com/2007/10/visual-studio-sharing-one-file-between.html

public class Settings 
{ 
    public static string ConfigFile{get{return "Config.XML";}} 
    public string Property1 { get; set; } 

    /// <summary> 
    /// Saves the settings to the Xml-file 
    /// </summary> 
    public void Save() 
    { 
     XmlSerializer serializer = new XmlSerializer(typeof(Settings)); 
     using (TextWriter reader = new StreamWriter(ConfigFile)) 
     { 
      serializer.Serialize(reader, this); 
     } 
    } 
    /// <summary> 
    /// Reloads the settings from the Xml-file 
    /// </summary> 
    /// <returns>Settings loaded from file</returns> 
    public static Settings Load() 
    { 
     XmlSerializer serializer = new XmlSerializer(typeof(Settings)); 
     using (TextReader reader = new StreamReader(ConfigFile)) 
     { 
      return serializer.Deserialize(reader) as Settings; 
     } 
    } 
} 
관련 문제