Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

This is my first time doing something like this, After doing a large amount of research i still cannot find what i am looking for.

Pretty much what i have is a Attachments table in my SQL database and users can store any type of file in it (Eg. PDF, Images, Word Files.... what ever they want to)

All that i want is When a user Clicks on a button in my Webpage What ever file they have stored in the database should be retrieved and saved on the users local machine (after the Save Dialog appears).

I dont want to use gridViews and all sorts of funny Objects,

Just a Simple button click --> get data --> Save Dialog appears --> and save to the local machine.

I am using ASP.NET, C# and Linq to retrieve the Data.

Thank you in advance.

share|improve this question
    
just a quick addition, a user may only store 1 attachment in the database – user2285916 Jul 3 '13 at 7:44

What is the datatype of file in attachments table?? are you saving the file path or what??

if you are saving the file path you can direclty write

Responce.Redirect(filepath);

which will download the file and saved to local machine.

share|improve this answer
    
The path is not being save, in the DB i have Column named "Attachments" which is a (Image) type and a column named "FileName" which just stores the FileName(varchar) The Attachment gets converted to Binary then the Binary Data is just being saved in the Database. – user2285916 Jul 3 '13 at 7:56

Read this article How to show uploaded file on the webpage with download option?

<a id="A1" href='path/filename' runat="server" target="_blank">
  <asp:Label ID="lblFileName" runat="server" Text='filename'>
   </asp:Label>
  </a> 
share|improve this answer
    
I have the correct code now, Thank you for the replies guys. I will post my answer once i am able to answer my own question :D – user2285916 Jul 3 '13 at 8:15
    var imageFile = (from i in db.Attachments
             where i.IncidentActionID == _tempAction.IncidentActionsID
             select i).FirstOrDefault();


Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + imageFile.FileName + "");
Response.BinaryWrite(imageFile.Attachments);
Response.End();
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.