Welcome Guest Search | Active Topics | Sign In | Register

File Uploader Options
Brandon
Posted: Wednesday, October 24, 2007 10:52:32 AM
Rank: Member
Groups: Member

Joined: 10/11/2007
Posts: 12
Once files have been uploaded to the tempfilelocation how do i in code process the files and move them to the desired location some vb.net code to do this would be of great help.
Thanks in advance
eo_support
Posted: Wednesday, October 24, 2007 10:59:05 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

You will do that by handling FileUploaded event. You can find sample VB.NET code at here:

http://www.essentialobjects.com/Demo/Default.aspx?path=AJAXUploader\_i8

Look for the For Each look in the sample code, you will see all it does it to display each uploaded file's TempFileName property. You need to change that to:

File.Move(file.TempFileName, wherever_you_want_to_move_the_file_to)

Thanks
mckulap
Posted: Saturday, November 3, 2007 8:02:15 PM
Rank: Advanced Member
Groups: Member

Joined: 9/18/2007
Posts: 38
I tried this

Dim files As EO.Web.AJAXPostedFile() = AJAXUp1.PostedFiles
Dim filex As EO.Web.AJAXPostedFile
For Each filex In files
File.Move(filex.TempFileName, BS.ProjectRoot & "Images\Temp2\")
Next

my tempfilelocation = BS.ProjectRoot & "Images\Temp\"

so i store the uploads into temp then attempt to move them to temp2 bascially. Both folder have write access

I get this error: Cannot create a file when that file already exists.

on this line:
File.Move(filex.TempFileName, BS.ProjectRoot & "Images\Temp2\")

any help?
eo_support
Posted: Saturday, November 3, 2007 8:10:46 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
The second parameter of File.Move takes a file name, not a directory name.
mckulap
Posted: Saturday, November 3, 2007 8:17:05 PM
Rank: Advanced Member
Groups: Member

Joined: 9/18/2007
Posts: 38
ok I fixed that - now I am getting:

The given path's format is not supported

on this line:

File.Move(filex.TempFileName, BS.ProjectRoot & "Images\Temp2\" & filex.TempFileName)

the temp folder stores odd names - nothing like "pic.jpg" I assume this is normal - right? so how to I tell the move command to name the file it's proper name?

thanks
mckulap
Posted: Saturday, November 3, 2007 8:24:37 PM
Rank: Advanced Member
Groups: Member

Joined: 9/18/2007
Posts: 38
it seems like the filex.TempFileName.ToString is returning the .data file name which is long and cryptic (see below)

aka : eouploader.a5b15145-1999-474e-b160-7985cea4c807.3.data

the actual file uploaded was "picture.jpg"

how do I re-get the correct name?
eo_support
Posted: Saturday, November 3, 2007 8:38:28 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

As for your questions:

1. "The given path's format is not supported". That's because TempFileName contains the full path. If your BS.ProjectRoot is "c:\", then in your case, TempFileName would be "c:\Images\Temp\eouploader.a5b15145-1999-474e-b160-7985cea4c807.3.data", and you are appending it to BS.ProjectRoot & "Images\Temp2\" in your File.Move call. That produces a file name of "c:\Images\Temp2\c:\Images\Temp\eouploader.a5b15145-1999-474e-b160-7985cea4c807.3.data\". Obviously that's not valid;

2. Use ClientFileName instead of TempFileName. TempFileName is a temporary file. It contains the valid contents but the file name is automatically generated.

While we strive to offer the best tech support in the industry, we would also expect you to rely on your own knowledge and skills to solve most programming issues you hit, especially when they don’t really have anything to do with our product at all. It would be much appreciated if you can do that!

Thanks
mckulap
Posted: Saturday, November 3, 2007 9:25:56 PM
Rank: Advanced Member
Groups: Member

Joined: 9/18/2007
Posts: 38
thanks for the quick response. I don't see how you expect me to understand the attributes and properties you coded for your object. the filex object I am struggling with is your Essential Object .net control.


by the way for anyone else struggling with this same issue here is the syntax to provide you the uploaded files real name

System.IO.Path.GetFileName(filex.ClientFileName)

filex is declared as

Dim filex As EO.Web.AJAXPostedFile


entire code below

Protected Sub AJAXUp1_FileUploaded(ByVal sender As Object, ByVal e As System.EventArgs) Handles AJAXUp1.FileUploaded

Dim files As EO.Web.AJAXPostedFile() = AJAXUp1.PostedFiles
Dim filex As EO.Web.AJAXPostedFile
For Each filex In files
File.Move(filex.TempFileName, BS.ProjectRoot & "Images\Temp2\" & System.IO.Path.GetFileName(filex.ClientFileName))
Next
AJAXUp1.ClearPostedFiles()
End Sub
eo_support
Posted: Saturday, November 3, 2007 9:58:14 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
mckulap wrote:
I don't see how you expect me to understand the attributes and properties you coded for your object. the filex object I am struggling with is your Essential Object .net control.


Everything is in the documentation. You can go to Start -> Program Files -> EO.Web Controls 2007.1 -> ASP.NET 1.1/2.0 -> EO.Web Help to find out everything about our objects.

Thanks for sharing the code though. I am sure it will be helpful for other users.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.