473,221 Members | 1,556 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,221 software developers and data experts.

File Download not finishing Sub

I have a function that downloads a file to the users computer and it works
fine.

The problem is that I then want the program to rename the file (file.move)
to the same name plus todays date.

The problem is that when you run the program it gets to the:

Response.AddHeader("Content-Disposition", "attachment; filename=" +
file.Name)

and this does something to the program and it will finish the response
section to write file but never does anything else.

Following is the Sub and it works fine, but never does any code after the
response section. Not the Trace and not the section that does the rename.

************************************
Sub GetFileDownload(strRequest as String)
trace.warn("in file download")
if (strRequest <"")

' get absolute path of the file
Dim file as System.IO.FileInfo = new System.IO.FileInfo(strRequest)
' if the file exists on the server
if (file.Exists)

' set appropriate headers
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" +
file.Name)
Response.AddHeader("Content-Length", file.Length.ToString())
Response.ContentType = "application/octet-stream"
Response.WriteFile(file.FullName)
Response.End()
trace.warn("inside Download strRequest = " & strRequest)
' Dim newFile as System.IO.FileInfo = new System.IO.FileInfo(strRequest &
" " & DateTime.Now.Month & "_" & DateTime.Now.Day & "_" & DateTime.Now.Year)
' if not newFile.Exists
' System.IO.File.Move(file.FullName.ToString(),file. DirectoryName & "\"
& strRequest & " " & DateTime.Now.Month & "_" & DateTime.Now.Day & "_" &
DateTime.Now.Year)
' end if
else
' if file does not exist
StatusMessage.Text = "This file does not exist."
end if
else
StatusMessage.Text = "Please provide a file to download."
end if
trace.warn("At end of Download")
end sub
*************************************************

Why does this happen? I assume it has something to the HTTP pipe.

How can I get this to rename the file after it copies it?

Thanks,

Tom
Nov 7 '06 #1
3 2105
a Response.End() terminates the current thread, so no code after it run.
rename before.

-- bruce (sqlwork.com)

"tshad" <ts**********@ftsolutions.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>I have a function that downloads a file to the users computer and it works
fine.

The problem is that I then want the program to rename the file (file.move)
to the same name plus todays date.

The problem is that when you run the program it gets to the:

Response.AddHeader("Content-Disposition", "attachment; filename=" +
file.Name)

and this does something to the program and it will finish the response
section to write file but never does anything else.

Following is the Sub and it works fine, but never does any code after the
response section. Not the Trace and not the section that does the rename.

************************************
Sub GetFileDownload(strRequest as String)
trace.warn("in file download")
if (strRequest <"")

' get absolute path of the file
Dim file as System.IO.FileInfo = new System.IO.FileInfo(strRequest) ' if
the file exists on the server
if (file.Exists)

' set appropriate headers
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" +
file.Name)
Response.AddHeader("Content-Length", file.Length.ToString())
Response.ContentType = "application/octet-stream"
Response.WriteFile(file.FullName)
Response.End()
trace.warn("inside Download strRequest = " & strRequest)
' Dim newFile as System.IO.FileInfo = new System.IO.FileInfo(strRequest
& " " & DateTime.Now.Month & "_" & DateTime.Now.Day & "_" &
DateTime.Now.Year)
' if not newFile.Exists
' System.IO.File.Move(file.FullName.ToString(),file. DirectoryName &
"\" & strRequest & " " & DateTime.Now.Month & "_" & DateTime.Now.Day &
"_" & DateTime.Now.Year)
' end if
else
' if file does not exist
StatusMessage.Text = "This file does not exist."
end if
else
StatusMessage.Text = "Please provide a file to download."
end if
trace.warn("At end of Download")
end sub
*************************************************

Why does this happen? I assume it has something to the HTTP pipe.

How can I get this to rename the file after it copies it?

Thanks,

Tom


Nov 7 '06 #2
"bruce barker (sqlwork.com)" <b_*************************@sqlwork.comwrote
in message news:%2******************@TK2MSFTNGP04.phx.gbl...
>a Response.End() terminates the current thread, so no code after it run.
rename before.
Is there a way to get around this?

I want to copy the file to another file when this is done. I can copy it
before (but I need to do it after in case he cancels the copy). The
following routine works.

*************************************
Sub GetFileDownload(strRequest as String)
if (strRequest <"")

