Forum Moderators: open
Thanks much,
Ross
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">
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.