By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,638 Members | 1,983 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,638 IT Pros & Developers. It's quick & easy.

How to Upload a file

P: n/a
I want my user to upload a file to the site.
Let us say a word file to be saved in the database
for other users of the site to use.
How can this be done?
Is there a web control for that?
Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi,

place

<input type="file" id="File1" runat="server" />

on the page (inside server-side form). It is of type
System.Web.UI.HtmlControls.HtmlInputFile (you need this for the code-behind
member if you use codebehind). it has the methods and properties to get
access to the uploaded file.

Here is an article that explains what to do in practise.
http://www.codeproject.com/aspnet/fileupload.asp

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
"Manu" <an*******@discussions.microsoft.com> wrote in message
news:cc****************************@phx.gbl...
I want my user to upload a file to the site.
Let us say a word file to be saved in the database
for other users of the site to use.
How can this be done?
Is there a web control for that?
Nov 18 '05 #2

P: n/a
Here is one more KB article http://support.microsoft.com/?kbid=816150 for
uploading a file to the webserver.

"Manu" <an*******@discussions.microsoft.com> wrote in message
news:cc****************************@phx.gbl...
I want my user to upload a file to the site.
Let us say a word file to be saved in the database
for other users of the site to use.
How can this be done?
Is there a web control for that?

Nov 18 '05 #3

P: n/a
The previous posts describe the basic machinery for doing an upload. However, the typical reason for uploading a file is to grant access to it to an audience. You could put it in a publicly-readble folder but this would (obviously) allow anyone to view it which may not be what you want. We avoid this by having all file access channelled through a page where I can do authentication and access control. The actual physical location is hidden. A second issue you might need to consider it having multiple versions of a document. To handle this I rename all uploaded files to a GUID (keeping the file extension) and then have a database table that maps an upload ID to a physical file. The user things they are getting 'MyFile.doc' but instead they get '4a452..etc.doc'. This renaming/mapping allows me to keep arbitrary versions of 'MyFile.doc' - this is essential in some situations where we need to keep the state of a file at a given time, not just the latest. I hope this gives some pointers.
Nov 18 '05 #4

P: n/a
Kevin, I've got basically the same architecture. For the most part it works
well. I am having an issue with file sizes, though. I've got the max
request limit set at 1GB - we need the ability to upload large files - But
if I upload anything larger than, say, 450MB, I get an out of memory error.
Does the upload control try to cache the whole file before it writes it? Is
this an issue for your system? Thanks.

Jerry

"Kevin Waite" <an*******@discussions.microsoft.com> wrote in message
news:5F**********************************@microsof t.com...
The previous posts describe the basic machinery for doing an upload.

However, the typical reason for uploading a file is to grant access to it to
an audience. You could put it in a publicly-readble folder but this would
(obviously) allow anyone to view it which may not be what you want. We
avoid this by having all file access channelled through a page where I can
do authentication and access control. The actual physical location is
hidden. A second issue you might need to consider it having multiple
versions of a document. To handle this I rename all uploaded files to a
GUID (keeping the file extension) and then have a database table that maps
an upload ID to a physical file. The user things they are getting
'MyFile.doc' but instead they get '4a452..etc.doc'. This renaming/mapping
allows me to keep arbitrary versions of 'MyFile.doc' - this is essential in
some situations where we need to keep the state of a file at a given time,
not just the latest. I hope this gives some pointers.
Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.