' get absolute path of the file
Dim file as System.IO.FileInfo = new System.IO.FileInfo(strRequest)
' if the file exists on the server

if (file.Exists)
Dim newFileName as string
newFileName = strRequest.Replace(".txt","_" & DateTime.Now.Month & "_" &
DateTime.Now.Day & "_" & DateTime.Now.Year & ".txt")
Dim newFile as System.IO.FileInfo = new System.IO.FileInfo(strRequest &
" " & DateTime.Now.Month & "_" & DateTime.Now.Day & "_" & DateTime.Now.Year)

if not newFile.Exists
System.IO.File.Copy(file.FullName.ToString(),newFi leName)
end if

' set appropriate headers
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" +
file.Name)
Response.AddHeader("Content-Length", file.Length.ToString())
Response.ContentType = "application/octet-stream"
Response.WriteFile(file.FullName)
Response.End()
else
' if file does not exist
StatusMessage.Text = "This file does not exist."
end if
else
StatusMessage.Text = "Please provide a file to download."
end if
trace.warn("At end of Download")
end sub
************************************************** **********************

But I can't move the Copy section after the Responses (as you said).

I actually found that once you hit the first Resonse.AddHeader - the trace
won't work.

The other problem is - is there a way to know whether the user cancelled the
download? When you get the popup to allow the user to save the file - he
can also cancel it.

Thanks,

Tom
>
-- bruce (sqlwork.com)

"tshad" <ts**********@ftsolutions.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>>I have a function that downloads a file to the users computer and it works
fine.

The problem is that I then want the program to rename the file
(file.move) to the same name plus todays date.

The problem is that when you run the program it gets to the:

Response.AddHeader("Content-Disposition", "attachment; filename=" +
file.Name)

and this does something to the program and it will finish the response
section to write file but never does anything else.

Following is the Sub and it works fine, but never does any code after the
response section. Not the Trace and not the section that does the
rename.

************************************
Sub GetFileDownload(strRequest as String)
trace.warn("in file download")
if (strRequest <"")

' get absolute path of the file
Dim file as System.IO.FileInfo = new System.IO.FileInfo(strRequest) '
if the file exists on the server
if (file.Exists)

' set appropriate headers
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" +
file.Name)
Response.AddHeader("Content-Length", file.Length.ToString())
Response.ContentType = "application/octet-stream"
Response.WriteFile(file.FullName)
Response.End()
trace.warn("inside Download strRequest = " & strRequest)
' Dim newFile as System.IO.FileInfo = new
System.IO.FileInfo(strRequest & " " & DateTime.Now.Month & "_" &
DateTime.Now.Day & "_" & DateTime.Now.Year)
' if not newFile.Exists
' System.IO.File.Move(file.FullName.ToString(),file. DirectoryName &
"\" & strRequest & " " & DateTime.Now.Month & "_" & DateTime.Now.Day &
"_" & DateTime.Now.Year)
' end if
else
' if file does not exist
StatusMessage.Text = "This file does not exist."
end if
else
StatusMessage.Text = "Please provide a file to download."
end if
trace.warn("At end of Download")
end sub
*********************************************** **

Why does this happen? I assume it has something to the HTTP pipe.

How can I get this to rename the file after it copies it?

Thanks,

Tom



Nov 7 '06 #3
The other thing I would like to be able to do is tell whether the user
presses the Cancel button or not. Since it doesn't come back - how do you
do that. Or can you?

Thanks,

Tom

"tshad" <ts**********@ftsolutions.comwrote in message
news:O1**************@TK2MSFTNGP03.phx.gbl...
"bruce barker (sqlwork.com)" <b_*************************@sqlwork.com>
wrote in message news:%2******************@TK2MSFTNGP04.phx.gbl...
>>a Response.End() terminates the current thread, so no code after it run.
rename before.

Is there a way to get around this?

I want to copy the file to another file when this is done. I can copy it
before (but I need to do it after in case he cancels the copy). The
following routine works.

*************************************
Sub GetFileDownload(strRequest as String)
if (strRequest <"")

' get absolute path of the file
Dim file as System.IO.FileInfo = new System.IO.FileInfo(strRequest) ' if
the file exists on the server

