2011-07-08 73 views
0

doc文件我的文檔文件存儲到SQL Server數據庫中,我想查看我的視圖頁面上這個文件我怎麼可以查看視圖PLZ此文件中的任何一個可以幫助我 我的類代碼是在這裏如何填充上查看

public class Candidate : System.ComponentModel.IDataErrorInfo 
{ 

    [Column] 
    public byte[] FileData { get; set; } 
     [Column] 
     public string Filecontent { get; set; } 

    } 

我的控制器代碼在這裏;

 public ActionResult CreateCandidate(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 }); 

     } 

我以二進制格式存儲PLZ這個文件給我的示例代碼

回答

0

你可以有一個控制器動作,這將允許用戶下載此文件:

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"); 
} 

現在,還剩下什麼是爲您的用戶提供一個視圖上的鏈接,以便他們可以下載它:

<%= Html.ActionLink("download document", "download", new { id = "123" }) %> 
+0

嗨達林我不想下載ser點擊鏈接,查看此文件不下載 – sandy

+0

@sandy,查看文件在哪裏?這是Word文檔文件。你是否想要將doc文件轉換爲HTML? –

+0

沒有轉換是無法查看 – sandy