2012-01-04 2 views
1

웹 응용 프로그램 [asp.net]에서 다운로드 코드를 작성했지만 정상적으로 작동하지만 한 창 표시를 다운로드 할 때 "저장"/ "저장"할 때이 메시지를 묻지 않습니다. 다운로드를 클릭하면 파일이 표시됩니다. 새 창에서 또는 새 페이지에서. [다운로드 페이지는 탁월합니다.] 너 나 좀 도와 줄 수있어? 당신보다. 내 코드는 다음과 같습니다.asp.net의 파일 다운로드 옵션은 무엇입니까?

string pah = "./Files/" + ds.Tables[0].Rows[0]["targetname"].ToString();      
     // You should put more appropriate MIME type as per your file time - perhaps based on extension 
     Response.ContentType = "application/octate-stream"; 
     //Response.AddHeader("content-disposition", "attachment;filename=[your file name w/o path]"); 
     Response.AddHeader("content-disposition", "attachment;filename="+ds.Tables[0].Rows[0]["targetname"].ToString()); 
     // Start pushing file to user, IIS will do the streaming. 
     Response.TransmitFile(pah); 
     Response.Flush(); 

나를 도울 수 있습니다. 고맙습니다.

답변

1

ASP는 클라이언트 측 컴퓨터에서 핸들을 가지고 있으므로 관련 응용 프로그램과 직접 파일을 열 수 없습니다. 보안상의 이유로 좋은 브라우저는 사용자에게 '이 파일로 무엇을하고 싶습니까?'라고 묻습니다. 열다 ? 디스크에 저장 하시겠습니까? ?. 마이크로 소프트 워드에서 ActiveX와 다른 브라우저를위한 브라우저 플러그인이 같은 취소 "그럼에도 불구하고, 마이크로 소프트 IE에서이 작업을 수행하는 일부 액티브 방법이 될 수있다

1

이 스레드가 당신을 도울 수 있습니다.

당신은 변경해야 "첨부 파일을,"을 "인라인;"당신의 응답 헤더에

 Response.AddHeader("content-disposition", "inline;filename="+ds.Tables[0].Rows[0]["targetname"].ToString()); 
     Response.TransmitFile(pah); 
     Response.Flush(); 

여전히 같은 경우. Response.TransitFile에 문제가 있으면 다음 방법을 사용하십시오.

// Open the file. 
iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read,System.IO.FileShare.Read); 

// Total bytes to read: 
dataToRead = iStream.Length; 

Response.ContentType = "application/octet-stream"; 
Response.AddHeader("Content-Disposition", "attachment; filename=" + +ds.Tables[0].Rows[0]["targetname"].ToString()); 

// Read the bytes. 
while (dataToRead > 0) 
{ 
    // Verify that the client is connected. 
    if (Response.IsClientConnected) 
    { 
     // Read the data in buffer. 
     length = iStream.Read(buffer, 0, 10000); 

     // Write the data to the current output stream. 
     Response.OutputStream.Write(buffer, 0, length); 

     // Flush the data to the HTML output. 
     Response.Flush(); 

     buffer= new Byte[10000]; 
     dataToRead = dataToRead - length; 
    } 
    else 
    { 
     //prevent infinite loop if user disconnects 
     dataToRead = -1; 
    } 
} 

하지만 난 정말 같은 사용하는 HTML 기반 파일 뷰어 추천 :

+0

아직 대화 상자를 저장하고 있습니다! –

+0

위의 답변을 업데이트하고 TransitFile에 대체 방법을 추가합니다. 이게 도움이 되길 바란다. – Qorbani

+0

Ok Qorbani, 내가 확인하고 답장을 보내 주셔서 감사합니다. –