asp.net uploading picture to a temporary folder

ProgrammerAtAIMS
ProgrammerAtAIMS used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ste5anSenior Developer

Commented:
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.

Author

Commented:
Hi ste5an,
what do you mean by touching the file? do you have any example on this?
ste5anSenior Developer

Commented:
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.
IT Professional
Top Expert 2015
Commented:
I need to know if there is a way to upload my file to a temporary asp.net folder
Below code will returns path of current user's TEMP folder
var tempPath =  Path.GetTempPath();

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial