2012-11-07 4 views
0

서버 데이터베이스에서 파일 다운로드를 구성하고 클라이언트 컴퓨터에서 파일을 여는 방법은 무엇입니까?서버 db에서 업로드하고 클라이언트 컴퓨터에서 파일 열기

내 코드는 페이지가 서버에 개방되어있는 경우에만 작동합니다

 OracleCommand oracleCom = new OracleCommand(); 
     oracleCom.Connection = oraConnect; 
     oracleCom.CommandText = "Select m_content, f_extension From " + Session["tableNameIns"] + 
              " where i_id = " + rowData; 
     OracleDataAdapter adapter = new OracleDataAdapter(); 
     DataTable tableD = new DataTable(); 
     tableD.Locale = System.Globalization.CultureInfo.InvariantCulture; 
     adapter.SelectCommand = oracleCom; 
     adapter.Fill(tableD); 

     string FileName = Path.GetTempPath(); 
     FileName += "tempfile" + tableD.Rows[0][1]; 

     byte[] file = new byte[0]; 
     file = (byte[])tableD.Rows[0][0]; 
     FileStream fs = new FileStream(FileName, FileMode.OpenOrCreate, FileAccess.Write); 
     fs.Write(file, 0, file.GetUpperBound(0) + 1); 
     fs.Close(); 
     System.Diagnostics.Process.Start(FileName); 

답변

0

이 웹 응용 프로그램에서 그냥 가능하다.
이렇게하려면 Windows 응용 프로그램을 작성하십시오.

브라우저의 보안 제한으로 인해 브라우저에서 exe를 다운로드하여 직접 실행할 수 없습니다.
응답에서 EXE를 전송할 수 있습니다. 사용자가 수동으로 저장하고 실행합니다.

현재 설정에서 요청이 오는지 여부에 관계없이 서버에서 아직 exe가 작성되고 실행 중입니다.

단지 부수적인데, 훨씬 더 사용하기 쉬운 WriteAllBytes 바이트 배열을 파일에 쓰는 것이 더 쉽습니다. 잠금 장치를 걱정하거나 그런 식으로 개체를 처리 할 필요가 없습니다.

File.WriteAllBytes(FileName, file); 
0

답변 해 주셔서 감사합니다! 나는 이것을 이렇게했다 :

Response.ContentType = "APPLICATION/OCTET-STREAM"; 
Response.AddHeader("Content-Disposition", @"attachment;filename=\" + initFileName); 
Response.BinaryWrite(file); 

여기서 : 파일 - 이진 형식의 매개 변수이다. initFileName - 문자열 유형 파일 이름. 3 줄만).

관련 문제