store and retrieve files to n from secondary storage on server

Asked By shilpa gavhane
09-Jan-10 05:52 AM
Earn up to 0 extra points for answering this tough question.
Can I get the code for storing files(.pdf,.doc,.xls,.jpeg,.txt) on  server's disk and retrieve them and display to the user... like attaching files to mail and download them from that mail..

  re

Huggy Bear replied to shilpa gavhane
09-Jan-10 06:19 AM
What do you mean by code for Storing on the FileSystem? You need to have the files in the filesystem directory.If you have to create the files programatically then you can use FileStream to create and write the data to the files. You should have the binary data which you read from the file earlier.

To display the files, display the filename in a LinkButton on your page and use the below code in the LinkButton1_Click event to download the file to the clients machine.  

//ContentType should be changed based on the file type
Response.ContentType = "image/jpeg";
Response.AppendHeader("Content-Disposition","attachment; filename=filenamewithpath");
Response.TransmitFile( Server.MapPath("filenamerelativepath") );
Response.End();

  Re:

web mavin replied to shilpa gavhane
09-Jan-10 07:01 AM

So, basically what you want is an "upload" functionality which would upload the files onto the server disk. Refer this link or you'd find many references on this googling it.

Retrieving it is also pretty simple..either use the approach described in the earlier post or you could even check for 'download' file functionality on web (just as references: http://www.west-wind.com/weblog/posts/76293.aspx; http://www.dotnetheaven.com/Uploadfile/Globalking/filedownload03232006040747AM/filedownload.aspx)

Create New Account