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
ProgrammerAtAIMSAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
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.
0
ProgrammerAtAIMSAuthor Commented:
Hi ste5an,
what do you mean by touching the file? do you have any example on this?
0
ste5anSenior DeveloperCommented:
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.
0
Prakash SamariyaIT ProfessionalCommented:
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.