File Move & Delete?

  • Thread starter Thread starter Arpan
  • Start date Start date
A

Arpan

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
 
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
 
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
 
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
 
Back
Top