473,324 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Problem moving/deleting file after SaveAs()

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
5 6995
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Robert McGregor | last post by:
Hi all, I've got a Front End / Back End database that was working just fine. One day i opened the FE to find that if I tried to open one of the linked tables from the database window, nothing...
8
by: mytfein | last post by:
Hi Everyone, Background: Another department intends to ftp a .txt file from the mainframe, for me to process. The objective is to write a vb script that would be scheduled to run daily to...
6
by: Ken Allen | last post by:
I have enocuntered something wierd. If I invoke an instance of the above dialog and elect to save the file in a directory where a file of that name does not exist, then the return is...
1
by: Sobhan Vezzu | last post by:
Hi All, Using a webpage I am uploading the file onto webserver. First time it works fine. If I use the same file from second time it throws an error. Error: "The process cannot access the...
1
by: fa_2064 | last post by:
hi every body when i run this code i receive this error! my "wwwroot" folder is shared, but i don't know what it's reason is!!! {"Access to the path...
10
by: Paul | last post by:
Hi I am using the HtmlInputFile control to upload a file from a client to a server. I have a browse to find the file on the server but need to create the path dynamically as to were it will go...
0
by: .nu | last post by:
#!/usr/bin/env python # -*- coding: utf-8 -*- # Name: Sleepy Hollow # Author: .nu import wx import os import sys
11
by: Don | last post by:
QUESTIONS: 1. Has anyone figured out how to successfully install the Office 97 Pro Service Release 2 patch in Vista? 2. Has anyone successfully installed an Office 97 Pro CD (SR2 version) in...
2
by: andrescasta | last post by:
Hello, i have a problem when i try to delete a file that i recently uploaded. To upload, i used the FileUpload, when i receive the file, i save it in a directory inside the virtual application...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.