tags:

views:

167

answers:

3

Through the website, I need to allow the user to add attachments and store them. And also add pictures and display and store them.

+2  A: 

Where's your question? This is a very broad statement and you've not given any details as to what you need. With that said I am going to take a stab and give you a very general high level overview.

To upload files you can use an input control with a type set to file. This will let your user select an attachment.

Once they have selected it and posted to the server you will get access to the files via Request.File

You have a ton of options to store the files:

  1. Save the files as a blob in a database using an image or binary data type
  2. Save the file on the file system and store a pointer in your database
  3. If your using SQL 2008 there's a new file stream data type which is sort of like option 2.

Edit

I recently added attachment capability and some of the things I ran into include:

  • IE8 no longer includes the real file path in the input control. It now returns c:\FakePath as
  • Make sure to set the encoding type on the form if your not going to user server side controls.
  • If you want to upload multiple files a simple method is to have one visible input control, then as the user selects a file hide the input, and replace with a new input. Then provide the user with a list of the files, allowing them to delete the files.

Edit

Ok to do this you need to have a directory which is in iis, that the worker process has write access to, once you save the file, you can build a url for the user. If you have named user accounts you can store the files using the username which will help avoid collisions.

JoshBerke
Sorry for not being very clear.For example, I want to choose a picture, save it on the server not on the database, give the hyperlink for the picture of attachment for the user to access it.
Ahmad Farid
@Ahmad Feel free to do so. :)
deceze
A: 

There are loads of tutorials out there, it can be a fairly easy thing to do and you can then make it as complicated as you like to suit your needs. Try these tutorials: they are websites i cannot live without as an ASP.NET developer,

http://www.asp.net/learn/videos/video-255.aspx

http://www.4guysfromrolla.com/webtech/091201-1.shtml

Have fun!

Michael Willmott
+1  A: 

As an outline of where to start:

You will want to use the FileUpload control to allow the uploads.

A database to store which files a user has uploaded.

A display page to build the html to view the pictures / files. Probably using a repeater of some description.

Things to beware of are maximum file sizes of uploads and any security risks with people uploaded files to your server.

Robin Day
thanks man. i was able to save the file by giving it its physical path on the hard drive like: c:\folder\filename.txtbut i want to save it at the folder of the project and solution, so when i try using like FileUploader.PostedFile.SaveAs("~/Pictures/" + filepath);it doesn't want. any suggestions?
Ahmad Farid
FileUploader.PostedFile.SaveAs(Server.MapPath("~/Pictures/" + filepath));
Robin Day