Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Problem cleaning up temp folder after saving files to database

Reply
Thread Tools

Problem cleaning up temp folder after saving files to database

 
 
Author #1
Guest
Posts: n/a
 
      05-21-2009
One of my asp.net 3.5 web applications tracks all kinds of user files.
Users can upload files to a storage in addition to other file
information which is stored in the SQL Server 2005 Database.

Currently, my design is to store the files in the same SQL Server 2005
database. This is my preferred method. (I may consider storing files
in the file system, and simply keep the path in the database, if my
current problem cannot get resolved nicely.)

I am using this ajax file upload tool to upload files:
http://en.fileuploadajax.subgurim.net/

This tool uploads the file to a temp folder, and when a user clicks on
a Save button, my application reads the uploaded file from this temp
folder and sends it to the database.

The problem:

1) Because more than 1 user may be uploading files at the same time,
and 1 user during 1 session may upload more than 1 file, the system
must be able to identify *the-just-uploaded* files *by the current
user*. I have been successful in doing this by using a Guid plus
SessionID.

2) Immediately after the files are sent to the database, I attempt to
erase all of them from the temp folder, and this is where I am having
problem.

I think I have to erase any file that has been saved to the database
as a cleanup for the next file upload operation.

The problem is, when my application tries to erase the files
immediately after they are saved to the database, I get an exception
which says: The file is being used by another process.

I guess this is because the deletion attempt happens too soon after
the files are saved to the database.

How would you resolve this problem? I am more interested in the
design. In other words, what technique would you use in this kind of
situation to avoid such file read-then-delete conflict?

I hope that this isn't too long and if it is not clear, please yell.
Thanks.
 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      05-21-2009
I am not sure "too soon" is the problem. If you read a file with a stream
and close the stream properly there shouldn't be a problem.


--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


"Author #1" <> wrote in message
news:47c2c00d-62d9-4da8-9ec7-...
> One of my asp.net 3.5 web applications tracks all kinds of user files.
> Users can upload files to a storage in addition to other file
> information which is stored in the SQL Server 2005 Database.
>
> Currently, my design is to store the files in the same SQL Server 2005
> database. This is my preferred method. (I may consider storing files
> in the file system, and simply keep the path in the database, if my
> current problem cannot get resolved nicely.)
>
> I am using this ajax file upload tool to upload files:
> http://en.fileuploadajax.subgurim.net/
>
> This tool uploads the file to a temp folder, and when a user clicks on
> a Save button, my application reads the uploaded file from this temp
> folder and sends it to the database.
>
> The problem:
>
> 1) Because more than 1 user may be uploading files at the same time,
> and 1 user during 1 session may upload more than 1 file, the system
> must be able to identify *the-just-uploaded* files *by the current
> user*. I have been successful in doing this by using a Guid plus
> SessionID.
>
> 2) Immediately after the files are sent to the database, I attempt to
> erase all of them from the temp folder, and this is where I am having
> problem.
>
> I think I have to erase any file that has been saved to the database
> as a cleanup for the next file upload operation.
>
> The problem is, when my application tries to erase the files
> immediately after they are saved to the database, I get an exception
> which says: The file is being used by another process.
>
> I guess this is because the deletion attempt happens too soon after
> the files are saved to the database.
>
> How would you resolve this problem? I am more interested in the
> design. In other words, what technique would you use in this kind of
> situation to avoid such file read-then-delete conflict?
>
> I hope that this isn't too long and if it is not clear, please yell.
> Thanks.
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 4092 (20090520) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4092 (20090520) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com



 
Reply With Quote
 
 
 
 
Author #1
Guest
Posts: n/a
 
      05-21-2009
On May 21, 1:58*am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.org> wrote:
> I am not sure "too soon" is the problem. If you read a file with a stream
> and close the stream properly there shouldn't be a problem.
>
> --
> Eliyahu Goldin,
> Software Developer
> Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldin
>
> "Author #1" <gnewsgr...@gmail.com> wrote in message
>
> news:47c2c00d-62d9-4da8-9ec7-...
>
>
>
> > One of my asp.net 3.5 web applications tracks all kinds of user files.
> > Users can upload files to a storage in addition to other file
> > information which is stored in the SQL Server 2005 Database.

>
> > Currently, my design is to store the files in the same SQL Server 2005
> > database. *This is my preferred method. *(I may consider storing files
> > in the file system, and simply keep the path in the database, if my
> > current problem cannot get resolved nicely.)

>
> > I am using this ajax file upload tool to upload files:
> >http://en.fileuploadajax.subgurim.net/

>
> > This tool uploads the file to a temp folder, and when a user clicks on
> > a Save button, my application reads the uploaded file from this temp
> > folder and sends it to the database.

>
> > The problem:

>
> > 1) Because more than 1 user may be uploading files at the same time,
> > and 1 user during 1 session may upload more than 1 file, the system
> > must be able to identify *the-just-uploaded* files *by the current
> > user*. *I have been successful in doing this by using a Guid plus
> > SessionID.

>
> > 2) Immediately after the files are sent to the database, I attempt to
> > erase all of them from the temp folder, and this is where I am having
> > problem.

>
> > I think I have to erase any file that has been saved to the database
> > as a cleanup for the next file upload operation.

>
> > The problem is, when my application tries to erase the files
> > immediately after they are saved to the database, I get an exception
> > which says: The file is being used by another process.

>
> > I guess this is because the deletion attempt happens too soon after
> > the files are saved to the database.

>
> > How would you resolve this problem? I am more interested in the
> > design. In other words, what technique would you use in this kind of
> > situation to avoid such file read-then-delete conflict?

>
> > I hope that this isn't too long and if it is not clear, please yell.
> > Thanks.

>
> > __________ Information from ESET NOD32 Antivirus, version of virus
> > signature database 4092 (20090520) __________

>
> > The message was checked by ESET NOD32 Antivirus.

>
> >http://www.eset.com

>
> __________ Information from ESET NOD32 Antivirus, version of virus signature database 4092 (20090520) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com


Yes, you are correct. Indeed, I forget to close the FileStream and the
BinaryReader. After I added

fs.Close();
br.Close();

it is all good, now.

Thanks a lot for this reminder. I keep forgetting closing IO streams.
 
Reply With Quote
 
Author #1
Guest
Posts: n/a
 
      05-22-2009
Andrew Morton wrote:
> Author #1 wrote:
> > Thanks a lot for this reminder. I keep forgetting closing IO streams.

>
> If you open them with a "using" statement, they will be closed
> automatically.
>
> See "Using block" in the help.
>
> Andrew


I have been using the using block for db operations all the time,
haven't used it for file IO, well, I rarely do file IO operation, so,
I haven't got used to it.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem logging into eBay after deleting all contents of Temp Folder - Help Needed! ruddy2000 General Computer Support 0 11-15-2006 12:30 PM
Cleaning temp files in XP owdio Computer Support 3 05-03-2005 08:29 PM
Temp Internet and temp files now in winnt directory w2k pro Bibble Bobble Computer Support 1 11-27-2003 06:14 PM
computer freezing while cleaning temp files Viewasku1977 Computer Support 4 11-08-2003 05:24 PM
Cleaning out Windows Temp Folder rfdjr1@optonline.net Computer Support 32 10-16-2003 08:47 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57