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

File Move & Delete?

P: n/a
A Form has a FileUpload, 2 Buttons & a TextBox web server controls.
Using the FileUpload control, I want to give users the provision to
move & delete files that DO NOT exist in C:\Inetpub\wwwroot (i.e. the
root directory). This is the code:

<script runat="server">
Sub MoveFile(ByVal obj As Object, ByVal ea As EventArgs)
File.Move(fudFileSource.FileName, txtFileDest.Text)
'File.Move("F:\4.jpg", "C:\4.jpg")
End Sub

Sub DeleteFile(ByVal obj As Object, ByVal ea As EventArgs)
File.Delete(fudFileSource.FileName)
'File.Delete("F:\4.jpg")
End Sub
</script>

Now since the files do not exist in the root directory, I can't use
Server.MapPath but if I simply use fudFIleSource.FileName &
txtFileDest.Text to move a file from location to another location, then
the following error gets generated pointing to the File.Move() line:

Could not find file 'C:\WINNT\system32\4.jpg'.

& in case of the Delete method, the file doesn't get deleted. Is there
any way by which I can let users move & delete files that DO NOT exist
in the root directory?

Note that if I use the physical path of the files (as shown in the 2
commented lines in the code above), then both the Move & Delete methods
get executed successfully.

Thanks,

Arpan

Aug 30 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi

Why don't you try appending the physical drive name with the
fudFileSource.FileName, and then call the Move or Delete Method.

Something like

File.Move("F:\\" + fudFileSource.FileName, txtFileDest.Text), if you are
sure with the drive name.

Prem
"Arpan" wrote:
A Form has a FileUpload, 2 Buttons & a TextBox web server controls.
Using the FileUpload control, I want to give users the provision to
move & delete files that DO NOT exist in C:\Inetpub\wwwroot (i.e. the
root directory). This is the code:

<script runat="server">
Sub MoveFile(ByVal obj As Object, ByVal ea As EventArgs)
File.Move(fudFileSource.FileName, txtFileDest.Text)
'File.Move("F:\4.jpg", "C:\4.jpg")
End Sub

Sub DeleteFile(ByVal obj As Object, ByVal ea As EventArgs)
File.Delete(fudFileSource.FileName)
'File.Delete("F:\4.jpg")
End Sub
</script>

Now since the files do not exist in the root directory, I can't use
Server.MapPath but if I simply use fudFIleSource.FileName &
txtFileDest.Text to move a file from location to another location, then
the following error gets generated pointing to the File.Move() line:

Could not find file 'C:\WINNT\system32\4.jpg'.

& in case of the Delete method, the file doesn't get deleted. Is there
any way by which I can let users move & delete files that DO NOT exist
in the root directory?

Note that if I use the physical path of the files (as shown in the 2
commented lines in the code above), then both the Move & Delete methods
get executed successfully.

Thanks,

Arpan

Aug 30 '06 #2

P: n/a
File.Move("F:\\" + fudFileSource.FileName, txtFileDest.Text), if you are
sure with the drive name.
That's exactly where the problem lies. I am not at all sure what could
the drive name be. Even if I am sure, the source file may reside in any
directory/sub-directory. Even if I know the directory/sub-directory
where the file exists, the file name could be anything with any
extension.

The bottomline is the source file path & name could be any valid path &
name that exists in the hard drive.

Any other ideas?

Thanks,

Regards,

Arpan

Prem Kumar wrote:
Hi

Why don't you try appending the physical drive name with the
fudFileSource.FileName, and then call the Move or Delete Method.

Something like

File.Move("F:\\" + fudFileSource.FileName, txtFileDest.Text), if you are
sure with the drive name.

Prem
"Arpan" wrote:
A Form has a FileUpload, 2 Buttons & a TextBox web server controls.
Using the FileUpload control, I want to give users the provision to
move & delete files that DO NOT exist in C:\Inetpub\wwwroot (i.e. the
root directory). This is the code:

<script runat="server">
Sub MoveFile(ByVal obj As Object, ByVal ea As EventArgs)
File.Move(fudFileSource.FileName, txtFileDest.Text)
'File.Move("F:\4.jpg", "C:\4.jpg")
End Sub

Sub DeleteFile(ByVal obj As Object, ByVal ea As EventArgs)
File.Delete(fudFileSource.FileName)
'File.Delete("F:\4.jpg")
End Sub
</script>

Now since the files do not exist in the root directory, I can't use
Server.MapPath but if I simply use fudFIleSource.FileName &
txtFileDest.Text to move a file from location to another location, then
the following error gets generated pointing to the File.Move() line:

Could not find file 'C:\WINNT\system32\4.jpg'.

& in case of the Delete method, the file doesn't get deleted. Is there
any way by which I can let users move & delete files that DO NOT exist
in the root directory?

Note that if I use the physical path of the files (as shown in the 2
commented lines in the code above), then both the Move & Delete methods
get executed successfully.

Thanks,

Arpan
Aug 30 '06 #3

P: n/a
Arpan

I did it this way, probably you can give a try tooo.

..aspx
<form id="form1" runat="server">
<input id="File1" type="file" runat="server"/>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>

..aspx.cs
Response.Write(File1.Value); //This gives you the full path, not just
the filename.

Hope this helps
Prem

"Arpan" wrote:
File.Move("F:\\" + fudFileSource.FileName, txtFileDest.Text), if you are
sure with the drive name.

That's exactly where the problem lies. I am not at all sure what could
the drive name be. Even if I am sure, the source file may reside in any
directory/sub-directory. Even if I know the directory/sub-directory
where the file exists, the file name could be anything with any
extension.

The bottomline is the source file path & name could be any valid path &
name that exists in the hard drive.

Any other ideas?

Thanks,

Regards,

Arpan

Prem Kumar wrote:
Hi

Why don't you try appending the physical drive name with the
fudFileSource.FileName, and then call the Move or Delete Method.

Something like

File.Move("F:\\" + fudFileSource.FileName, txtFileDest.Text), if you are
sure with the drive name.

Prem
"Arpan" wrote:
A Form has a FileUpload, 2 Buttons & a TextBox web server controls.
Using the FileUpload control, I want to give users the provision to
move & delete files that DO NOT exist in C:\Inetpub\wwwroot (i.e. the
root directory). This is the code:
>
<script runat="server">
Sub MoveFile(ByVal obj As Object, ByVal ea As EventArgs)
File.Move(fudFileSource.FileName, txtFileDest.Text)
'File.Move("F:\4.jpg", "C:\4.jpg")
End Sub
>
Sub DeleteFile(ByVal obj As Object, ByVal ea As EventArgs)
File.Delete(fudFileSource.FileName)
'File.Delete("F:\4.jpg")
End Sub
</script>
>
Now since the files do not exist in the root directory, I can't use
Server.MapPath but if I simply use fudFIleSource.FileName &
txtFileDest.Text to move a file from location to another location, then
the following error gets generated pointing to the File.Move() line:
>
Could not find file 'C:\WINNT\system32\4.jpg'.
>
& in case of the Delete method, the file doesn't get deleted. Is there
any way by which I can let users move & delete files that DO NOT exist
in the root directory?
>
Note that if I use the physical path of the files (as shown in the 2
commented lines in the code above), then both the Move & Delete methods
get executed successfully.
>
Thanks,
>
Arpan
>
>

Aug 30 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.