if (file.Exists)
Dim newFileName as string
newFileName = strRequest.Replace(".txt","_" & DateTime.Now.Month & "_"
& DateTime.Now.Day & "_" & DateTime.Now.Year & ".txt")
Dim newFile as System.IO.FileInfo = new System.IO.FileInfo(strRequest &
" " & DateTime.Now.Month & "_" & DateTime.Now.Day & "_" &
DateTime.Now.Year)

if not newFile.Exists
System.IO.File.Copy(file.FullName.ToString(),newFi leName)
end if

' set appropriate headers
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" +
file.Name)
Response.AddHeader("Content-Length", file.Length.ToString())
Response.ContentType = "application/octet-stream"
Response.WriteFile(file.FullName)
Response.End()
else
' if file does not exist
StatusMessage.Text = "This file does not exist."
end if
else
StatusMessage.Text = "Please provide a file to download."
end if
trace.warn("At end of Download")
end sub
************************************************** **********************

But I can't move the Copy section after the Responses (as you said).

I actually found that once you hit the first Resonse.AddHeader - the trace
won't work.

The other problem is - is there a way to know whether the user cancelled
the download? When you get the popup to allow the user to save the file -
he can also cancel it.

Thanks,

Tom
>>
-- bruce (sqlwork.com)

"tshad" <ts**********@ftsolutions.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>>>I have a function that downloads a file to the users computer and it
works fine.

The problem is that I then want the program to rename the file
(file.move) to the same name plus todays date.

The problem is that when you run the program it gets to the:

Response.AddHeader("Content-Disposition", "attachment; filename=" +
file.Name)

and this does something to the program and it will finish the response
section to write file but never does anything else.

Following is the Sub and it works fine, but never does any code after
the response section. Not the Trace and not the section that does the
rename.

************************************
Sub GetFileDownload(strRequest as String)
trace.warn("in file download")
if (strRequest <"")

' get absolute path of the file
Dim file as System.IO.FileInfo = new System.IO.FileInfo(strRequest) '
if the file exists on the server
if (file.Exists)

' set appropriate headers
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" +
file.Name)
Response.AddHeader("Content-Length", file.Length.ToString())
Response.ContentType = "application/octet-stream"
Response.WriteFile(file.FullName)
Response.End()
trace.warn("inside Download strRequest = " & strRequest)
' Dim newFile as System.IO.FileInfo = new
System.IO.FileInfo(strRequest & " " & DateTime.Now.Month & "_" &
DateTime.Now.Day & "_" & DateTime.Now.Year)
' if not newFile.Exists
' System.IO.File.Move(file.FullName.ToString(),file. DirectoryName &
"\" & strRequest & " " & DateTime.Now.Month & "_" & DateTime.Now.Day &
"_" & DateTime.Now.Year)
' end if
else
' if file does not exist
StatusMessage.Text = "This file does not exist."
end if
else
StatusMessage.Text = "Please provide a file to download."
end if
trace.warn("At end of Download")
end sub
************************************************ *

Why does this happen? I assume it has something to the HTTP pipe.

How can I get this to rename the file after it copies it?

Thanks,

Tom




Nov 8 '06 #4

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

Similar topics

5
by: galsaba | last post by:
I upload a file to my website. the name of the file is me.zip. What command I need to write as html to have the user to download it? 2. If I uploaded the file me.zip in my website:...
12
by: Jerry Camel | last post by:
I thought I had finally figured out how to control the downloads from my page. I was having issues with large files, but after much research I came up with the following code. The download seems to...
1
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved...
4
by: nick | last post by:
hi all, Is there anyone who can help in finishing this problem? I’m checking a huge text file for some data, there are lots of lines where some of these lines lets say start with the word...
16
by: matt | last post by:
I have used some free code for listing files for download, but I want to send an email to the administrator when the file has been downloaded. I have got some code in here that does it, but it will...
10
by: David | last post by:
I have googled to no avail on getting specifically what I'm looking for. I have found plenty of full blown apps that implement some type of file transfer but what I'm specifcally looking for is an...
4
by: Roberto Mora | last post by:
I have not done programming in a very long time and what is worst, I never learned VB. Although my job does not require this knowledge, I cam across a problem that although it seemed simple it has...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
7
Curtis Rutland
by: Curtis Rutland | last post by:
Building A Silverlight (2.0) Multi-File Uploader All source code is C#. VB.NET source is coming soon. Note: This project requires Visual Studio 2008 SP1 or Visual Web Developer 2008 SP1 and...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.