2012-04-18 4 views
2

이 코드를 사용하여 데이터를 Word 서식 파일로 보내고 클라이언트로 보냅니다.오류 서버에서 문서가 열려 있지 않기 때문에이 명령을 사용할 수 없습니다.

 protected void Button1_Click(object sender, EventArgs e) 
    { 
     object missing = System.Reflection.Missing.Value; 
     Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application(); 

     string DocFilePath = ""; 
     //string FilePath = System.Windows.Forms.Application.StartupPath; 
     object fileName = Server.MapPath(@"~\asset\wordtemplates\Estelam.dot"); 
     DocFilePath = fileName.ToString(); 

     FileInfo fi = new FileInfo(DocFilePath); 
     if (fi.Exists) 
     { 
      object readOnly = false; 
      object isVisible = true; 

      object LetterNo = "LetterNo"; 
      object LetterDate = "LetterDate"; 
      object Attachment = "Attachment"; 

      object To = "To"; 
      object From = "From"; 

      object Fname = "Fname"; 
      object Lname = "Lname"; 
      object FatherName = "FatherName"; 
      object IDNumber = "IDNumber"; 
      object BirthDate = "BirthDate"; 
      object BirthLocation = "BirthLocation"; 
      object PersonelID = "PersonelID"; 
      object MembershipDate = "MembershipDate"; 
      object Membership = "Membership"; 

      object Degree = "Degree"; 
      object Level = "Level"; 
      object Guild = "Guild"; 
      object Janbazi = "Janbazi"; 
      object Esarat = "Esarat"; 
      object Education = "Education"; 
      object Field = "Field"; 
      object Education2 = "Education2"; 
      object DocLocation = "DocLocation"; 

      Microsoft.Office.Interop.Word.Document aDoc = WordApp.Documents.Open(ref fileName, ref missing, ref readOnly, 
       ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, 
       ref isVisible, ref isVisible, ref missing, ref missing, ref missing); 

      //Microsoft.Office.Interop.Word.Document aDoc = WordApp.Documents.Open(ref fileName); 

      WordApp.ActiveDocument.FormFields.get_Item(ref LetterNo).Result = TextBox_LetterNo.Text; 

지역의 좋은 올바른에서이 코드가 작동,하지만 난 내 서버에이 사이트를 게시하고 둘 때이 오류 런타임을 얻을.

This command is not available because no document is open. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Runtime.InteropServices.COMException: This command is not available because no document is open.

Source Error:An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

왜 서버에서 열 수 없습니까? 이 오류를 해결하는 방법?

저는 Windows7, VS2010, SQLServer2008, office2010을 사용하고 서버에서는 Windows Server 2008, IIS7, office2010을 사용합니다.

서버에서이 오류를 해결하려면 어떻게해야합니까?

+0

ASP.NET 웹 응용 프로그램과 같은 서버 응용 프로그램에서 Office 자동화를 사용할 수 없습니다. Office 제품은 _desktop_ 제품이며 서비스 환경에서는 제대로 작동하지 않습니다. –

답변

1

당신이 누락 바탕 화면 폴더 wihtout 향후 변경 할 수 있도록 확인합니다 config 파일에 퍼팅 응용 프로그램의 경로, 을 읽을 here

Office 응용 프로그램을 자동화하기 위해 OfficeAutomationUser 계정을 구성해야합니다 (아직 완료하지 않은 경우). this

참고 : 서버에 Office 자동화를 설치하지 않는 것이 좋습니다. Open Xml SDK를 사용하여 Office 응용 프로그램을 자동화하십시오.

0

여기 VB 예제를 볼 수있는 word in asp을 읽으십시오.하지만 필요한 정보를 얻을 수있을 것 같습니다.

0

템플릿 파일을 서버의 구성 파일에 저장하려고 시도 했습니까 ?? 서버 경로가 "D : // Project Folder/Template Folder"가 아닌 상대 경로입니다. 한 다음, 쉽게 OfficeAutomation에 대한 귀하의 사이트를 다시 게시