delphi programming forums mysql charset mget recursive synonimos
free ventrilo servers hosting cs javascript delay python find in list
Back Forum New
abstract:

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.CompleteRe quest();
if (file.Length < answerClicked + ".exe".Length)
{
UpdateDataBase(answerClicked);
}
}
else
{
Response.Write(MyAlert);
}
}
catch (Exception ex)
{
Response.Write("Error: " + ex.Message);
}
}


Hi
I am trying to make a webpage in html and use a codebehind to do the work for it and display the results. On the webpage 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 dont 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:
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.CompleteRe quest();
if (file.Length < answerClicked + ".exe".Length)
{
UpdateDataBase(answerClicked);
}
}
else
{
Response.Write(MyAlert);
}
}
catch (Exception ex)
{
Response.Write("Error: " + ex.Message);
}
}

TOP

I'm sorry I put this in the wrong area....I was thinking about my html website when I wrote it. Its asp.net. I can move it for you. Never mind. no place to delete it or move it so I will leave you.



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.CompleteRe quest();
if (file.Length < answerClicked + ".exe".Length)
{
UpdateDataBase(answerClicked);
}
}
else
{
Response.Write(MyAlert);
}
}
catch (Exception ex)
{
Response.Write("Error: " + ex.Message);
}
}

TOP

Back Forum