i am using VS13 and sql server.i want to preview a word file when it upload in the database and download from the detabase.i have already use some code but there are some error.
code and error given below---i have use Technical Refence from
http://www.aspsnippets.com/Articles/Display-Word-document-on-web-page-in-ASP.Net.aspx[
^]
SETP 1: Added reference of Microsoft Word 11.0 Object Library
STEP 2:
using Microsoft.Office;
using Microsoft.Office.Interop.Word;
using System.IO;
STEP 3:
protected void Upload(object sender, EventArgs e)
{
object missingType = Type.Missing;
object readOnly = true;
object isVisible = false;
object documentFormat = 8;
string randomName = DateTime.Now.Ticks.ToString();
object htmlFilePath = Server.MapPath("~/Temp/") + randomName + ".htm";
string directoryPath = Server.MapPath("~/Temp/") + randomName + "_files";
FileUpload1.SaveAs(Server.MapPath("~/Temp/") + Path.GetFileName(FileUpload1.PostedFile.FileName));
object fileName = FileUpload1.PostedFile.FileName;
ApplicationClass applicationclass = new ApplicationClass();
applicationclass.Documents.Open(ref fileName,
ref readOnly,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref isVisible,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType);
applicationclass.Visible = false;
Document document = applicationclass.ActiveDocument;
document.SaveAs(ref htmlFilePath, ref documentFormat, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType);
document.Close(ref missingType, ref missingType, ref missingType);
File.Delete(Server.MapPath("~/Temp/") + Path.GetFileName(FileUpload1.PostedFile.FileName));
byte[] bytes;
using (FileStream fs = new FileStream(htmlFilePath.ToString(), FileMode.Open, FileAccess.Read))
{
BinaryReader reader = new BinaryReader(fs);
bytes = reader.ReadBytes((int)fs.Length);
fs.Close();
}
Response.BinaryWrite(bytes);
Response.Flush();
File.Delete(htmlFilePath.ToString());
foreach (string file in Directory.GetFiles(directoryPath))
{
File.Delete(file);
}
Directory.Delete(directoryPath);
Response.End();
}
ERROR SHOWING::
1.The type 'Microsoft.Office.Interop.Word.ApplicationClass' has no constructors defined
2.'Microsoft.Office.Interop.Word.ApplicationClass' does not contain a definition for 'Documents' and no extension method 'Documents' accepting a first argument of type 'Microsoft.Office.Interop.Word.ApplicationClass' could be found (are you missing a using directive or an assembly reference?)
3.'Microsoft.Office.Interop.Word.ApplicationClass' does not contain a definition for 'Documents' and no extension method 'Documents' accepting a first argument of type 'Microsoft.Office.Interop.Word.ApplicationClass' could be found (are you missing a using directive or an assembly reference?)
5.Interop type 'Microsoft.Office.Interop.Word.ApplicationClass' cannot be embedded. Use the applicable interface instead.
6.Interop type 'Microsoft.Office.Interop.Word.ApplicationClass' cannot be embedded. Use the applicable interface instead.
Please tell me whats wrong????