Forum Moderators: open

Message Too Old, No Replies

ASP Upload?

Want to upload files

         

RossWal

8:23 pm on Aug 22, 2002 (gmt 0)

10+ Year Member



I'm designing a .net application that will need to upload files. I'd like users to be able to choose to drop the file onto the page or browse to it on their desktop. Client machines will all be IE5.5 and up. I though I heard .net (Visual Studio) provides an upload component but I can't find it. Anyone know if I need a third party product? Do any have drag and drop (copy/paste)capabilities?

Thanks much,
Ross

4eyes

9:45 am on Aug 23, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not sure about .NET, but there are few cgi scripts that provide file uploads.

Searching on Hotscripts should find something appropriate.

aspdaddy

10:04 am on Aug 23, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have used this one to drag and drop files for uploading in asp / IE5.5

M/S File Upload Control [msdn.microsoft.com]

Did this on the client side though, as the app was for an intranet.

<OBJECT classid="clsid:886E7BF0-C867-11CF-B1AE-00AA00A3F2C3">

threecrans

12:08 pm on Aug 23, 2002 (gmt 0)

10+ Year Member



.NET does have built in support for retrieving posted files. It is actually quite simple. It would go something like this (hope I get this all right, I'm doing it from memory).

Client side:
1) Create a form with enctype="multipart/form-data"
2) Add an input type=file


<form enctype="multipart/form-data" runat="server">
<input id="myfile" type="file" runat="server">
<input type=button id="mybutton" runat="server">
</form>

Server side:
1) In the mybutton_click event, handle the posted file. The posted file will be represented on the server as an HttpPostedFile object.
Use the SaveAs method to save to a file. Access the InputStream object to use the file data in other ways.

if (myfile.PostedFile != null)
{
// Get the HTTP posted file instance (to simplify the code)
HttpPostedFile postedfile = myfile.PostedFile;

// Get the filename
string filename = new System.IO.FileInfo(postedfile.FileName).Name;
try
{
// save to a file...if you want to access the file data in memory
// use postedfile.InputStream
postedfile.SaveAs("c:\\" + filename);
}
catch (Exception ex)
{
// handle exception
}
}

This will cause the "browse" button to appear on the browser. I do not think there is any way to "drag-and-drop" without embedding some object in the browser.

aspdaddy

11:42 am on Aug 25, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>This will cause the "browse" button to appear on the browser

Actually, the


<input type=file>

is all thats needed for a browse button.

threecrans

2:27 pm on Aug 25, 2002 (gmt 0)

10+ Year Member




Actually, the

<input type=file>

is all thats needed for a browse button.

Yes...didn't mean to imply all the server code was required to make a "Browse" button to appear on the browser...but it certainly reads that way. :)