Last post Jan 23, 2007 01:49 PM by jose_jimenez
Dec 15, 2006 11:44 AM|kreid|LINK
I have a collection of files which are constantly being created on a remote server, but not uploaded to my web server until requested by a client. When a client requests a file, I want to pull it onto my web werver, whilst checking for it's creation using
a FileSystemWatcher. Once it is created, I wish to initiate a download by doing:
Response.ContentType = "text/plain";
Response.AddHeader("content-disposition", "attachment; filename=" + channelAFileInfo.Name);
The problem is that I want checking for the file to continue in the background, event if a user navigates off the page after requesting a file. Since Page.HttpResponse is only available in code-behind, how can I do this?
I have tried using a separate class, created in the session state, and passing this.Response into it from the initial page so that I have a reference to it, but of course this is invalid too. My other idea is to open up a popup window or a hidden window to handle the http response. I think this option would work, but it seems messy to me.
If all else fails, I could just say: "stay on the page until the download completes" but I would prefer not to.
I would appreciate any help with this, as I am pretty confused as to what to do. I can't find any documentation of similar problems.
HttpWebRequest IfModifiedSince NotModified Exception
Dec 15, 2006 05:23 PM|jose_jimenez|LINK
the web is stateless. There is no way to capture a response object to use later. If the file is not on your server, you cannot serve it later.
The way I have handled this is to have your web page queue the request for the file and let the user know they will receive a notice when the file is available. Once the file is available, send the user an email using your filesystemwatcher (create a separate
application or set something up with file dependencies on your web application). The email should have a link to the file in order to download it or a page that initiates the download and then removes it as necessary.
Dec 15, 2006 06:10 PM|kreid|LINK
Thanks for your reply.
I now have a clearer idea of how I am goiong to tackle this. You are correct that the web is stateless, and therefore, if the user navigates away from the "Download_Request" page, there is nothing I can do to let them download the file, since that particular
file to get from the remote server. I will use a class containing a FileSystemWatcher within my application state to watch for created files in response to requests from all users. This will also have the benefit of not replicating requests for the same
files from different users. During the time when the file is being retrieved from the remote server, the popup window will display a ProgressBar-type control and a message "Downloading file... please do not close this window". Once the file is available,
the popup will either close atumatically (not sure how to do this) or display "Download completed, please select the file for download to your computer". The user can then close the popup, and re-click the file link to download the file.
What do you think of this mechanism? Would it be affected by popup blockers? Would it be better to open a new window - "target=_blank" - rather than a popup? How could a normal window like this be resized and have address bar, etc removed?
Thanks for taking the time to answer my post, much appreciated!
Dec 16, 2006 06:15 PM|jose_jimenez|LINK
The popup window will work better so the user does not have to worry about staying on the same page.
Jan 21, 2007 04:53 PM|kreid|LINK
starts again while it writes a message to a Label on the page; if they are ready, it writes an html link to the page which the user can click to open the files in another window.
My problems are:
I have POST values in the url - will these be preserved with window.settimeout? (I am assuming this reloads the page but I could be wrong.)
It would be ideal if someone could post example source or pseudo code to get me on the right track![Idea]
Jan 23, 2007 01:12 AM|Zhao Ji Ma - MSFT|LINK
can add event handler to the event. The entire procedure is similar as server side code called by client side code. And parameter can be past by HTTP GET or HTTP POST.
Hope it helps
Jan 23, 2007 01:49 PM|jose_jimenez|LINK
Here is a link describing how to generate a script to post back to the server: