2013-10-28 4 views
0

내 고객 중 한 명이 내 ActiveX 컨트롤에 문제가 있습니다. ActiveX는 Excel 파일을 다운로드하여 내 문서의 폴더에 저장 한 다음 Excel을 실행하고 파일을 엽니 다. 여기 내 문서 폴더에 파일을 다운로드하지 않습니다.

파일을 다운로드하고 여는 코드입니다 :

private string Checkout(string strFileUrl, string strPhysicalDir, string strPhysicalName) 
    {    
     string strMyDocumentFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); 
     string strCiroDocFolder = String.Format(@"{0}\CiroDoc", strMyDocumentFolder); 
     string strCheckoutFolder = String.Format(@"{0}\{1}", strCiroDocFolder, strPhysicalDir); 
     string strFilePath = String.Format(@"{0}\{1}", strCheckoutFolder, strPhysicalName); 

     try 
     { 
      if (!Directory.Exists(strCiroDocFolder)) 
       Directory.CreateDirectory(strCiroDocFolder); 

      if (!Directory.Exists(strCheckoutFolder)) 
       Directory.CreateDirectory(strCheckoutFolder); 

      if (File.Exists(strFilePath)) 
       File.Delete(strFilePath); 

      WebClient myWebClient = new WebClient(); 
      myWebClient.DownloadFile(strFileUrl, strFilePath);    
     } 
     catch (Exception e) 
     { 
      return e.Message; 
     } 

     return Run(strFilePath); 
    } 

    private string Run(string strFilePath) 
    { 
     if (!File.Exists(strFilePath)) 
      return "filenotfound"; 

     if (IsExecutable(strFilePath)) 
      return "isexecutable"; 

     try 
     { 
      System.Diagnostics.Process.Start(strFilePath); 
     } 
     catch (Exception e) 
     { 
      //This get returned 
      return String.Format("{0} ({1})", e.Message, strFilePath); 
     } 

     return "success";  
    } 

실행 방법은 "오류가 명령을 프로그램에 보낼 때 발생했습니다"예외를 반환합니다.

내 문서 폴더를 확인할 때 파일이 없습니다. 거기에 없기 때문에, 나는 Run 메소드가 멈추고 "filenotfound"를 반환 할 것으로 기대합니다.

이렇게하면 혼란 스럽습니다. File.Exists은 왜 true을 반환합니까? Windows 파일 가상화가 실행되고 파일이 VirtualStore 폴더에 저장됩니까? 그렇다면 어떻게 그 행동을 멈출 수 있습니까? 아니면 내 고객의 컴퓨터에서이 동작을 유발할 수 있습니까?

아직 내 컴퓨터에서이 문제를 재현하지 못했습니다. 내가 어떻게 감사 할 지 알고 있다면.

내 고객의 컴퓨터에 설치

  • OS : 윈도우 7
  • 브라우저 : IE 10
  • 안티 바이러스 : 맥아피

내가하려고합니다 누락 된 몇 가지 관련 정보 임가있는 경우 그것을 얻으십시오.

+0

함수에 전달 된 값이 실제로 예상 한 값인지 확인하기 위해 중단 점을 설정하려고합니다. 또한 Path.Combine 메서드를 사용하면 모든 문자열 연결을 제거하는 데 많은 도움이됩니다. – Steve

+0

strFilePath가 내가 Exception을 따라 반환하기 때문에 기대 한 것임을 확인할 수 있습니다. Path에 감사드립니다 .Combine 메서드는 그것에 대해 몰랐습니다! –

답변

0

Internet Explorer를 보호 모드로 설정하고 UAC를 사용하도록 설정하면 System.Diagnostics.Process.Start(strFilePath);이 예상대로 실행되지 않습니다.

대신이 코드를 사용하면 보호 모드에서도 Excel 파일이 열립니다.

Process myProcess = new Process(); 
myProcess.EnableRaisingEvents = false; 
myProcess.StartInfo.FileName = "excel"; 
myProcess.StartInfo.Arguments = String.Format(@"""{0}""", strFilePath); 
myProcess.Start(); 
관련 문제