2010-11-20 5 views
4

내 응용 프로그램은 나와 나 동료를위한 프로그램이므로 Click-Once 또는 copy-the-exe인지는 상관하지 않습니다. Windows 탐색기에서 지정된 확장명을 가진 파일을 클릭하고 내 프로그램을 실행하고 해당 파일을 열 수있게하려고합니다. 파일 이름을 캡처 할 수 없습니다.WPF; 한 번 클릭하십시오. 실행할 파일을 두 번 클릭하십시오. VS 2008

표면적 솔루션 :

http://blogs.msdn.com/b/avip/archive/2008/10/27/wpf-supporting-command-line-arguments-and-file-extensions.aspx

내가 노력하고있어 코드는 아래이며,이 시점에서 내가 할 노력하고있어 모든 텍스트 상자에 클릭 한 파일의 이름을 넣어. 내 관련 무지가 Windows 탐색기에서 일회용 응용 프로그램을 참조하는 방법에 대한 것입니다 용의자. 빌드 할 때 setup.exe라는 파일 (Wis.application이라는 파일)로 끝납니다. 설치를 위해 "setup"을 클릭하면 "Click-once application reference"유형의 바로 가기로 끝납니다. C : \ Users \ ptom \ AppData \ Roaming \ Microsoft \ Windows \ 시작 메뉴 \ 프로그램 \ Wis ". 설치로 만든 바로 가기로 파일을 연결하고 setup.exe로 파일을 연결하려고했습니다. 파일을 클릭하면 응용 프로그램이 시작되지만 AppDomain.CurrentDomain.SetupInformation.ActivationArguments가 null임을 나타냅니다. ("에 의해"나는 텍스트 상자가 내가 null인지 확인하기 위해 테스트 한 곳의 텍스트로 채워진다는 것을 의미합니다). 디버그에서 응용 프로그램을 실행하거나 시작 메뉴에서 실행하면 ActivationArguments가 null이 아니며 ActivationData (string [])의 길이가 길다는 것을 나타내는 코드 경로 다음에 예상 한대로 동작합니다 여기

0은

using System; 
using System.Collections.Generic; 
using System.Configuration; 
using System.Data; 
using System.Linq; 
using System.Windows; 

namespace Wis 
{ 
    /// <summary> 
    /// Interaction logic for App.xaml 
    /// </summary> 
    public partial class App : Application 
    { 
     protected override void OnStartup(StartupEventArgs e) 
     { 

      // Check if this was launched by double-clicking a doc. If so, use that as the 

      // startup file name. 
      if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments == null) 
      { 
       this.Properties["DoubleClickedFileToLoad"] = "There were no activation arguments AGAIN"; 
      } 
      else 
      { 
       if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData != null 
            && AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData.Length > 0) 
       { 
        this.Properties["DoubleClickedFileToLoad"] = 
        AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0]; 
       } 
       else 
       { 
        this.Properties["DoubleClickedFileToLoad"] = "Type in a file name"; 
       } 
      } 


     } 
    } 
} 

감사

답변

3

첫 번째에서 ClickOnce 게시를 위해 당신이 파일 ASSOC을 추가해야합니다 (프로젝트 -> 속성 - 선택> 제작 - 옵션 -> 파일 연결)
는 다음 참조 추가
그런 다음 당신은 할 수 (ClickOnce 또는 Local)

+0

코드에 붙여 넣었습니다. ApplicationDeployment라는 객체가 있습니다. 나는 처음에 그것을 잘라 냈다. 첫 번째 테스트를 사용하기 위해 System.Deployment에 대한 참조를 추가해야했습니다. –

3

당신이 Environment.GetCommandLineArgs()을 확인 했 App.xaml.cs를의 코드인가? 응용 프로그램이 시작된 인수가 표시됩니다.

응용 프로그램이 파일과 연결되어 있으면 파일 이름이 인수 중 하나로 포함되어야합니다. 에 "System.Deployment"모든

+0

같은 방식으로 App.cs에서 경로를 추출합니다. 몇 군데의 간단한 해결책이 작동하지 않지만 지금은 시도해 보았습니다. 그것은 효과가있다. 그래서 나는 그것을 어떻게 만들지 모른다. 나는 내 .../windows/Start Menu/Programs/Pwis 폴더에있는 한 번 클릭 한 단축키를 확장명과 연관 시켰고 주어진 확장명을 가진 폴더를 클릭하면 두 번째 인수가 파일이되었습니다. 그래서 그것은 the_smallest의 대답보다 간단한 방법입니다. 다른 대답이 더 많은 시나리오를 다루고 있는지 확실하지 않습니다. –

관련 문제