i store doc file into sql server data base i want view this file on my view page how i can view this file on view plz any one help me my class code is here
public class Candidate : System.ComponentModel.IDataErrorInfo
{
[Column]
public byte[] FileData { get; set; }
[Column]
public string Filecontent { get; set; }
}
my controllercode is here;
public ActionResult C开发者_高级运维reateCandidate(Candidate candidate, HttpPostedFileBase file)
{
candidate.Filecontent = Request.Files["file"].ContentType;
Stream filestream = Request.Files["file"].InputStream;
int filelength = Request.Files["file"].ContentLength;
candidate.FileData = new byte[filelength];
filestream.Read(candidate.FileData, 0, filelength);
IcandidateRepository.SaveCandidate(candidate);
return RedirectToAction("CandidateDetails", new { id =
candidate.CandidateID });
}
i store this file in binary format plz give me sample code
You could have a controller action which would allow users to download this file:
public ActionResult Download(int? id)
{
byte[] doc = FetchDocumentFromDatabase(id);
if (doc == null)
{
// no document found with the given id
throw new HttpException(404, "Not found");
}
return File(doc, "application/msword", "document.doc");
}
Now, what is left is to provide your users with a link on the view so that they can download it:
<%= Html.ActionLink("download document", "download", new { id = "123" }) %>
精彩评论