Avatar of ProgrammerAtAIMS
ProgrammerAtAIMS
 asked on

asp.net uploading picture to a temporary folder

hi,
I have a web page where a user can upload a file or picture and if a picture I need to display it in an image field.

I am using an "ajaxToolkit:AsyncFileUpload" and on AsyncFileUpload_UploadedComplete I am saving the Image and showing it using this code :
 Protected Sub AsyncFileUpload_UploadedComplete(ByVal sender As Object, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs)
    If e.State = AjaxControlToolkit.AsyncFileUploadState.Success Then
         If AsyncFileUpload.HasFile Then
             Dim filename As String = System.IO.Path.GetFileName(e.FileName)
             Dim fileextension As String = IO.Path.GetExtension(AsyncFileUpload2.FileName)
             Dim strPath As String = MapPath("~/temp/") + filename
             If IsValidImage(fileextension) Then                
                 AsyncFileUpload.SaveAs(strPath)
                 Image.imageurl = strPath
             else
                 AsyncFileUpload.SaveAs(strPath)
                 Image.imageurl = Defaultpth
             End If
                 Session(ViewState("page_id") + "fileuploaded") = 1
         End If
    End If
 End Sub

Open in new window


My code is working fine but after a while this temp folder I created is getting very large and I need to clear it.
I need to know if there is a way to upload my file to a temporary asp.net folder that is cleared after a while automatically without having to clear it manually.
Thank you in advance
ASP.NET

Avatar of undefined
Last Comment
Prakash Samariya

8/22/2022 - Mon
ste5an

It strongly depends on your requirements here, But I would consider touching the files, when displayed. So you can delete files older than a certain time span.
ProgrammerAtAIMS

ASKER
Hi ste5an,
what do you mean by touching the file? do you have any example on this?
ste5an

hmm, basic IPC.. Touching means to change a files attribute(s). In this case the last access date can be a candidate, when no other process (e.g. AV) is reading those files. Otherwise you need to touch the last modified or created date.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
Prakash Samariya

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question