PRB: ????? ??? "Response.WriteFile" ????? ??? ????

?????? ????????? ?????? ?????????
???? ???????: 812406 - ??? ???????? ???? ????? ????? ??? ???????.
??????
?????? ?????? ?????? ???? ??? ???????? ?? ??? ??????? ???? ????? ?????? ?????? ?? Microsoft. ?? ???? Microsoft ?? ???? ? ?????? ?? ??????? ????? ???? ?? ???? ?????? "?? ??? ????????.
????? ???? | ?? ????

?? ??? ??????

???????

??? ?????? ??????? ????? Response.WriteFile ?????? ??? ???? ?? ?? ?????? ??????? ??? ?? ?? ????? ???? ????? ????? ???????:
?? ???? ??? ??????
- ?? -
????? ?????? ??? ?????

????? ??? ???? ????? ?????? ???? ??? ???? ??? ??? ??? ????? ??????. ?????? ??? ???? "?????" ?? ?????? ??? ???? ?????? ?????? ????? ?????.

?????? ???????: ????? ??? ?????? ??? ??? ??? ??? ????? ????? ????? ???? ?????? ??? ?? ??? ????? ?????? ?? ???? ???. ?????? ?????? ????? ??? ????? ??????? ?? ???? ??? ????? ??? ????.
????? ?? ????? ??????? ??????? ?? ??? ????? ???????:

????? Aspnet_wp.exe (?? W3wp.exe ????????? ???? ???? ??? ????? ??????? ?????? Microsoft [IIS] 6.0) ???? ??? ?????.

????? ??? ??????? ?? ????? ????? ?? ??????? ??????? ?? ???? ???.

?????

????? ????? ??????? ???? ??? ???? ???? ?????? ???? ????? ???? ????? ??????? ?????. ??? ????? ??????? ???????? ASP.NET (Aspnet_wp.exe ?? W3wp.exe ????????? ???? ???? ??? 6.0 ????? ??????? ?????? [IIS]) ??? ????? ?????, ???? ???? ?????? ????? ?????. ???? ????? ?????? ASP.NET ?? ????? ???????? ??? ????? ????? ??????? ?????? Microsoft (Inetinfo.exe ?? ????). ?? ????? ?? ???? ??? ?????.

???????? ??? ????? ???? ????????? ?? ????? IIS ?????? ???????? ?? ?? ???? ???????? ?????? ?? ???????. ????? ???? ????? ???? ?????? ???????? ?? ??????? ????? ????? ????? ??? ??? ???????? ?????. ?? ???? ??? ??? ????? ?? ??????? ??????? ??? ??????. ???? ????? ???? ?????? ??????? ???????? ??? ???? ???.

???? ??????

??????? ?????? ??? ??? ??????? ?????? ?? ?? ????? ???????:
  • ?????? ??? ???????? ???????? ?? ????? ????? ?? ?? ???? ???????? ??? ??? ??????? ???????. ???? ???????? ???????? ??????? ????? ?????? ????.

    ??? ??? ????? ???? ????? ??????? ???? ??????? ??? false ?? ??? Web.config ????? ASP.NET ??? ???? ????? ??????? Server.ScriptTimeOut ??? ???? ?????? ???? ????? ???. ?????????? ??? ????? ?????? Server.ScriptTimeOut ??? 90 ?????. ??? ???? ??? ????? ????? debugtrue ???? Server.ScriptTimeOut ???? ????? ??? ????? ???? 30,000,000 ?????. ??? ????? ??? ??? ????? ??? ?? ???? ???? ??? ???? ????? ??? ASP.NET ????? ??.

    ?????? ?? ????????? ???????? ?????? ???? ??? ?? ???? ??? ??? ??? ???????? ????????? ?? ????? ???? FileStream. ??? ??????? ??? ?????? ???? ????? ??? ??? ??????? ???? ??? ???????. ????? ?? ?????????? ???? ???????? ???? FileStream ?? ?????? REFERENCES.
    ??? .NET Visual BasiciStream
          Dim iStream As System.IO.Stream
    
          ' Buffer to read 10K bytes in chunk:
          Dim buffer(10000) As Byte
    
          ' Length of the file:
          Dim length As Integer
    
          ' Total bytes to read:
          Dim dataToRead As Long
    
          ' Identify the file to download including its path.
          Dim filepath As String = "DownloadFileName"
    
          ' Identify the file name.
          Dim filename As String = System.IO.Path.GetFileName(filepath)
    
          Try
             ' Open the file.
             iStream = New System.IO.FileStream(filepath, System.IO.FileMode.Open, _
                                                    IO.FileAccess.Read, IO.FileShare.Read)
    
             ' Total bytes to read:
             dataToRead = iStream.Length
             
             Response.ContentType = "application/octet-stream"
             Response.AddHeader("Content-Disposition", "attachment; filename=" & filename)
    
             ' Read the bytes.
                While dataToRead > 0
                    ' Verify that the client is connected.
                    If Response.IsClientConnected Then
                        ' 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()
    
                        ReDim buffer(10000) ' Clear the buffer
                        dataToRead = dataToRead - length
                    Else
                        'prevent infinite loop if user disconnects
                        dataToRead = -1
                    End If
                End While
    
          Catch ex As Exception
             ' Trap the error, if any.
             Response.Write("Error : " & ex.Message)
          Finally
             If IsNothing(iStream) = False Then
                ' Close the file.
                iStream.Close()
             End If
             Response.Close()
          End Try
    
    ??? Visual C# ?? .NET
    	System.IO.Stream iStream = null;
    
    	// Buffer to read 10K bytes in chunk:
    	byte[] buffer = new Byte[10000];
    
    	// Length of the file:
    	int length;
    
    	// Total bytes to read:
    	long dataToRead;
    
    	// Identify the file to download including its path.
    	string filepath  = "DownloadFileName";
    
    	// Identify the file name.
    	string  filename  = System.IO.Path.GetFileName(filepath);
    
    	try
    	{
    		// 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=" + filename);
    
    		// 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;
    			}
    		}
    	}
    	catch (Exception ex) 
    	{
    		// Trap the error, if any.
    		Response.Write("Error : " + ex.Message);
    	}
    	finally
    	{
    		if (iStream != null) 
    		{
    			//Close the file.
    			iStream.Close();
    		}
    		Response.Close();
    	}
    	
    ??????? DownloadFileName ?? ??? ????? ???? ?? 100 ???????? (MB).

    - ?? -
  • ???? ???????? ???????? ?????? ?????.

    - ?? -
  • ?????? Microsoft ASP 3.0 ????????? ?? ??????? ?????? FileUp Artisans ?? ASP.

    - ?? -
  • ????? ???? ISAPI ?????? ?????.

    - ?? -
  • ??????? FTP ?????? ?????.

