File Move & Delete?

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
 
G

Guest

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
 
A

Arpan

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top