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

getting "System.IO.IOException: The process cannot access the file" while delete a file

P: n/a
the following is the full page code for uploading a file to server.
since i got no idea to overwrite the file, i want delete the file if
the file is already uploaded.
i got the folder name and filename of the file to delete from the
so i got the above error when i try to delete the file before upload.
Please anyone help me to solve out from this error.

<%@ Import Namespace="System.IO" %>
<%@ Page Language="vb" %>
<Script Language="VB" RunAt="Server">
Dim MyPath, MyName as string

Sub Page_Load(Sender as Object, e as EventArgs)
dim serpath as string
MyPath = request.QueryString("path")
MyPath = replace(MyPath,"/","\")
MyPath = replace(MyPath,"""","")
serpath = server.MapPath("") ' Set the path.
MyPath = serpath & "\" & mypath
End Sub

Sub Upload_Click(Sender as Object, e as EventArgs)
' Display properties of the uploaded file
if File.exists(mypath) then
end if

' Let us recover only the file name from its fully qualified path at
Dim strFileName as string
strFileName = MyFile.PostedFile.FileName

' Let us Save uploaded file to server at
catch Exp as exception
response.Write("Error Occored")
End Try
myfile = nothing
End Sub
<table cellpadding="0" cellspacing="0" width="400" align="center">
<Font Color="DarkGreen" Face=Helvetica Size=3> <B>Upload your file
to replace the old file
<HR Size="2" Color=Black >
<Form Method="Post" EncType="Multipart/Form-Data" RunAt="Server">
Choose Your File To Upload : <BR>
<Input ID="MyFile" Type="File" RunAt="Server" Size="40"> <BR>
<Input Type="Submit" Value="Upload"
OnServerclick="Upload_Click" RunAt="Server">
<HR Size="2" Color=Black>


Jun 29 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.