Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6978035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:42:13+00:00 2026-05-27T17:42:13+00:00

I am developing a commenting system with asp.net. A user can attach an image

  • 0

I am developing a commenting system with asp.net. A user can attach an image with “Attach” button and post the comment with “Post” button. Uploading the image starts when the user attaches it. An ASHX handler saves the uploaded file to “temp” folder. If the user clicks “Post” button, I move the image into a safe place. If he doesn’t click “Post”, closes the browser and goes away, the file remains in the “temp” folder. How can I delete a file from this “temp” folder one hour later after it is uploaded?

Details:
I thought using System.Timers.Timer in the ashx file used for uploading

System.Timers.Timer timer = new System.Timers.Timer(300);
string fileName;

public void Cleaner()
{
    System.Timers.Timer timer = new System.Timers.Timer(300); //3 second
    timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
    timer.Start();
}

protected void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs a)
{
    timer.Stop();
    timer.Close();

    string path = "temp";
    string mapPath = HttpContext.Current.Server.MapPath("../" + path);
    FileInfo TheFile = new FileInfo(mapPath + "\\" + fileName);
    if (TheFile.Exists) File.Delete(mapPath + "\\" + fileName);
}

public void ProcessRequest(HttpContext context)
{
    //Saving uploaded file
    Cleaner();
}

but I feel that I am not doing right.

Timer ticks after 3 seconds but HttpContext.Current in the timer_Elapsed() function returns null. Besides, file name also returns null after timer ticks. I couldn’t find a way to pass file name as a parameter when binding an event. Simply, it is problematic. I am looking for a more elegant way to delete the uploaded file after one hour.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:42:14+00:00Added an answer on May 27, 2026 at 5:42 pm

    I would avoid timers as you will create one timer per file which will not scale very well at all.

    How about this, run a clean up process on another thread in the web app started on app start that will delete temp files each time a session expires. That way you need no timers as the process will be prompted each time a session expires. You will need a class to store a reference (by unique name I guess) to the file which are still live (by that I mean the session to which they belong is still live) which the clean process can check.

    LMK if you want some code pointers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a commenting application where users can comment with their Facebook or Twitter
Developing a .NET WinForms application: how can I check if the window is in
Developing a WP7 app, and I'm trying to post something to the user's feed.
Developing a C# .NET 2.0 WinForm Application. Need the application to close and restart
When developing a desktop application in .NET, is it possible to not require the
Developing a multilingual application in VB.Net 2008, Im able to add resources to forms
After developing in VS.NET for many years, I'm starting to do some Xcode development
I am developing a comments moderating system as part of my website so i
iam developing iPhone application that allow user to define stations near to him, so
Developing an app that people pay a monthly subscription to use. They can pay

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.