473,785 Members | 2,969 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem when sending a file to the client

Hi !

here's the code of the function I use to send a file to the client :
Private Function SendFile(ByVal fich As String, ByVal nom As String) As Boolean

Try

Dim oldCT As String = Response.Conten tType

Response.Clear( )
Response.Conten tType = "applicatio n/octet-stream"
Response.AddHea der("Content-Disposition", "attachment ; filename=""" & nom & """")

Dim fi As IO.FileInfo = New IO.FileInfo(Ser ver.MapPath("fi chiers\") & fich)
If Not fi.Exists Then
Return False
Exit Function
End If

Dim fs As IO.FileStream = fi.OpenRead
Dim tab(fs.Length) As Byte
fs.Read(tab, 0, fs.Length)
fs.Close()
Response.Binary Write(tab)

Response.Flush( )
Response.Close( )

Response.Clear( )
Response.Conten tType = oldCT

Return True

Catch ex As Exception

Return False

End Try

End Function
When I call it, the transfer works fine, the file is ok, but the web application stops responding to the client. When the client clicks a link or tries to do something on the page, nothing happens and the status bar indicates "Error on page"

Has someone an idea ?

Thanks in advance
--------------------------------
From: frenchie seb

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>xRjvRvO3c06 p6Q698UYtfA==</Id>
Nov 18 '05 #1
1 1139
Why do you have Response.Close( ) method ?
Look what is written about this method in MSDN : Closes the socket
connection to a client.
I think you should remove it from there

Regards
Martin

"frenchie seb via .NET 247" <an*******@dotn et247.com> wrote in message
news:Ok******** *****@tk2msftng p13.phx.gbl...
Hi !

here's the code of the function I use to send a file to the client :
Private Function SendFile(ByVal fich As String, ByVal nom As String) As Boolean
Try

Dim oldCT As String = Response.Conten tType

Response.Clear( )
Response.Conten tType = "applicatio n/octet-stream"
Response.AddHea der("Content-Disposition", "attachment ; filename=""" & nom & """")
Dim fi As IO.FileInfo = New IO.FileInfo(Ser ver.MapPath("fi chiers\") & fich) If Not fi.Exists Then
Return False
Exit Function
End If

Dim fs As IO.FileStream = fi.OpenRead
Dim tab(fs.Length) As Byte
fs.Read(tab, 0, fs.Length)
fs.Close()
Response.Binary Write(tab)

Response.Flush( )
Response.Close( )

Response.Clear( )
Response.Conten tType = oldCT

Return True

Catch ex As Exception

Return False

End Try

End Function
When I call it, the transfer works fine, the file is ok, but the web application stops responding to the client. When the client clicks a link or
tries to do something on the page, nothing happens and the status bar
indicates "Error on page"
Has someone an idea ?

Thanks in advance
--------------------------------
From: frenchie seb

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>xRjvRvO3c06 p6Q698UYtfA==</Id>

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2987
by: Allman | last post by:
I'm trying to implement a small WebDAV server using PHP. (WebDAV is an HTTP extension that (among other things) makes it possible to manage files using the HTTP protocol; kinda in the same way like using FTP through a web-browser.) I've made a short index.php file which is automatically run when then target
13
23339
by: Mimi | last post by:
Hello, I am having trouble using the session vars in PHP 4.3.9 OS: Win XP Prof Web Server IIS (is local and there are no links to other servers from the web pages I work on) Browser: IE 6.0 The problem I am having is that each time I reload the same PHP page, I get
3
399
by: DJTN | last post by:
I have created 2 vb.net applications in VS 2002, a server and a client using the .net.sockets namespace. I can connect and receive data fine but the client cannot tell when it has recived all the data from the server and close the file. I'm sending multiple request for data and I do not want to close the connecting everytime the entire file has been sent from the server and then reconnect. I'm sending binary data, is there anyway to tell...
0
1421
by: Efim | last post by:
Hi, I have got some problem with sending of events in .NET. I am using remouting. The client has got 2 objects for receiving different types of events (responses and events) The server has got two objects for sending of these events. The client opens tcp port 0 to receive events: if (ChannelServices.GetChannel("tcp") == null) {
11
6639
by: Abhishek | last post by:
I have a problem transfering files using sockets from pocket pc(.net compact c#) to desktop(not using .net just mfc and sockets 2 API). The socket communication is not a issue and I am able to transfer data across.On the serve I am using Socket 2 API (recv function to read bytes)and not using ..NET. I use FileStream to open the file on the pocket pc, then associate a BinaryReader object with the stream and call ReadBytes to read all the...
0
1234
by: Fabrice DG | last post by:
Hi all. I don't know if this post is really at the right place but I hope someone can help me.. I developed a NT service, in order to automate mail exchanges between different kind of users This service uses the POP3 and SMTP protocoles to perform the task Because we have a very heavy security policy, with no accessible SMTP gateways, I coded the use of Outlook (only for sending) as an evolution, with the classical outlook.application, etc...
4
8202
by: yaron | last post by:
Hi, I have a problem when sending data over TCP socket from c# client to java server. the connection established ok, but i can't send data from c# client to java server. it's work ok with TcpClient, NetworkStream and StreamWriter classes. but with low level socket it doesn't work (When using the Socket class Send method).
2
1945
by: hoenes1 | last post by:
I've got an aspx-Page "SendFile.aspx" which is called by a Link on "ShowListOfFiles.aspx" and sends the file in the OnLoad Eventhandler. The filename to download is stored in a Session variable. I'm sending the file to the client in 4 KB chunks. Sending the file works fine, but when I click a link on the calling aspx-Page ("ShowListOfFiles.aspx") after the download completed, the browser window shows fragments of the recently transmitted...
15
2414
by: Ron L | last post by:
We are working on a distributed VB.Net application which will access a SQL database located on a known server. Each client will run on the user's local machine. To implement this, we are trying to use remoting for our access to the SQL server, with the remoting being via IIS. Since all of our users will have accounts in the destination domain, we want to have IIS handle the security for us and not allow anonymous. We have set this up...
9
4304
by: darthghandi | last post by:
I am trying to create a server application using asynchronous sockets. I run into a problem when I try to connect to my server using a non-.net program. I can establish the connection, and send some packets in response to the programs first message, but when I receive a response back, it's the last packet I sent. After that packet, I receive the packet I really wanted. This only happens when I connect with local host. I tried...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10148
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10091
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.