By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,544 Members | 2,002 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,544 IT Pros & Developers. It's quick & easy.

Problem moving/deleting file after SaveAs()

P: n/a
Hi,

I'm trying to upload some files via a form, and I have managed so far to
save the files on the server in a temporary directory using:

HttpPostedFile.SaveAs(string filename);

This is a necessary stage as I need to perform some tests on the file
before allowing it to be saved to its final destination directory. The
files being uploaded contain data, so it's necessary to test the
integrity of the data after uploading it.

The problem now is that, after I have uploaded and tested the data, I
then want to move the file (or delete it if it was not valid) to the
data directory. I then receive the following error:

"The process cannot access the file because it is being used by
another process."

I have tried to find a method of closing the file that has been saved by
the above method, but I can't seem to find one. Any suggestions?

--
Dylan Parry
http://webpageworkshop.co.uk -- FREE Web tutorials and references

Listening to: Rush - Cygnus X-1 Book II : Hemispheres
May 10 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Dylan Parry <us****@dylanparry.com> wrote:
I'm trying to upload some files via a form, and I have managed so far to
save the files on the server in a temporary directory using:

HttpPostedFile.SaveAs(string filename);

This is a necessary stage as I need to perform some tests on the file
before allowing it to be saved to its final destination directory. The
files being uploaded contain data, so it's necessary to test the
integrity of the data after uploading it.

The problem now is that, after I have uploaded and tested the data, I
then want to move the file (or delete it if it was not valid) to the
data directory. I then receive the following error:

"The process cannot access the file because it is being used by
another process."

I have tried to find a method of closing the file that has been saved by
the above method, but I can't seem to find one. Any suggestions?


Reflector indicates that that method does indeed close the file. You
might consider copying the data out of the HttpPostedFile.InputStream
and testing that directly, followed by saving to its final location
directly.

-- Barry
May 10 '06 #2

P: n/a
Hi,

Are you closing the file after y ou finish working with it, are you using a
thread or something like that?
Apparently that is the error you are getting

Another possible source of error (not present here) is if you want to move
the file to a dir to which the user under the IIS is executing has no
permission, by default ASP.net run under anonymous_IIS , this use has a very
limited set of permissions.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Dylan Parry" <us****@dylanparry.com> wrote in message
news:52**************@dylanparry.com...
Hi,

I'm trying to upload some files via a form, and I have managed so far to
save the files on the server in a temporary directory using:

HttpPostedFile.SaveAs(string filename);

This is a necessary stage as I need to perform some tests on the file
before allowing it to be saved to its final destination directory. The
files being uploaded contain data, so it's necessary to test the
integrity of the data after uploading it.

The problem now is that, after I have uploaded and tested the data, I
then want to move the file (or delete it if it was not valid) to the
data directory. I then receive the following error:

"The process cannot access the file because it is being used by
another process."

I have tried to find a method of closing the file that has been saved by
the above method, but I can't seem to find one. Any suggestions?

--
Dylan Parry
http://webpageworkshop.co.uk -- FREE Web tutorials and references

Listening to: Rush - Cygnus X-1 Book II : Hemispheres

May 10 '06 #3

P: n/a
Pondering the eternal question of "Hobnobs or Rich Tea?", Ignacio Machin
( .NET/ C# MVP ) finally proclaimed:
Are you closing the file after y ou finish working with it, are you using a
thread or something like that?


I think you might be on to something there. I will check to see whether
the checking process actually closes the files - I have a feeling that
it might not!

Thanks,

--
Dylan Parry
http://webpageworkshop.co.uk -- FREE Web tutorials and references
May 10 '06 #4

P: n/a
Hi,

The problem now is that, after I have uploaded and tested the data,
Reflector indicates that that method does indeed close the file. You
might consider copying the data out of the HttpPostedFile.InputStream
and testing that directly, followed by saving to its final location
directly.


She did test the data form the file, this mean she opened/read and not quite
close it :)
OP: Can you post the code you are using?

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
May 10 '06 #5

P: n/a
Pondering the eternal question of "Hobnobs or Rich Tea?", Ignacio Machin
( .NET/ C# MVP ) finally proclaimed:
She did test the data form the file, this mean she opened/read and not quite
close it :)
That's exactly what was happening... although I'm not sure who "she" is
:s
OP: Can you post the code you are using?


No need. I found that the method I was using to check the data (one that
I didn't write) wasn't closing the files on its own and needed me to
explicitly tell it to do so. As such it's working fine now!

Thanks,

--
Dylan Parry
http://webpageworkshop.co.uk -- FREE Web tutorials and references
May 10 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.