With download code, you may update increment counter to a database or file.
Steps:
1. When user clicks on button to download a file.
2. Read increment counter value from database or from file.
3. Increment by 1.
4. Write to a file or update to a database.
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
Well I presume that your files for downloading purpose are located in a folder named myfiles under web application root.
Write following code in Button's click event where file downloading process starts.
protected void Button1_Click(object sender, EventArgs e)
{
DownLoadFile("test.zip"); // This file is located under myfiles
folder.
}
Add the definition of DownLoadFile() function in your code section of your page.
void DownLoadFile(string filename)
{
string path = MapPath("~/files/" + filename);
byte[] byte_array = System.IO.File.ReadAllBytes(path);
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Type", "application/octate-stream");
Response.AddHeader("Content-Length", byte_array.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
Response.BinaryWrite(byte_array);
Response.Flush();
Response.End();
/****
* Write your code to update counter value - (Database or file)
****/
}
>but how am i going to know that file is downloaded? reply.
You have to read the value of counter.
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
use application variable...
dnanetwork
Practically a Master Poster
633 posts since May 2008
Reputation Points: 28
Solved Threads: 106
well why u didn;t agreed with application variable which is global...
or u suggest why not to use an application variable...?
Well I presume that your files for downloading purpose are located in a folder named myfiles under web application root.
Write following code in Button's click event where file downloading process starts.
protected void Button1_Click(object sender, EventArgs e)
{
DownLoadFile("test.zip"); // This file is located under myfiles
folder.
}
Add the definition of DownLoadFile() function in your code section of your page.
void DownLoadFile(string filename)
{
string path = MapPath("~/files/" + filename);
byte[] byte_array = System.IO.File.ReadAllBytes(path);
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Type", "application/octate-stream");
Response.AddHeader("Content-Length", byte_array.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
Response.BinaryWrite(byte_array);
Response.Flush();
Response.End();
/****
* Write your code to update counter value - (Database or file)
****/
}
>but how am i going to know that file is downloaded? reply.
You have to read the value of counter.
dnanetwork
Practically a Master Poster
633 posts since May 2008
Reputation Points: 28
Solved Threads: 106
The application variable is not persisted (saved). It will increment for the life of a session then go back to zero.
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
dnanetwork
Practically a Master Poster
633 posts since May 2008
Reputation Points: 28
Solved Threads: 106
You're welcome.
Please mark this thread as solved if we have answered your question and good luck!
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735