?????

????? ??? ?????? ??? ???????.

??????? ????

????? ????? ????? ?? ????

  1. ?? Microsoft Visual Basic .NET ?? ?? Microsoft Visual C# .NET ? ????? ????? "????? ???" ????. ?????????? ??? ????? WebForm1.aspx.
  2. ???? ?????? ???? ?? ???? ??????? ??? WebForm1.aspx.
  3. ???? ????? ??????? ??? ???? ???? ??? ????? ???? ?? "??? ???".
  4. ?? ???? ???????? ???????? ??????? ?? ????? Button1 ?????.

    ??? .NET Visual Basic
    	' Identify the file to download including its path.
    	Dim filepath As String = DownloadFileName
    
    	' Identify the file name.
    	Dim filename As String = System.IO.Path.GetFileName(filepath)
    
    	Response.Clear()
    	
    	' Specify the Type of the downloadable file.
    	Response.ContentType = "application/octet-stream"
    
    	' Set the Default file name in the FileDownload dialog box.
    	Response.AddHeader("Content-Disposition", "attachment; filename=""" & filename & """")
    
    	Response.Flush()
    
    	' Download the file.
    	Response.WriteFile(filepath)

    ??? Visual C# ?? .NET
    	// Identify the file to download including its path.
    	string filepath = DownloadFileName;
    
    	// Identify the file name.
    	string filename = System.IO.Path.GetFileName(filepath);
    
    	Response.Clear();
    
    	// Specify the Type of the downloadable file.
    	Response.ContentType = "application/octet-stream";
    
    	// Set the Default file name in the FileDownload dialog box.
    	Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
    
    	Response.Flush();
    
    	// Download the file.
    	Response.WriteFile(filepath);
  5. ??????? DownloadFileName ??? ????? ???? ?? 100 ???? ????.
  6. ?? ??????? ????? ? ???? ??? ????.
  7. ???? ??? Button1.

?????

????? ?? ?????????? ???? ??? ????? ???????? ??????? ?????? ?? "????? ??????? ?? Microsoft:
307603 ????? ????? ??????? ???????? ??? ???????? ???????? ASP.NET ? Visual Basic .NET
306654 ????? ????? ??????? ???????? ??? ???????? ???????? ASP.NET ? Visual C# .NET
????? ?? ?????????? ?? ?????? ???? ???? ????? Microsoft (MSDN) ?????? ??? ?????:
http://msdn2.microsoft.com/en-us/library/system.io.filestream(vs.71).aspx

???????

???? ???????: 812406 - ????? ??? ??????: 11/?? ??????/1428 - ??????: 4.3
????? ???
  • Microsoft Web Services Enhancements for Microsoft .NET 1.1
  • Microsoft ASP.NET 1.1
  • Microsoft ASP.NET 1.0
????? ??????: 
kbmt kbwebserver kbwebforms kbweb kbdownload kbprb KB812406 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????812406

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com