GIDForums  

Go Back   GIDForums > Webmaster Forums > Web Design Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 15-Jun-2008, 15:02
mjcs100 mjcs100 is offline
Awaiting Email Confirmation
 
Join Date: May 2008
Posts: 4
mjcs100 is on a distinguished road

Help with determining size of downloaded file


I am trying to make a web page in html and use a codebehind to do the work for it and display the results. On the web page I have a form with 4 submit buttons with different values for each and if the person click one it goes to the codebehind and finds out which button was selected and goes through the process of downloading the file with response. Transmitfile and then records it in a database of how many downloads it downloaded. The problem I am having is that when the person clicks the button to download and it comes up with the dialog box to save and they decide at that time they don't want to download it and cancels, it still goes through and adds it to the database. I can not figure out how to get it to wait till it is completely downloaded before it is added to the database. I was thinking about using the file size and telling it if it does not equal the size of the file not to add it to the database and if it does then to add it. The bold part is the part I am having trouble with and wandered if anyone could give me some insite as to what I'm looking for or maybe a website that would explain what I am trying to do. I hope you understand what I'm trying to explain in accomplishing this.

codebehind:

Code:
protected void Page_Load(object sender, EventArgs e) { if (Request.Form["bSubmit"] == "(PLS)") { answerClicked = "PLS"; GetFile(); } else if (Request.Form["bSubmit"] == "(LYA)") { answerClicked = "LYA"; GetFile(); } else if (Request.Form["bSubmit"] == "Learning Your Colors (LYC)") { answerClicked = "LYC"; GetFile(); } else if (Request.Form["bSubmit"] == "Learning Your Numbers (LYN)") { answerClicked = "LYN"; GetFile(); } } public void GetFile() { int size = 0; answerClicked + ".exe".Length = size; String MyAlert= "<script> alert('Sorry, the file does not exist.'); </Script>"; try { // Get the physical Path of the file(test.doc) string path = Server.MapPath("programs/"); // Create New instance of FileInfo class to get the properties of the file being downloaded FileInfo file = new FileInfo(path + answerClicked + ".exe"); //file.Length = answerClicked + ".exe".Length; // Checking if file exists if (file.Exists) { // Clear the content of the response Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "application/exe"; Response.AppendHeader("Content-Disposition", "inline; filename=" + answerClicked + ".exe"); Response.TransmitFile("programs/" + answerClicked + ".exe"); HttpContext.Current.ApplicationInstance.CompleteRequest(); if (file.Length < answerClicked + ".exe".Length) { UpdateDataBase(answerClicked); } } else { Response.Write(MyAlert); } } catch (Exception ex) { Response.Write("Error: " + ex.Message); } }
Last edited by admin : 16-Jun-2008 at 10:21. Reason: Please insert your example codes between [CODE] and [/CODE] tags
  #2  
Old 16-Jun-2008, 10:10
JustinFox JustinFox is offline
Junior Member
 
Join Date: Mar 2008
Posts: 59
JustinFox will become famous soon enough

Re: Help with determining size of downloaded file


If you are using sql server 2005, you can make a tiny app that you can schedule on the server to clean up the database entries that are say 'pending download' if they have been there a day or so.

you would just use the task manager to schedule your app. everyday at say 2:00 a.m. and if a downloads status is 'downloading' and it has been there for over an hour, delete that record.

Justin Fox
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 08:44
Hard drive/CPU Diagnoses Issues binarybug Computer Hardware Forum 1 22-Jan-2007 20:23
After execution - Error cannot locate /Skin File? WSCH C++ Forum 1 05-Mar-2005 21:03
Having a problem Chuckles Computer Hardware Forum 19 13-Sep-2004 13:17
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 12:28

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 08:49.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.